Is there any existing rule/plugin to check for the file existence?


(Rajesh Balu) #1

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube: 6.7
    Scanner: 3.0.3
  • what are you trying to achieve: Want to check if the file exists in a given code base through Sonar rule
  • what have you tried so far to achieve this: Trying to find if there is any existing rules/plugin.

(G Ann Campbell) #2

Hi,

There’s nothing like this available AFAIK, and off-hand it doesn’t really sound like it falls into the SonarQube domain.

Ann


(Rajesh Balu) #3

Thanks for the response. Below is my use-case. Please let me know if this is feasible or not through SonarQube.

Let’s say, before I check for the values in XML files using XPATH, I want to confirm if the file is available before check for the value.


(G Ann Campbell) #4

Assuming you’re writing a custom XPath rule for XML:

  • your rule will be run on all relevant (i.e. .xml) files by default, and you can just assume it won’t be applied to files that don’t exist. :wink:
  • your rule will only run in the context of one file at a time, with no visibility into what other files do or don’t exist on the file system.

HTH,
Ann


(Rajesh Balu) #5

Got your point. A rule will not be applied if a file does not exist. But I need to check for the file existence to meet our org coding standard.

So basically, you point is, there is no way in Sonar to tell if the file exists in a code base?


(G Ann Campbell) #6

There’s no easy way to do it as a rule within SonarQube.

However

If you really want to see this reported in SonarQube you could using scripting within your build system to check for the existence of the file, and craft a Generic Issue Data report that raises an issue when it’s not there.

BTW, it may sound like I’ve made a distinction without a difference here but that documentation I’ve linked to should make the difference clear.

Ann