[ESLint rule] prevent useRecoilCallback without a dependency array (#4411)
Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com>
This commit is contained in:
committed by
GitHub
parent
41c7cd8cf7
commit
60598bf235
@ -0,0 +1,46 @@
|
||||
import { ESLintUtils } from '@typescript-eslint/utils';
|
||||
|
||||
// NOTE: The rule will be available in ESLint configs as "@nx/workspace-useRecoilCallback-has-dependency-array"
|
||||
export const RULE_NAME = 'useRecoilCallback-has-dependency-array';
|
||||
|
||||
export const rule = ESLintUtils.RuleCreator(() => __filename)({
|
||||
name: RULE_NAME,
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description: 'Ensure `useRecoilCallback` is used with a dependency array',
|
||||
recommended: 'recommended',
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
isNecessaryDependencyArray:
|
||||
'Is necessary dependency array with useRecoilCallback',
|
||||
},
|
||||
fixable: 'code',
|
||||
},
|
||||
defaultOptions: [],
|
||||
create: (context) => {
|
||||
return {
|
||||
CallExpression: (node) => {
|
||||
const { callee } = node;
|
||||
if (
|
||||
callee.type === 'Identifier' &&
|
||||
callee.name === 'useRecoilCallback'
|
||||
) {
|
||||
const depsArg = node.arguments;
|
||||
if (depsArg.length === 1) {
|
||||
context.report({
|
||||
node: callee,
|
||||
messageId: 'isNecessaryDependencyArray',
|
||||
data: {
|
||||
callee,
|
||||
deps: depsArg[0],
|
||||
},
|
||||
fix: (fixer) => fixer.insertTextAfter(depsArg[0], ', []'),
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user