-
Notifications
You must be signed in to change notification settings - Fork 883
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
ruff
exits with code 0
if there's a SyntaxError but rule E999
is not selected
#8447
Comments
Seems reasonable to change the exit code if we fail to parse any files — I'm unsure of the difficulty to implement this. |
Thanks for your prompt response! Would it be unreasonable to exit with What do you think? |
What's the two line change? :) I think we want to still lint the remaining files, so only exit at the end. |
I need to think on this... There's been a lot of back and forth on this behavior:
|
@zanieb I did it by just exiting with @charliermarsh what if you just add a cli option to exit if there's a In any case, you obviously know the codebase (and other related issues logged) better than I do, so I'll leave this up to you :)) Thanks! |
I don't think exiting on the first error is an acceptable solution, unfortunately. We have people that rely on the current behavior and we can perform some lints despite syntax errors in a file. |
This affects writing rules as well, you write a new rule $ cargo run -p ruff -- check foo.py --no-cache --preview --select E123
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
Running `target/debug/ruff check foo.py --no-cache --preview --select E123`
error: Failed to parse foo.py:1:5: Simple statements must be separated by newlines or semicolons
All checks passed! The last line gives a false sense of everything working. I think putting a |
I believe @dhruvmanila might eventually be looking into how we can surface parse errors as diagnostics? |
Yes, ideally the syntax errors should be surfaced using the same diagnostic system Ruff uses to display lint errors. There are still some outstanding questions with regards to the exit code and how should |
As per the title, if the rule with code
E999
is not included in the configuration, thenruff
will terminate successfully even if there's aSyntaxError
. So, for example, if one wanted to runruff
against only the Pylfakes rules, the logical configuration for the rules would be--select F
, but this doesn't work as expected.Specifically, running
ruff --select F <filename.py>
exits withcode 0
even if there's aSyntaxError
- it does printerror: Failed to parse
but it doesn't raise an error. I believe this shouldn't be the default behavior as it would allowruff
to succeed in automated pipelines even with aSyntaxError
(and possibly otherF
code errors). As a workaround for the mentioned use-case, one can also includeE999
in the selected rules. However, this isn't very intuitive since having aSyntaxError
means that an AST can't be generated and so, even ifE999
isn't really aPyflakes
error, the python code can't be run.FWIW, ruff rules list
E999
as apycodestyle
error code, while in reality it's a code returned byflake8
when it can't generate an AST for a given file. The equivalentpycodestyle
code isE901 SyntaxError or IndentationError
as listed here.The text was updated successfully, but these errors were encountered: