what are you trying to achieve*
I would like set new custom rule in my project. As it’s PL/SQL related repository I have to do it via XPath.
In my case I would like to create a rule that shows (for partcular file extension) that SQL keyword ‘FORCE’ have to be used on the beginning of code, during view creation.
COMPLIANT: CREATE OR REPLACE FORCE VIEW…
NONCOMPLIANT: CREATE OR REPLACE VIEW…
Unfortunately there are no info about xpath expressions creation in sonar documentation and in others such info has often nothing to do with sonar rules.
what have you tried so far to achieve this*
I was on sonar documentation chapter “Adding Code Rules” as well as browsed half of internet trying to solve this puzzle but I did not find even quite similar issue to mine.
Did you have a look at the documentation page about “Adding coding rules”?
Did you run the SSLR Toolkit for PL/SQL to see how the syntax tree is represented for the code you want to detect?
First question: I already answered in my first post
Second question: Yes I can see the syntax tree and my code parsed on XML but there is no further info what I should do with it. I still have to write my Xpath expression on my own using XPath language which I don’t know.
I noticed that our PL/SQL parser doesn’t know about the FORCE clause. I created SONARPLSQL-761 to address this problem.
If you look at the XML tab in the SSLR Toolkit, you can guess that a basic XPath expression such as //CREATE_VIEW will detect all CREATE VIEW statements. As long as SONARPLSQL-761 is not fixed, that will be enough.
If you need to learn XPath, this forum is not the best place…