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

fix: correct locations of invalid /* eslint */ comments #18593

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment (npx eslint --env-info):

  • Node version: v20.12.0
  • npm version: v10.5.0
  • Local ESLint version: v9.5.0
  • Global ESLint version: no
  • Operating System: windows

What parser are you using (place an "X" next to just one item)?

[x] Default (Espree)
[ ] @typescript-eslint/parser
[ ] @babel/eslint-parser
[ ] vue-eslint-parser
[ ] @angular-eslint/template-parser
[ ] Other

Please show your full configuration:

Configuration
export default [];

What did you do? Please include the actual source code causing the issue.

// line 1
// line 2
/* eslint no-alert: [2 */

What did you expect to happen?

An error about invalid JSON in inlline config on line 3.

What actually happened? Please include the actual, raw output from ESLint.

Error on line 1 instead of line 3:

 1:1  error  Failed to parse JSON from ' "no-alert": [2': Expected ',' or ']' after array element in JSON at position 16

Playground Demo

What changes did you make? (Give an overview)

SourceCode#applyInlineConfig() was returning these errors without the loc property (line and column were directly on the error as received from the config comment parser) so the error loc start was defaulting to 1:1. I fixed this to return loc on the error, and also refactored code to create lint errors in the Linter rather than in the config comment parser. This also adds endLine and endColumn so the whole comment will be underlined.

Is there anything you'd like reviewers to focus on?

This bug was not introduced in #18448, we missed it earlier.

@mdjermanovic mdjermanovic requested a review from a team as a code owner June 16, 2024 13:31
@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label Jun 16, 2024
@github-actions github-actions bot added the core Relates to ESLint's core APIs and features label Jun 16, 2024
Copy link

netlify bot commented Jun 16, 2024

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 086ef28
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/666ee93d7d7acd0008f2a280

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Leaving open until the patch release window has closed.

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jun 17, 2024
@mdjermanovic mdjermanovic merged commit f9e95d2 into main Jun 18, 2024
19 checks passed
@mdjermanovic mdjermanovic deleted the fix-config-comment-loc branch June 18, 2024 15:26
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Dec 16, 2024
@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 16, 2024
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
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants