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

Linter ignores multiline /* eslint-env */ directives #14652

Closed
mdjermanovic opened this issue May 31, 2021 · 2 comments
Closed

Linter ignores multiline /* eslint-env */ directives #14652

mdjermanovic opened this issue May 31, 2021 · 2 comments

Comments

@mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented May 31, 2021

Tell us about your environment

  • ESLint Version: v7.27.0
  • Node Version: v12.18.4
  • npm Version: v6.14.6
  • Operating System: windows

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, 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, as well as the command that you used to run ESLint.

/* eslint-env browser 
*/

window;
npx eslint index.js

What did you expect to happen?

no no-undef errors, because browser environment enables window global

What actually happened? Please copy-paste the actual, raw output from ESLint.

  4:1  error  'window' is not defined  no-undef

Steps to reproduce this issue:

Online Demo

Are you willing to submit a pull request to fix this bug?

Yes, if it is a bug.

The issue is: linter ignores multiline /* eslint-env ... */ comments. A single-line comment works well, as in this demo.

I couldn't find a test case or a discussion that would confirm that this was intentional. It looks like a common bug with . in a regular expression that doesn't have the s flag.

Also, noInlineConfig: true option does report multiline eslint-env as a directive:

module.exports = {
  rules: {
    "no-undef": "error"
  },
  noInlineConfig: true
};
/* eslint-env browser 
*/

window;
  1:1  warning  '/*eslint-env*/' has no effect because you have 'noInlineConfig' setting in your config (.eslintrc.js)
  4:1  error    'window' is not defined  
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage May 31, 2021
@mdjermanovic mdjermanovic moved this from Needs Triage to Feedback Needed in Triage May 31, 2021
@mdjermanovic
Copy link
Member Author

@mdjermanovic mdjermanovic commented Jun 3, 2021

@eslint/eslint-tsc Thoughts about this? I think this is a bug, but would like another confirmation. We have PR #14660 prepared.

Loading

@nzakas
Copy link
Member

@nzakas nzakas commented Jun 4, 2021

Most likely a bug. I’m not sure how much it matters since this feature will be going away, but no objections to fixing it.

Loading

Triage automation moved this from Feedback Needed to Complete Jun 4, 2021
mdjermanovic added a commit that referenced this issue Jun 4, 2021
…14660)

* Fix: linter ignores multiline /*eslint-env*/ directives (fixes #14652)

* Update lib/linter/linter.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Chore: add more tests

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Triage
Complete
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants