eslint / eslint

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

Bug: v9.0.0 has prevented ancestor glob patterns #18370

Closed elliottmangham closed 1 week ago

elliottmangham commented 4 weeks ago

Environment

Node version: v21.7.2 npm version: v10.5.0 Local ESLint version: 9.1.0 Global ESLint version: 9.1.0 Operating System: darwin 23.4.0

What parser are you using?

@babel/eslint-parser

What did you do?

I used to simply run eslint '../assets/source/scripts/**/*.js' and it worked perfectly. Since updating to ES Lint v9.0.0, however, it no longer works.

Below is my eslint.config.js file (formerly .eslintrc.js), which hasn't changed besides the file name.

const path = require('path');

module.exports = {
    env: {
        browser: true,
        es2021: true,
        node: true,
    },
    extends: 'eslint:recommended',
    parserOptions: {
        ecmaVersion: 'latest',
        sourceType: 'module',
    },
    settings: {
        'import/resolver': {
            node: {
                paths: [path.resolve(__dirname, 'packages')],
            },
        },
    },
    overrides: [
        {
            env: {
                node: true,
            },
            files: ['.eslintrc.{js,cjs}'],
            parserOptions: {
                sourceType: 'script',
            },
        },
    ],
    rules: {
        'no-unused-vars': 'warn',
    },
};

What did you expect to happen?

It should run ES Lint on all JS files in my ../assets/source/scripts/ directory as per my glob pattern ../assets/source/scripts/**/*.js.

What actually happened?

I get the following error:

> eslint '../assets/source/scripts/**/*.js'

Oops! Something went wrong! :(

ESLint: 9.1.0

You are linting "../assets/source/scripts/**/*.js", but all of the files matching the glob pattern "../assets/source/scripts/**/*.js" are ignored.

If you don't want to lint these files, remove the pattern "../assets/source/scripts/**/*.js" from the list of arguments passed to ESLint.

If you do want to lint these files, try the following solutions:

* Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored.
* Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.

Link to Minimal Reproducible Example

https://github.com/coderesolution/boilerplate

Participation

Additional comments

Please observe the ../ at the beginning, as the JS files are in the parent folder where I run my scripts and where my package.json file is. I have noticed that if I removed the ../ and reference JS files in the same directory or below, it works. Interesting, if I reference a single file above, like ../assets/source/scripts/app.js, this works.

This suggests that something in v9.0.0 has prevented ancestor directories/files from linting if combined with a glob pattern like **/*.js.

paulocoghi commented 3 weeks ago

I'm having the same bug, or at least a similar one.

After updating from ESLint 8.57.0 to 9.0.0 and moving .eslintrc.js to eslint.config.js (without changing anything inside it), I received the error:

Oops! Something went wrong! :(

ESLint: 9.0.0

You are linting "{src,apps,libs,test}/**/*.ts", but all of the files matching the glob pattern "{src,apps,libs,test}/**/*.ts" are ignored.

If you don't want to lint these files, remove the pattern "{src,apps,libs,test}/**/*.ts" from the list of arguments passed to ESLint.

If you do want to lint these files, try the following solutions:

* Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored.
* Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.

Here is my eslint.config.js:

const isFixMode = process.argv.includes("--fix");

module.exports = {
  parser: "@typescript-eslint/parser",
  extends: [
    "xo",
    "xo-space",
    "xo-typescript",
    "prettier",
    "plugin:import/typescript",
    "plugin:unicorn/recommended",
    "plugin:prettier/recommended",
  ],
  ignorePatterns: ["**/dist/*", "**/node_modules/*"],
  overrides: [
    {
      plugins: ["jest"],
      files: [
        "test/**/*.ts",
        "tests/**/*.ts",
        "**/*.spec.ts",
      ],
      rules: {
        "@typescript-eslint/no-unsafe-assignment": "off",
        "max-nested-callbacks": "off",
        "jest/no-focused-tests": "error",
        ...(isFixMode && {
          "jest/no-focused-tests": "warn",
        }),
      },
    },
  ],
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: "module",
  },
  env: {
    commonjs: true,
    es6: true,
    node: true,
    jest: true,
  },
  plugins: [
    "@typescript-eslint",
    "import",
    "unused-imports",
    "unicorn",
    "prettier",
  ],
  rules: {
    "prettier/prettier": ["error"],
    "@typescript-eslint/member-ordering": "off",
    "@typescript-eslint/no-unsafe-assignment": "off",
    "@typescript-eslint/no-unsafe-argument": "off",
    "@typescript-eslint/no-unsafe-call": "off",
    "@typescript-eslint/no-unsafe-return": "off",
    "no-console": "off",
    "@typescript-eslint/ban-types": "off",
    "comma-dangle": ["error", "always-multiline"],
    "unicorn/no-new-array": "off",
    "unicorn/no-reduce": "off",
    "unicorn/no-array-reduce": "off",
    "unicorn/prevent-abbreviations": [
      "error",
      {
        replacements: {
          props: false,
          args: false,
          params: false,
          env: false,
        },
      },
    ],
    "import/prefer-default-export": "off",
    "import/first": "error",
    "import/newline-after-import": "error",
    "import/no-duplicates": "error",
    "import/no-unresolved": "error",
    "import/order": [
      "error",
      {
        "newlines-between": "always",
        alphabetize: { order: "asc" },
        groups: ["builtin", "external", "internal", "parent", "sibling"],
      },
    ],
    "unused-imports/no-unused-imports-ts": "error",
    "unused-imports/no-unused-vars-ts": [
      "warn",
      {
        vars: "all",
        varsIgnorePattern: "^_",
        args: "after-used",
        argsIgnorePattern: "^_",
      },
    ],
    "@typescript-eslint/naming-convention": [
      "error",
      {
        selector: ["variable"],
        modifiers: ["const"],
        format: ["strictCamelCase", "StrictPascalCase", "UPPER_CASE"],
        leadingUnderscore: "allow",
      },
    ],
    "new-cap": "off",
  },
  settings: {
    "import/ignore": ["node_modules"],
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"],
    },
    "import/resolver": {
      typescript: {
        alwaysTryTypes: true,
      },
    },
  },
};
mdjermanovic commented 3 weeks ago

Link to Minimal Reproducible Example

https://github.com/coderesolution/boilerplate

I'm getting 404 on this link, perhaps the repo is private. Can you provide another repo where we could reproduce this?

elliottmangham commented 3 weeks ago

Link to Minimal Reproducible Example

https://github.com/coderesolution/boilerplate

I'm getting 404 on this link, perhaps the repo is private. Can you provide another repo where we could reproduce this?

Hey so sorry I posted this just before I left for vacation. I can create a reproduction mid May when I am back at the studio.

Glad to see another user has had the same issue though.

nzakas commented 3 weeks ago

@elliottmangham @paulocoghi neither of your examples are valid eslint.config.js files. Please see the migration guide for help in converting your config file.

@paulocoghi please create a StackBlitz or GitHub repo with a minimal reproduction so we can take a look.

eslint-github-bot[bot] commented 1 week ago

It looks like there wasn't enough information for us to know how to help you, so we're closing the issue.

Thanks for your understanding.