sonar-r-plugin icon indicating copy to clipboard operation
sonar-r-plugin copied to clipboard

Not able to find a InputFile with R/tests/testthat.R

Open nicolasfguillaume opened this issue 3 years ago • 4 comments

The plugin is able to find and lint source files, but not able to find test files:

ERROR: Not able to find a InputFile with R/tests/testthat.R

However, in the logs I can see that this test file was indexed correctly:

'R/tests/testthat.R' indexed as test with language 'r' 

Also, I made sure to define the properties in sonar-project.properties:

sonar.sources=R/R/
sonar.tests=R/tests/

In the source of the plugin, I can see in the function processIssue in file https://github.com/Merck/sonar-r-plugin/blob/master/src/main/java/com/msd/gin/common/sonar/LintRSensor.java#L97 that the InputFile type expected is MAIN InputFile.Type.MAIN (and not TEST), which makes me think that the test files are excluded from linting.

This is even more surprising because there are test files in the json file in the sample-project (https://github.com/Merck/sonar-r-plugin/blob/master/sample-project/lintr_out.json#L390).

Please advise.

nicolasfguillaume avatar Apr 08 '22 15:04 nicolasfguillaume

You are correct: only "main" files are reported to SonarQube for found issues. All other LintR issues found on for example test files will be ignored. I can imagine it could be configurable or filter can be removed completely. Any suggestion from your side?

kmoco2am avatar Apr 08 '22 15:04 kmoco2am

Yes in my opinion it would make sense to lint the test files as well as the main files. Here is my suggestion (please note that I am not a java expert):

        InputFile inputFile = fileSystem.inputFile(
                fileSystem.predicates().and(
                        fileSystem.predicates().hasRelativePath(issue.getFilename()),
                        fileSystem.predicates().or(
                                fileSystem.predicates().hasType(InputFile.Type.MAIN),
                                fileSystem.predicates().hasType(InputFile.Type.TEST))));

Thank you.

nicolasfguillaume avatar Apr 11 '22 12:04 nicolasfguillaume

Hello @kmoco2am could we please add these modifications to the project if they look ok to you? Thank you!

nicolasfguillaume avatar Jun 30 '22 12:06 nicolasfguillaume

Hi, it would may be make sense to make it configurable. There can be projects where developers care about production files quality mainly and tests could be more relaxed so excluded. What do you think?

kmoco2am avatar Jul 01 '22 08:07 kmoco2am