eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
24.39k stars 4.4k forks source link

Bug: eslint v8 with flat config and airbnb-base throws cryptic error #18380

Closed gingkapls closed 3 weeks ago

gingkapls commented 3 weeks ago

Environment

Node version: v20.12.2 npm version: 10.5.0 Local ESLint version: v8.5.7 Global ESLint version: - Operating System: Linux / NixOS 24.05

What parser are you using?

Default (Espree)

What did you do?

Configuration ```js import globals from "globals"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ {languageOptions: { globals: globals.browser }}, ...compat.extends("airbnb-base"), ]; ```
class Rectangle {
  #height = 0;
  #width;

  constructor(height, width) {
    this.#height = height;
    this.#width = width;
  }
}

What did you expect to happen?

It should complain only about unused variables and lack of linebreaks between class members.

What actually happened?

It throws a cryptic error stating 2:3 error Parsing error: Unexpected character '#' referring to the first private property of the class.

Link to Minimal Reproducible Example

https://github.com/gingkapls/eslint-issue-minimal

Participation

Additional comments

Commenting out the ...compat.extends("airbnb-base"), from the configuration file fixes the issue. Perhaps FlatCompat class is not working properly.

The configuration was created using npm init @eslint/config and choosing the options for chose the following options:

This behaviour is peculiar since there is a warning when trying to use airbnb-base with eslint v9, but there's no such warning for running it with a flat config on eslint v8, especially when it's provided as an option during the recommend way of installing.