Navigation Menu

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 · Fixed by #14660
Closed

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

mdjermanovic opened this issue May 31, 2021 · 2 comments · Fixed by #14660
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 repro:yes
Projects

Comments

@mdjermanovic
Copy link
Member

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  
@mdjermanovic mdjermanovic added bug ESLint is working incorrectly repro:needed labels May 31, 2021
@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 mdjermanovic added core Relates to ESLint's core APIs and features repro:yes and removed repro:needed labels May 31, 2021
@mdjermanovic
Copy link
Member Author

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

@nzakas
Copy link
Member

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.

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jun 4, 2021
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>
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Dec 2, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 2, 2021
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 repro:yes
Projects
Archived in project
Triage
Complete
Development

Successfully merging a pull request may close this issue.

2 participants