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

Shell invocation should exit non-0 exit status on failure #491

Closed
bsolomon1124 opened this issue May 7, 2020 · 6 comments
Closed

Shell invocation should exit non-0 exit status on failure #491

bsolomon1124 opened this issue May 7, 2020 · 6 comments

Comments

@bsolomon1124
Copy link

Common convention with lint tools is to exit >0 if errors are found. That is not the case with lintr, either for lint() or lint_package():

$ Rscript -e "lintr::lint_package('myProjName')"
R/rdaPackaging.R:14:9: style: Only use double-quotes.
library('knitr')
        ^~~~~~~
R/rdaPackaging.R:15:9: style: Only use double-quotes.
library('packrat')

$ echo $?
0
@russHyde
Copy link
Collaborator

russHyde commented May 9, 2020

Since lintr is a package, rather than a command line tool, the exit code is the responsibilty of your lintr-calling script.

You could add lints <- lint(...); quit(status=length(lints)), I guess.

@bsolomon1124
Copy link
Author

Since lintr is a package, rather than a command line tool, the exit code is the responsibilty of your lintr-calling script.

I don't understand why this mentality dominates the R ecosystem.
Who runs a linter by importing it into an R repl?

Name one other languages that by convention suggests running linters as libraries
rather than as command-line tools.

$ python -m flake8 foo.py
foo.py:1:10: E201 whitespace after '('
foo.py:1:12: E202 whitespace before ')'

$ echo "$?"
1

$ python -m flake8 ok.py
$ echo "$?"
0

Here flake8 defines a main entry point which then raises SystemExit if the number of found issues is > 0.

@russHyde
Copy link
Collaborator

russHyde commented Dec 9, 2020

Suggest adding a section to the docs to explain how to run lintr at the command line (and return an appropriate exit code from lintr)

@AshesITR
Copy link
Collaborator

AshesITR commented Dec 9, 2020

There is a setting error_on_lint which should do what you want to.

Can you try putting error_on_lint: TRUE into your .lintr and re-run your test?

@bsolomon1124
Copy link
Author

Thanks @AshesITR , I verified that error_on_lint will call quit() with an exit code >0.

https://github.com/jimhester/lintr/blob/5e53d7a1435739faf05651f6abc754de67941b5c/R/methods.R#L81

IMO, that should be the default, but understand why there might be reluctance to change it and create backwards incompatibility.

@MichaelChirico
Copy link
Collaborator

I believe superseded by #1226

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

No branches or pull requests

4 participants