From 918873beb15d4a698fe5150d826d44b696283683 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 28 Aug 2022 21:47:58 +1200 Subject: [PATCH] feat(no-jest-import): remove rule (#1220) BREAKING CHANGE: removed `no-jest-import` rule --- README.md | 1 - docs/rules/no-jest-import.md | 20 -------- .../__snapshots__/rules.test.ts.snap | 2 - src/__tests__/rules.test.ts | 2 +- src/rules/__tests__/no-jest-import.test.ts | 47 ------------------- src/rules/no-jest-import.ts | 37 --------------- 6 files changed, 1 insertion(+), 108 deletions(-) delete mode 100644 docs/rules/no-jest-import.md delete mode 100644 src/rules/__tests__/no-jest-import.test.ts delete mode 100644 src/rules/no-jest-import.ts diff --git a/README.md b/README.md index 42a578a3c..d55d31676 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,6 @@ installations requiring long-term consistency. | [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | | | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ![recommended][] | | | [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ![recommended][] | ![fixable][] | -| [no-jest-import](docs/rules/no-jest-import.md) | Disallow importing Jest | ![recommended][] | | | [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | | | [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | ![recommended][] | | | [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | | diff --git a/docs/rules/no-jest-import.md b/docs/rules/no-jest-import.md deleted file mode 100644 index 661d427e8..000000000 --- a/docs/rules/no-jest-import.md +++ /dev/null @@ -1,20 +0,0 @@ -# Disallow importing Jest (`no-jest-import`) - -The `jest` object is automatically in scope within every test file. The methods -in the `jest` object help create mocks and let you control Jest's overall -behavior. It is therefore completely unnecessary to import in `jest`, as Jest -doesn't export anything in the first place. - -### Rule details - -This rule reports on any importing of Jest. - -To name a few: `var jest = require('jest');` `const jest = require('jest');` -`import jest from 'jest';` `import {jest as test} from 'jest';` - -There is no correct usage of this code, other than to not import `jest` in the -first place. - -## Further Reading - -- [The Jest Object](https://facebook.github.io/jest/docs/en/jest-object.html) diff --git a/src/__tests__/__snapshots__/rules.test.ts.snap b/src/__tests__/__snapshots__/rules.test.ts.snap index 6e0f2c3fc..9932b994d 100644 --- a/src/__tests__/__snapshots__/rules.test.ts.snap +++ b/src/__tests__/__snapshots__/rules.test.ts.snap @@ -28,7 +28,6 @@ exports[`rules should export configs that refer to actual rules 1`] = ` "jest/no-identical-title": "error", "jest/no-interpolation-in-snapshots": "error", "jest/no-jasmine-globals": "error", - "jest/no-jest-import": "error", "jest/no-large-snapshots": "error", "jest/no-mocks-import": "error", "jest/no-restricted-matchers": "error", @@ -80,7 +79,6 @@ exports[`rules should export configs that refer to actual rules 1`] = ` "jest/no-identical-title": "error", "jest/no-interpolation-in-snapshots": "error", "jest/no-jasmine-globals": "error", - "jest/no-jest-import": "error", "jest/no-mocks-import": "error", "jest/no-standalone-expect": "error", "jest/no-test-prefixes": "error", diff --git a/src/__tests__/rules.test.ts b/src/__tests__/rules.test.ts index a8c66cc18..826bfb533 100644 --- a/src/__tests__/rules.test.ts +++ b/src/__tests__/rules.test.ts @@ -2,7 +2,7 @@ import { existsSync } from 'fs'; import { resolve } from 'path'; import plugin from '../'; -const numberOfRules = 50; +const numberOfRules = 49; const ruleNames = Object.keys(plugin.rules); const deprecatedRules = Object.entries(plugin.rules) .filter(([, rule]) => rule.meta.deprecated) diff --git a/src/rules/__tests__/no-jest-import.test.ts b/src/rules/__tests__/no-jest-import.test.ts deleted file mode 100644 index 58e554fdc..000000000 --- a/src/rules/__tests__/no-jest-import.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { TSESLint } from '@typescript-eslint/utils'; -import rule from '../no-jest-import'; -import { espreeParser } from './test-utils'; - -const ruleTester = new TSESLint.RuleTester({ - parser: espreeParser, - parserOptions: { - ecmaVersion: 2015, - }, -}); - -ruleTester.run('no-jest-import', rule, { - valid: [ - { - code: 'import something from "something"', - parserOptions: { sourceType: 'module' }, - }, - 'require("somethingElse")', - 'require()', - 'entirelyDifferent(fn)', - ], - invalid: [ - { - code: 'require("jest")', - errors: [{ endColumn: 15, column: 9, messageId: 'unexpectedImport' }], - }, - { - code: 'import jest from "jest"', - parserOptions: { sourceType: 'module' }, - errors: [{ endColumn: 24, column: 1, messageId: 'unexpectedImport' }], - }, - { - code: 'var jest = require("jest")', - errors: [{ endColumn: 26, column: 20, messageId: 'unexpectedImport' }], - }, - { - code: 'import {jest as test} from "jest"', - parserOptions: { sourceType: 'module' }, - errors: [{ endColumn: 34, column: 1, messageId: 'unexpectedImport' }], - }, - { - code: 'const jest = require("jest")', - parserOptions: { sourceType: 'module' }, - errors: [{ endColumn: 28, column: 22, messageId: 'unexpectedImport' }], - }, - ], -}); diff --git a/src/rules/no-jest-import.ts b/src/rules/no-jest-import.ts deleted file mode 100644 index 6520cf1d0..000000000 --- a/src/rules/no-jest-import.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { TSESTree } from '@typescript-eslint/utils'; -import { createRule } from './utils'; - -export default createRule({ - name: __filename, - meta: { - type: 'problem', - docs: { - description: 'Disallow importing Jest', - category: 'Best Practices', - recommended: 'error', - }, - messages: { - unexpectedImport: `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`, - }, - schema: [], - }, - defaultOptions: [], - create(context) { - return { - 'ImportDeclaration[source.value="jest"]'( - node: TSESTree.ImportDeclaration, - ) { - context.report({ node, messageId: 'unexpectedImport' }); - }, - 'CallExpression[callee.name="require"][arguments.0.value="jest"]'( - node: TSESTree.CallExpression, - ) { - context.report({ - loc: node.arguments[0].loc, - messageId: 'unexpectedImport', - node, - }); - }, - }; - }, -});