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 Config (unnamed): Key "language" in ESLint@9.5.0+ #362

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

mizdra
Copy link
Owner

@mizdra mizdra commented Sep 2, 2024

close: #360

@mizdra mizdra added the Type: Bug Bug or Bug fixes label Sep 2, 2024
@mizdra
Copy link
Owner Author

mizdra commented Sep 2, 2024

It seems that language property has been added to the object returned by ESLint.prototype.calculateConfigForFile(filePath) since ESLint v9.5.0.

Example:

{
  linterOptions: { reportUnusedDisableDirectives: 'off' },
  language: {
    fileType: 'text',
    lineStart: 1,
    columnStart: 0,
    nodeTypeKey: 'type',
    visitorKeys: [Object],
    validateLanguageOptions: [Function: validateLanguageOptions],
    matchesSelectorClass: [Function: matchesSelectorClass],
    parse: [Function: parse],
    createSourceCode: [Function: createSourceCode]
  },
  languageOptions: {
    sourceType: 'module',
    ecmaVersion: 'latest',
    parser: [Object],
    parserOptions: {}
  },
  plugins: { '@': [Object], '@typescript-eslint': [Object] },
  rules: { '@typescript-eslint/no-explicit-any': [Array] },
  files: [ '**/*.*', '**/*' ]
}

The new ESLint supports the feature of adding languages via plugins, and the language property is supposed to be for that purpose.

@mizdra
Copy link
Owner Author

mizdra commented Sep 2, 2024

The config returned from ESLint.prototype.calculateConfigForFile(filePath) is passed to Linter.prototype.verify(text, config, filePath).

const messages = linter
.verify(currentText, config, filePath)

However, Linter.prototype.verify does not seem to support language properties for some reason.

async function calculateConfigForFile(eslint: ESLint, filePath: string): Promise<Linter.FlatConfig[]> {
const configs = await eslint.calculateConfigForFile(filePath);
// `language` property has been added to the object returned by `ESLint.prototype.calculateConfigForFile(filePath)` since ESLint v9.5.0.
// But, `Linter.prototype.verify()` does not accept `language` option. So, remove it.
Copy link
Owner Author

Choose a reason for hiding this comment

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

This may be a bug of ESLint.

TODO: Send a bug report to ESLint

Copy link
Owner Author

Choose a reason for hiding this comment

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

@mizdra mizdra force-pushed the fix-unknown-language-key-in-config branch from 5aa2b66 to 68c5dcf Compare September 2, 2024 16:08
@mizdra mizdra marked this pull request as ready for review September 2, 2024 16:15
@mizdra mizdra merged commit a32d53f into main Sep 2, 2024
26 checks passed
@mizdra mizdra deleted the fix-unknown-language-key-in-config branch September 2, 2024 16:15
@mizdra mizdra changed the title Fix Config (unnamed): Key "language" Fix Config (unnamed): Key "language" in ESLint@9.5.0+ Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error [ConfigError]: Config (unnamed): Key "language" on convertErrorToWarningPerFile
1 participant