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
eslint-disable-next-line works in shebang comments #9238
Comments
Working on this. |
I had the logic explicitly check that the comment has type "Line" before checking for a eslint-disable-next-line. Now
is giving an error, which is what we want. Perfect, that fixed this issue. Unfortunately, I discovered another issue with shebangs. The following code should give three errors, for lines (1), (2), and (3).
On the contrary, it results in an error only for the line (2), with lines (1) and (3) not giving any errors. Just to make sure this isn't an issue that I have introduced with my fix, I tried this test out on the original, unmodified eslint-disable-next-line code, and this bug is also present: with the unmodified eslint-disable-next-line code, this test gives no errors. It feels like Shebangs aren't being processed properly... ? |
Thanks for working on this!
I think shebangs are only allowed at the start of a file -- it's considered a syntax error if they appear anywhere else. |
Hmm, I wonder why it's inadvertently disabling all errors around it (except for the error on the next line, with my fix)... I'll keep at it, see what comes up! |
In general, no rules get run when a parsing error occurs, because no AST could be created. So if a file has invalid syntax, the parsing error is always the only error for that file. |
Ahh, that makes sense - thank you! EDIT: And I think I must've misunderstood where that error being reported was coming from! Thank you for clarifying! |
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue.
What did you expect to happen?
I expected an error to be reported, because
eslint-disable-next-line
is only supposed to work when using line comments.What actually happened? Please include the actual, raw output from ESLint.
No error was reported, because ESLint considered the shebang to be a valid
eslint-disable-next-line
comment.It looks like the issue is occurring as part of the inline comment processing here. In a previous version of ESLint,
ast.comments
did not contain shebangs, so it was safe for that logic to assume that all comments in the array had a type of eitherBlock
orLine
. However,ast.comments
now includes shebang comments (they have typeShebang
), so this is no longer a safe assumption.There are a few different ways that this could be fixed:
Line
before assuming that it's a line comment.The text was updated successfully, but these errors were encountered: