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

docs: fix malformed eslint config comments in rule examples #18078

Merged
merged 3 commits into from Feb 4, 2024

Conversation

fasttime
Copy link
Member

@fasttime fasttime commented Feb 3, 2024

Prerequisites checklist

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

[x] 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: v21.6.0
npm version: v10.2.4
Local ESLint version: v9.0.0-alpha.2 (Currently used)
Global ESLint version: Not found
Operating System: darwin 23.3.0

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
{
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  }
}

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

/* eslint mentioned in this comment */

What did you expect to happen?

Block comments starting with eslint are treated as configuration comments for rules. When ESLint cannot parse them as such, it reports a fatal error (repro).

This fatal error should not be allowed to occur in rule examples because it makes the example code unparsable even if the syntax is correct. It should be caught by the tool that validates rule examples (tools/check-rule-examples.js).

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

A rule example with a malformed eslint config comment can pass validation. We have two such examples in lines-around-comment, both fixed in this PR.

What changes did you make? (Give an overview)

  • Fixed the rule examples in lines-around-comment by replacing eslint with jshint - another special word that doesn't trigger the rule.
  • Extended the check-rule-examples tool to account for malformed eslint config comments when validating code.

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

@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label Feb 3, 2024
Copy link

netlify bot commented Feb 3, 2024

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 6f95b80
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/65be2788da4e9c0008688e43

@fasttime fasttime marked this pull request as ready for review February 3, 2024 11:54
@fasttime fasttime requested a review from a team as a code owner February 3, 2024 11:54
@mdjermanovic mdjermanovic changed the title fix: fix malformed eslint config comments in rule examples docs: fix malformed eslint config comments in rule examples Feb 3, 2024
@eslint-github-bot eslint-github-bot bot added the documentation Relates to ESLint's documentation label Feb 3, 2024
@mdjermanovic mdjermanovic removed the bug ESLint is working incorrectly label Feb 3, 2024
@mdjermanovic
Copy link
Member

This fatal error should not be allowed to occur in rule examples because it makes the example code unparsable even if the syntax is correct

Code with a malformed config comment is still parsed and rules are run. Linter just adds an error for the comment.

@mdjermanovic mdjermanovic added the accepted There is consensus among the team that this change meets the criteria for inclusion label Feb 4, 2024
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Seems good to avoid these comments as the errors would show in the Playground.

@mdjermanovic mdjermanovic merged commit 9458735 into main Feb 4, 2024
18 checks passed
@mdjermanovic mdjermanovic deleted the fix-eslint-comments-in-js branch February 4, 2024 17:04
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 documentation Relates to ESLint's documentation
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

2 participants