Skip to content

Bug: In-line disabling of the strict rule requires the comment to be the first line of the file (regression in ESLint v10) #20451

@Standard8

Description

@Standard8

Environment

Node version: v25.3.0
npm version: 11.7.0
Local ESLint version: 10.0.0-rc.0
Global ESLint version: N/A
Operating System: Mac 26.2

What parser are you using?

Default (Espree)

What did you do?

Configuration
export default [
  {
    files: ["*.js"],
    languageOptions: {
      sourceType: "script",
    },
    rules: {
      strict: ["error", "global"],
    }
  }
]
/* Copyright message, or comment explaning why strict is disabled. */
/* eslint-disable strict */

function foo() {
  console.log(foo);
}

What did you expect to happen?

No errors

What actually happened?

  1:1  error    Use the global form of 'use strict'                                        strict
  2:1  warning  Unused eslint-disable directive (no problems were reported from 'strict')

Link to Minimal Reproducible Example

https://github.com/Standard8/eslint-strict-mode-comment-location

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

If the /* eslint-disable strict */ line is on the very first line of the file, then it works. However, if it is not on the very first line then it fails, even if it is before any code.

This prevents situations like shown in the example, where we want to have a copyright message at the start of the file, or even a comment as to why strict mode is being disabled in the file.

This is a regression in the Eslint 10.0.0 series (I checked the alpha & beta and they failed also). Eslint 9.39.2 works fine.

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionbugESLint is working incorrectlypatch candidateThis issue may necessitate a patch release in the next few daysrepro:yesIssues with a reproducible exampleruleRelates to ESLint's core rules

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions