eslint / json

JSON language plugin for ESLint
Apache License 2.0
44 stars 4 forks source link

Bug: Error while loading rule 'logical-assignment-operators' #43

Closed danciudev closed 1 month ago

danciudev commented 1 month ago

Environment

ESLint version: 9.12.0 @eslint/json version: 0.5.0 Node version: v20.18.0 npm version: 10.8.2 Operating System: Windows 11 pnpm version: 8.14.3

Which language are you using?

json

What did you do?

Configuration
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';
import json from '@eslint/json';

export default tseslint.config(
  { ignores: ['dist'] },
  js.configs.all,
  // lint JSON files
  {
    files: ['**/*.json'],
    ignores: ['package-lock.json'],
    language: 'json/json',
    ...json.configs.recommended,
  },

  // lint JSONC files
  {
    files: ['**/*.jsonc'],
    language: 'json/jsonc',
    ...json.configs.recommended,
  },

  // lint JSON5 files
  {
    files: ['**/*.json5'],
    language: 'json/json5',
    ...json.configs.recommended,
  }
);

What did you expect to happen?

Make it work

What actually happened?

Error message:

Oops! Something went wrong! :(

ESLint: 9.12.0

TypeError: Error while loading rule 'logical-assignment-operators': sourceCode.getScope is not a function Occurred while linting C:\Users\danci\proyects\open-source\monorepo-template\apps\client\package.json at Object.create (C:\Users\danci\proyects\open-source\monorepo-template\node_modules.pnpm\eslint@9.12.0\node_modules\eslint\lib\rules\logical-assignment-operators.js:233:37) at createRuleListeners (C:\Users\danci\proyects\open-source\monorepo-template\node_modules.pnpm\eslint@9.12.0\node_modules\eslint\lib\linter\linter.js:943:21) at C:\Users\danci\proyects\open-source\monorepo-template\node_modules.pnpm\eslint@9.12.0\node_modules\eslint\lib\linter\linter.js:1068:84 at Array.forEach () at runRules (C:\Users\danci\proyects\open-source\monorepo-template\node_modules.pnpm\eslint@9.12.0\node_modules\eslint\lib\linter\linter.js:999:34) at #flatVerifyWithoutProcessors (C:\Users\danci\proyects\open-source\monorepo-template\node_modules.pnpm\eslint@9.12.0\node_modules\eslint\lib\linter\linter.js:1914:31)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/vitejs-vite-njjffd?file=eslint.config.js

Participation

Additional comments

No response

mdjermanovic commented 1 month ago

Hi @danciudev, thanks for the issue!

TypeError: Error while loading rule 'logical-assignment-operators': sourceCode.getScope is not a function Occurred while linting C:\Users\danci\proyects\open-source\monorepo-template\apps\client\package.json

This is expected behavior because JS rules can't work with JSON language.

js.configs.all,

You'll need to specify files here. Otherwise, this config object would apply to all files, including JSON files, and JS rules it enables can't work with JSON files.

- js.configs.all,
+ {
+   ...js.configs.all,
+   files: ["**/*.js", /* ... add more extensions here if needed */ ]
+ },