Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
chore: migrate no-jest-import to typescript (#259)
- Loading branch information
Showing
5 changed files
with
78 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { TSESTree } from '@typescript-eslint/experimental-utils'; | ||
import { createRule } from './tsUtils'; | ||
|
||
export default createRule({ | ||
name: __filename, | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: | ||
"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.", | ||
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: node.source, messageId: 'unexpectedImport' }); | ||
}, | ||
'CallExpression[callee.name="require"][arguments.0.value="jest"]'( | ||
node: TSESTree.CallExpression, | ||
) { | ||
context.report({ | ||
node: node.arguments[0], | ||
messageId: 'unexpectedImport', | ||
}); | ||
}, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters