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

Bug: comment mentionning eslint throws a parse error using jsonc. #73

Open
1 task
christophehurpeau opened this issue Dec 12, 2024 · 1 comment
Open
1 task
Labels
bug Something isn't working repro:needed This issue should include a reproducible example

Comments

@christophehurpeau
Copy link

christophehurpeau commented Dec 12, 2024

Environment

ESLint version: 9.16.0
@eslint/json version: 0.8.0
Node version: 22

Which language are you using?

jsonc

What did you do?

Configuration
{
    name: "@pob/eslint-config/base/languages/json/plugins",
    plugins: { json },
  },

  // lint JSON files
  {
    name: "@pob/eslint-config/base/languages/json/json",
    files: ["**/*.json"],
    language: "json/json",
    // @ts-ignore
    ...json.configs.recommended,
  },

  // lint JSONC files
  {
    name: "@pob/eslint-config/base/languages/json/jsonc",
    files: ["**/*.jsonc", "**/tsconfig.json", ".vscode/*.json"],
    language: "json/jsonc",
    languageOptions: {
      allowTrailingCommas: true,
    },
    // @ts-ignore
    ...json.configs.recommended,
  },

jsonc file (it's a settings.json for vscode):

{
  // npm config
  "npm.packageManager": "yarn",
  // eslint config
  "eslint.workingDirectories": ["."]
}

What did you expect to happen?

No error

What actually happened?

Failed to parse JSON from 'config': Expected property name or '}' in JSON at position 1 (line 1 column 2)eslint

Link to Minimal Reproducible Example

none

Participation

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

Additional comments

The issue is because the comment starts with "eslint" so it's considered as an eslint instruction, but it's not the case here. I've tracked the error to be from:

const parseResult = commentParser.parseJSONLikeConfig(value);
Image
@christophehurpeau christophehurpeau added bug Something isn't working repro:needed This issue should include a reproducible example labels Dec 12, 2024
@nzakas
Copy link
Member

nzakas commented Dec 13, 2024

Yes, comments beginning with "eslint" are considered directives, so you can do this:

// eslint no-unsafe-values: error
{}

If you change the capitalization of "eslint" to "ESLint", you'll avoid this error.

@nzakas nzakas added this to Triage Dec 13, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Dec 13, 2024
@nzakas nzakas moved this from Needs Triage to Triaging in Triage Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working repro:needed This issue should include a reproducible example
Projects
Status: Triaging
Development

No branches or pull requests

2 participants