-
-
Notifications
You must be signed in to change notification settings - Fork 6
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: TypeError: Error while loading rule 'no-irregular-whitespace': sourceCode.getAllComments is not a function #56
Comments
I temporarily added |
Thanks for the issue @adamlui, I am able to reproduce the error. The problem is that your conifg is applying JavaScript-only rules to JSON files, which is not an expected use case. Note that the Config objects that don't include Here's an updated version of your config file that fixes the error by ensuring that JavaScript rules only apply to files with the extension import js from '@eslint/js'
import globals from 'globals'
import json from '@eslint/json'
export default [
- js.configs.recommended,
+ {
+ files: ['**/*.js', '**/*.mjs'],
+ ...js.configs.recommended
+ },
{ ignores: ['**/*.min.js', '**/sandbox/*'] },
{
+ files: ['**/*.js', '**/*.mjs'],
rules: {
'indent': 'off', 'no-unexpected-multiline': 'off', 'key-spacing': 'off', // allow whitespace anywhere
'quotes': ['error', 'single', { 'allowTemplateLiterals': true }], // enforce single quotes except backticks to avoid escaping quotes
'comma-dangle': ['error', 'never'], // enforce no trailing commas in arrays or objects
'no-async-promise-executor': 'off', // allow promise executor functions to be async (to accomodate await lines)
'no-constant-condition': 'off', // allow constant conditions
'no-empty': 'off', // allow empty blocks
'no-inner-declarations': 'off', // allow function declarations anywhere
'no-useless-escape': 'off', // allow all escape chars cause ESLint sucks at detecting truly useless ones
'no-unused-vars': ['error', { 'caughtErrors': 'none' }] // allow unused named args in catch blocks
},
languageOptions: {
ecmaVersion: 'latest', sourceType: 'script',
globals: { ...globals.browser, ...globals.node }
}
},
{ files: ['**/*.mjs'], languageOptions: { sourceType: 'module' }},
{ files: ['**/*.json'], ignores: ['**/package-lock.json'], language: 'json/json', ...json.configs.recommended }
] For more information about targeting specific files, see the configuration files documentation. |
Thanks @fasttime it works like this! import js from '@eslint/js'
import globals from 'globals'
import json from '@eslint/json'
import markdown from '@eslint/markdown'
export default [
...markdown.configs.recommended,
{ ignores: ['**/*.min.js', '**/sandbox/*'] },
{
files: ['**/*.js', '**/*.mjs'], ...js.configs.recommended,
rules: {
'indent': 'off', 'no-unexpected-multiline': 'off', 'key-spacing': 'off', // allow whitespace anywhere
'quotes': ['error', 'single', { 'allowTemplateLiterals': true }], // enforce single quotes except backticks to avoid escaping quotes
'comma-dangle': ['error', 'never'], // enforce no trailing commas in arrays or objects
'no-async-promise-executor': 'off', // allow promise executor functions to be async (to accomodate await lines)
'no-constant-condition': 'off', // allow constant conditions
'no-empty': 'off', // allow empty blocks
'no-inner-declarations': 'off', // allow function declarations anywhere
'no-useless-escape': 'off', // allow all escape chars cause ESLint sucks at detecting truly useless ones
'no-unused-vars': ['error', { 'caughtErrors': 'none' }] // allow unused named args in catch blocks
},
languageOptions: {
ecmaVersion: 'latest', sourceType: 'script',
globals: { ...globals.browser, ...globals.node }
}
},
{ files: ['**/*.mjs'], languageOptions: { sourceType: 'module' }},
{ files: ['**/*.json'], ignores: ['**/package-lock.json'], language: 'json/json', ...json.configs.recommended },
{
files: ['**/*.md'],
rules: {
'markdown/heading-increment': 'off', // allow headings to skip levels
'markdown/fenced-code-language': 'off' // allow code blocks w/ no language specified
}
}
] However, when I try to move import js from '@eslint/js'
import globals from 'globals'
import json from '@eslint/json'
import markdown from '@eslint/markdown'
export default [
- ...markdown.configs.recommended,
{ ignores: ['**/*.min.js', '**/sandbox/*'] },
{
files: ['**/*.js', '**/*.mjs'], ...js.configs.recommended,
rules: {
'indent': 'off', 'no-unexpected-multiline': 'off', 'key-spacing': 'off', // allow whitespace anywhere
'quotes': ['error', 'single', { 'allowTemplateLiterals': true }], // enforce single quotes except backticks to avoid escaping quotes
'comma-dangle': ['error', 'never'], // enforce no trailing commas in arrays or objects
'no-async-promise-executor': 'off', // allow promise executor functions to be async (to accomodate await lines)
'no-constant-condition': 'off', // allow constant conditions
'no-empty': 'off', // allow empty blocks
'no-inner-declarations': 'off', // allow function declarations anywhere
'no-useless-escape': 'off', // allow all escape chars cause ESLint sucks at detecting truly useless ones
'no-unused-vars': ['error', { 'caughtErrors': 'none' }] // allow unused named args in catch blocks
},
languageOptions: {
ecmaVersion: 'latest', sourceType: 'script',
globals: { ...globals.browser, ...globals.node }
}
},
{ files: ['**/*.mjs'], languageOptions: { sourceType: 'module' }},
{ files: ['**/*.json'], ignores: ['**/package-lock.json'], language: 'json/json', ...json.configs.recommended },
{
- files: ['**/*.md'],
+ files: ['**/*.md'], ...markdown.configs.recommended,
rules: {
'markdown/heading-increment': 'off', // allow headings to skip levels
'markdown/fenced-code-language': 'off' // allow code blocks w/ no language specified
}
}
] I get this error:
Do you know why? Also it's interesting https://github.com/eslint/markdown?tab=readme-ov-file#configurations advises adding to top like ...
export default [
...markdown.configs.recommended
... ... yet the JS recommended obj didn't require destructuring in the working original config: ...
export default [
js.configs.recommended
... |
I double-checked the code and the recommended plugin.configs.recommended = [
/** @type {Config & {language:string}} */
({
name: "markdown/recommended",
files: ["**/*.md"],
language: "markdown/commonmark",
plugins: {
markdown: plugin,
},
rules: /** @type {RulesRecord} */ (recommendedRules),
}),
]; In this case, it is fine to use the spread syntax at the outer level: ...markdown.configs.recommended,
{
files: ['**/*.md'],
rules: {
'markdown/heading-increment': 'off', // allow headings to skip levels
'markdown/fenced-code-language': 'off' // allow code blocks w/ no language specified
}
} I agree that this inconsistency is confusing, because you have to check the docs every time to know how to include a config. On the other hand the |
I didn't get this:
You mean it is in roadmap to make @eslint/js config same structure as @eslint/markdown such that the recommended object should be specified at outer level? If so that's bad, even the @eslint/json config is so intuitive: ...
{ files: ['**/*.json'], ignores: ['**/package-lock.json'], language: 'json/json', ...json.configs.recommended },
... Also I think this is how most 3rd-party plugins sturcture it (including the eslint-json-plugin this replaced) so making @eslint/markdown that way too would be really good and make my configs (of which 30+ of my repos utilize) much more readable + easier to maintain |
I just installed eslint-plugin-yml because the eslint-plugin-json that @eslint/json replaced linted YAML, and its example config is: import eslintPluginYml from 'eslint-plugin-yml';
export default [
// add more generic rule sets here, such as:
// js.configs.recommended,
...eslintPluginYml.configs['flat/recommended'],
{
rules: {
// override/add rules settings here, such as:
// 'yml/rule-name': 'error'
}
}
]; ...but because ...
export default [
...markdown.configs.recommended, ...eslintPluginYml.configs['flat/standard'],
{
files: ['**/*.js', '**/*.mjs'], ...js.configs.recommended,
rules: {
... ... I get a similar error as before:
|
The details aren't settled yet, but if parts of the default config are moved into
We have a proposal to enable |
Environment
ESLint version: v9.14.0
@eslint/json version: v0.6.0
Node version: v22.9.0
npm version: v10.9.0
Operating System: Win10
Which language are you using?
json
What did you do?
Configuration
What did you expect to happen?
Lint the package.json
What actually happened?
Link to Minimal Reproducible Example
https://github.com/adamlui/js-utils
Participation
Additional comments
Just testing to replace 3rd-party eslint-plugin-json which hums along but this one immediately crashes.
Using
npm run lint:all
to runeslint .
The text was updated successfully, but these errors were encountered: