Skip to content

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

Closed
@mdjermanovic

Description

@mdjermanovic
Member

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  

Activity

added
bugESLint is working incorrectly
repro:neededThis issue should include a reproducible example
coreRelates to ESLint's core APIs and features
repro:yesIssues with a reproducible example
and removed
repro:neededThis issue should include a reproducible example
on May 31, 2021
added a commit that references this issue on Jun 3, 2021
4fd6945
mdjermanovic

mdjermanovic commented on Jun 3, 2021

@mdjermanovic
MemberAuthor

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

nzakas

nzakas commented on Jun 4, 2021

@nzakas
Member

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.

added
acceptedThere is consensus among the team that this change meets the criteria for inclusion
on Jun 4, 2021
added a commit that references this issue on Jun 4, 2021
c545163
locked and limited conversation to collaborators on Dec 2, 2021
added
archived due to ageThis issue has been archived; please open a new issue for any further discussion
on Dec 2, 2021
moved this to Complete in Triageon Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlycoreRelates to ESLint's core APIs and featuresrepro:yesIssues with a reproducible example

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @nzakas@mdjermanovic

      Issue actions

        Linter ignores multiline `/* eslint-env */` directives · Issue #14652 · eslint/eslint