Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nicolasfguillaume opened this issue Apr 8, 2022 · 4 comments
Open

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

nicolasfguillaume opened this issue Apr 8, 2022 · 4 comments

Comments

@nicolasfguillaume
Copy link

nicolasfguillaume commented Apr 8, 2022

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.

@kmoco2am
Copy link
Contributor

kmoco2am commented Apr 8, 2022

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?

@nicolasfguillaume
Copy link
Author

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
Copy link
Author

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

@kmoco2am
Copy link
Contributor

kmoco2am commented Jul 1, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants