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

eslint-disable-next-line works in shebang comments #9238

Closed
not-an-aardvark opened this issue Sep 5, 2017 · 6 comments
Closed

eslint-disable-next-line works in shebang comments #9238

not-an-aardvark opened this issue Sep 5, 2017 · 6 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features good first issue Good for people who haven't worked on ESLint before

Comments

@not-an-aardvark
Copy link
Member

Tell us about your environment

  • ESLint Version: 4.6.1
  • Node Version: 8.4.0
  • npm Version: 5.3.0

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

Configuration
module.exports = {
    rules: {
        no-undef: "error"
    }
};

What did you do? Please include the actual source code causing the issue.

#! eslint-disable-next-line
foo;

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 either Block or Line. However, ast.comments now includes shebang comments (they have type Shebang), so this is no longer a safe assumption.

There are a few different ways that this could be fixed:

  • Filter out shebangs before doing any processing on them.
  • Make the logic explicitly check that a comment has type Line before assuming that it's a line comment.
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion good first issue Good for people who haven't worked on ESLint before bug ESLint is working incorrectly core Relates to ESLint's core APIs and features labels Sep 5, 2017
@i-ron-y
Copy link
Contributor

i-ron-y commented Sep 5, 2017

Working on this.

@i-ron-y
Copy link
Contributor

i-ron-y commented Sep 6, 2017

I had the logic explicitly check that the comment has type "Line" before checking for a eslint-disable-next-line. Now

#! eslint-disable-next-line
foo;

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).

"foo;",                                          (1)
"#! eslint-disable-next-line",
"foo;",                                          (2)
"foo;"                                           (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... ?

@not-an-aardvark
Copy link
Member Author

Thanks for working on this!

It feels like Shebangs aren't being processed properly... ?

I think shebangs are only allowed at the start of a file -- it's considered a syntax error if they appear anywhere else.

@i-ron-y
Copy link
Contributor

i-ron-y commented Sep 6, 2017

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!

@not-an-aardvark
Copy link
Member Author

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.

@i-ron-y
Copy link
Contributor

i-ron-y commented Sep 6, 2017

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!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 8, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features good first issue Good for people who haven't worked on ESLint before
Projects
None yet
Development

No branches or pull requests

2 participants