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

9.12.0: Adding a snapshot file to a directory causes TypeError: Key "rules": Key "import/no-extraneous-dependencies": Could not find plugin "import". #3086

Open
jcollum-nutrien opened this issue Oct 16, 2024 · 9 comments

Comments

@jcollum-nutrien
Copy link

jcollum-nutrien commented Oct 16, 2024

As part of normal dev work I added a snapshot (Jest) file to a workspace in my repo. This apparently broke Eslint. When I remove the snapshot file the TypeError goes away. See NOTE THIS LINE in the middle.

✗ yarn workspace foo lint:fix
yarn workspace v1.22.19
yarn run v1.22.19
$ eslint src --fix
(node:41899) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

Oops! Something went wrong! :(

ESLint: 9.12.0

TypeError: Key "rules": Key "import/no-extraneous-dependencies": Could not find plugin "import".
    at throwRuleNotFoundError (/Users/justin.collum/Documents/work/bar/node_modules/eslint/lib/config/rule-validator.js:66:11)
    at RuleValidator.validate (/Users/justin.collum/Documents/work/bar/node_modules/eslint/lib/config/rule-validator.js:147:17)
    at new Config (/Users/justin.collum/Documents/work/bar/node_modules/eslint/lib/config/config.js:240:27)
    at [finalizeConfig] (/Users/justin.collum/Documents/work/bar/node_modules/eslint/lib/config/flat-config-array.js:216:16)
    at FlatConfigArray.getConfigWithStatus (/Users/justin.collum/Documents/work/bar/node_modules/@eslint/config-array/dist/cjs/index.cjs:1102:55)
    at FlatConfigArray.getConfig (/Users/justin.collum/Documents/work/bar/node_modules/@eslint/config-array/dist/cjs/index.cjs:1120:15)
    at entryFilter (/Users/justin.collum/Documents/work/bar/node_modules/eslint/lib/eslint/eslint-helpers.js:286:40)
    at async NodeHfs.<anonymous> (file:///Users/justin.collum/Documents/work/bar/node_modules/@humanfs/core/src/hfs.js:560:24)
    at async NodeHfs.<anonymous> (file:///Users/justin.collum/Documents/work/bar/node_modules/@humanfs/core/src/hfs.js:590:6)
    at async NodeHfs.walk (file:///Users/justin.collum/Documents/work/bar/node_modules/@humanfs/core/src/hfs.js:600:3)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 2
Command: /Users/justin.collum/.nvm/versions/node/v20.14.0/bin/node
Arguments: /opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js lint:fix
Directory: /Users/justin.collum/Documents/work/bar/lambdas/cawo/queries-resolver
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.



✗ rm lambdas/baz/bip/src/__snapshots__/bop.spec.ts.snap # <<<<<<======== NOTE THIS LINE



✗ yarn workspace foo lint:fix
yarn workspace v1.22.19
yarn run v1.22.19
$ eslint src --fix
(node:42266) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=4.7.4 <5.6.0

YOUR TYPESCRIPT VERSION: 5.6.2

Please only submit bug reports when using the officially supported version.

=============
✨  Done in 1.06s.
✨  Done in 1.21s.
config
import presets from '@nutrien/data-product-eslint-config/eslint-preset.mjs';

// pull in the list of packages that are included in the base layer for lambdas
import layerPackageJson from './layers/node-dependencies/nodejs/package.json' assert { type: 'json' };
const packages = Object.keys(layerPackageJson.dependencies);

export default [
  ...presets,
  {
    rules: {
      'import/no-extraneous-dependencies': 'warn',
      // overwrite extended base eslintrc sort-keys warning
      'sort-keys': [
        'error',
        'asc',
        { caseSensitive: true, natural: false, minKeys: 6 },
      ],
    },
    settings: {
      'import/core-modules': [2, ...packages],
    },
  },
];
base config
import js from '@eslint/js';
import ts from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import prettier from 'eslint-config-prettier';
import importPlugin from 'eslint-plugin-import';
import jest from 'eslint-plugin-jest';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import globals from 'globals';

/** @type {import('eslint').Linter.Config[]} */

export default [
  {
    files: ['**/*.{js,ts,jsx,tsx}'],
    languageOptions: {
      parser: tsParser,
      globals: {
        ...globals.node,
      },
    },
    plugins: {
      js,
      ts,
      '@typescript-eslint': ts,
      simpleImportSort,
      import: importPlugin,
    },
    ignores: ['.eslintrc.*', 'jest.config.js', 'cdk.out/**/*'],
    rules: {
      ...js.configs['recommended'].rules,

      ...ts.configs['recommended'].rules,

      '@typescript-eslint/no-unused-vars': 'error',
      '@typescript-eslint/no-explicit-any': 'error',

      'import/no-duplicates': 'error',
      'import/no-cycle': 'error',
      'import/no-extraneous-dependencies': 'error',

      // https://eslint.org/docs/latest/rules/no-redeclare#handled_by_typescript
      'no-redeclare': 'off',

      'simpleImportSort/imports': [
        'error',
        {
          // adds default custom grouping for @nutrien packages
          // see https://github.com/lydell/eslint-plugin-simple-import-sort#custom-grouping
          groups: [['^\\u0000', '^@?\\w'], ['^@nutrien'], ['^', '^\\.']],
        },
      ],
      'simpleImportSort/exports': 'error',
    },
  },
  {
    files: ['**/jest.setup.ts', '**/__tests__/**/*', '**/*.{spec,test}.*'],
    plugins: {
      jest,
    },
    languageOptions: {
      globals: {
        ...globals.jest,
      },
    },
    rules: {
      ...jest.configs['recommended'].rules,

      '@typescript-eslint/explicit-function-return-type': 'off',
      '@typescript-eslint/no-empty-function': 'off',
      '@typescript-eslint/no-explicit-any': 'off',
      '@typescript-eslint/no-non-null-assertion': 'off',

      'jest/no-alias-methods': 'warn',
      'jest/prefer-to-contain': 'warn',
      'jest/prefer-to-have-length': 'warn',
    },
  },
  // should be the last config in order to override preceding rules
  prettier,
];

@ljharb
Copy link
Member

ljharb commented Oct 16, 2024

the file is named bop.spec.ts.snap., with a trailing dot?

Also, you're using eslint 9, but can you confirm the version of the import plugin you're using?

@jcollum-nutrien
Copy link
Author

the file is named bop.spec.ts.snap.,

No, that's a typo from adding spaces after the end of the word. Two spaces and OSX inserts a period.

Also, you're using eslint 9, but can you confirm the version of the import plugin you're using?

"eslint-plugin-import": "^2.27.5", which is resolving to 2.29.1 in the node modules folder.

Looks like that's out of date. I'll update and see if it fixes it.

@ljharb
Copy link
Member

ljharb commented Oct 16, 2024

Indeed, that version doesn't support eslint 9 and you shouldn't be using them together :-)

@jcollum-nutrien
Copy link
Author

I set "eslint-plugin-import": "2.31.0", in my root package.json and the error is still happening.

✗ cat node_modules/eslint-plugin-import/package.json | grep version
  "version": "2.31.0",

However I'm not convinced that ESLint is actually using 2.31.0 when running the command. Is there some way to check the versions that ESLint is using for plugins when it runs? No --verbose and --debug isn't giving me that information.

@jcollum-nutrien
Copy link
Author

jcollum-nutrien commented Oct 16, 2024

I'm trying to just ignore any __snapshot__ folder instead of having to sort all this out. But when I add

ignores: ['**/__snapshot__/']

to my root eslint config

I get an error You are linting "src", but all of the files matching the glob pattern "src" are ignored. I take out that ignores block and the problem goes away. But the docs say:

If you want to recursively ignore all directories named .config, you need to use **/.config/, as in this example:

// eslint.config.js
export default [
    {
        ignores: ["**/.config/"]
    }
];

are the underscores in the path screwing things up? I tried escaping them and then Prettier removed the escapes. I don't think you need to escape underscores in a string.

Edit: sorted it by using ignores: ['**/*.snap'], instead. This looks like a different bug or a mismatch between the docs and the software.

@ljharb
Copy link
Member

ljharb commented Oct 16, 2024

You don't need to escape underscores, no.

@jcollum-nutrien
Copy link
Author

You don't need to escape underscores, no.

I got it sorted, see Edit block in that comment.

@ljharb
Copy link
Member

ljharb commented Oct 16, 2024

Awesome! What's the mismatch you see in the docs? Let's fix it :-)

@jcollum-nutrien
Copy link
Author

jcollum-nutrien commented Oct 16, 2024

The docs say this should work (the full quote is up above):

ignores: ["**/.config/"]

but when I add

ignores: ['**/__snapshot__/']

I get an error about src being ignored. I can fix it with

ignores: ['**/*.snap'],

to ignore all of the files with .snap extension and it works fine. I don't see how adding ignores: ['**/__snapshot__/'] would result in all files in all src directories being ignored.

I still think there's an actual bug in here somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants