import-js/eslint-plugin-import

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

Open

#3.086 aberto em 16 de out. de 2024

Ver no GitHub
 (9 comments) (0 reactions) (0 assignees)JavaScript (4.946 stars) (1.540 forks)batch import
help wanted

Description

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.
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],
    },
  },
];
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,
];

Guia do colaborador