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

Change Request: Disallow multiple configuration comments for the same rule #18132

Closed
1 task done
mdjermanovic opened this issue Feb 20, 2024 · 1 comment · Fixed by #18157
Closed
1 task done

Change Request: Disallow multiple configuration comments for the same rule #18132

mdjermanovic opened this issue Feb 20, 2024 · 1 comment · Fixed by #18157
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint

Comments

@mdjermanovic
Copy link
Member

ESLint version

v9.0.0-beta.0

What problem do you want to solve?

Example:

/* eslint semi: ["error", "never"] */

foo

/* eslint semi: ["error", "always"] */

foo;
  3:4  error  Missing semicolon  semi

Allowing multiple configuration comments for the same rule can lead to the conclusion that it's possible to have different configurations for different parts of the file, while actually the last configuration applies to the whole file.

It's also confusing, now when comments with just severity retain previously configured options (#17381), what should be the final configuration in cases like this:

/* eslint semi: ["error", "never"] */

/* eslint semi: ["warn"] */

// should the final configuration be semi: ["warn", "never"] ?

What do you think is the correct solution?

Disallow multiple configuration comments for the same rule.

The first comment should apply, while the others should be reported as lint errors.

Participation

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

Additional comments

This makes two breaking changes:

  1. Reporting multiple configuration comments as lint errors is a breaking change.
  2. The first comment will apply, while it used to be the last comment. This could be avoided by applying the last comment and reporting previous ones, but I think it makes more sense to report those that appear later.
@mdjermanovic mdjermanovic added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features breaking This change is backwards-incompatible labels Feb 20, 2024
@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label Feb 22, 2024
@mdjermanovic
Copy link
Member Author

I'm working on this.

snitin315 pushed a commit that referenced this issue Mar 3, 2024
* feat!: disallow multiple configuration comments for same rule

Fixes #18132

* update lint error message

Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>

* update tests

Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
Archived in project
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants