@nkzw/eslint-plugin 1.8.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/index.js +8 -2
- package/package.json +10 -5
- package/rules/ensure-relay-types.js +39 -0
- package/rules/no-instanceof.js +1 -3
- package/rules/require-use-effect-arguments.js +47 -0
- package/test.js +0 -24
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
# `@nkzw/eslint-plugin`
|
|
2
2
|
|
|
3
|
-
ESLint rules for Nakazawa Tech.
|
|
3
|
+
ESLint rules for Nakazawa Tech. This plugin is automatically bundled with [`@nkzw/eslint-config`](https://github.com/cpojer/eslint-config).
|
package/index.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import noInstanceof from './rules/no-instanceof.js';
|
|
2
|
+
import requireUseEffectArguments from './rules/require-use-effect-arguments.js';
|
|
3
|
+
import ensureRelayTypes from './rules/ensure-relay-types.js';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
export default {
|
|
4
6
|
configs: {
|
|
5
7
|
strict: {
|
|
6
8
|
rules: {
|
|
9
|
+
'@nkzw/ensure-relay-types': 2,
|
|
7
10
|
'@nkzw/no-instanceof': 2,
|
|
11
|
+
'@nkzw/require-use-effect-arguments': 2,
|
|
8
12
|
},
|
|
9
13
|
},
|
|
10
14
|
},
|
|
11
15
|
rules: {
|
|
16
|
+
'ensure-relay-types': ensureRelayTypes,
|
|
12
17
|
'no-instanceof': noInstanceof,
|
|
18
|
+
'require-use-effect-arguments': requireUseEffectArguments,
|
|
13
19
|
},
|
|
14
20
|
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkzw/eslint-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "ESLint
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "ESLint plugin for Nakazawa Tech.",
|
|
5
5
|
"author": "Christoph Nakazawa <christoph.pojer@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git://github.com/
|
|
8
|
+
"url": "git://github.com/nkzw-tech/eslint-plugin.git"
|
|
9
9
|
},
|
|
10
10
|
"main": "index.js",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"index.js",
|
|
14
|
+
"rules"
|
|
15
|
+
],
|
|
11
16
|
"keywords": [],
|
|
12
17
|
"license": "MIT",
|
|
13
18
|
"devDependencies": {
|
|
14
|
-
"eslint": "^
|
|
19
|
+
"eslint": "^9.0.0"
|
|
15
20
|
},
|
|
16
21
|
"peerDependencies": {
|
|
17
|
-
"eslint": ">=
|
|
22
|
+
"eslint": ">= 9"
|
|
18
23
|
},
|
|
19
24
|
"scripts": {
|
|
20
25
|
"test": "node test test.js"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
create(context) {
|
|
3
|
+
const trackedHooks = new Set();
|
|
4
|
+
return {
|
|
5
|
+
CallExpression(node) {
|
|
6
|
+
if (node.callee.type !== 'Identifier') {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const name = node.callee.name;
|
|
11
|
+
if (trackedHooks.has(name) && !node.typeArguments) {
|
|
12
|
+
context.report({
|
|
13
|
+
message: '`' + name + '` calls must have type parameters.',
|
|
14
|
+
node,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
ImportDeclaration(node) {
|
|
20
|
+
if (node.source.value === 'react-relay/hooks.js') {
|
|
21
|
+
for (const specifier of node.specifiers) {
|
|
22
|
+
if (
|
|
23
|
+
specifier.type === 'ImportSpecifier' &&
|
|
24
|
+
(specifier.imported.name === 'useMutation' ||
|
|
25
|
+
specifier.imported.name === 'usePaginationFragment')
|
|
26
|
+
) {
|
|
27
|
+
trackedHooks.add(specifier.local.name);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
meta: {
|
|
35
|
+
fixable: false,
|
|
36
|
+
hasSuggestions: false,
|
|
37
|
+
type: 'problem',
|
|
38
|
+
},
|
|
39
|
+
};
|
package/rules/no-instanceof.js
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
create(context) {
|
|
3
|
+
const useEffectNames = new Set();
|
|
4
|
+
return {
|
|
5
|
+
CallExpression(node) {
|
|
6
|
+
let name = null;
|
|
7
|
+
if (node.callee.type === 'Identifier') {
|
|
8
|
+
name = node.callee.name;
|
|
9
|
+
} else if (node.callee.type === 'MemberExpression') {
|
|
10
|
+
const object = node.callee.object;
|
|
11
|
+
const property = node.callee.property;
|
|
12
|
+
|
|
13
|
+
if (object.type === 'Identifier' && property.type === 'Identifier') {
|
|
14
|
+
name = `${object.name}.${property.name}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (name && useEffectNames.has(name) && node.arguments.length < 2) {
|
|
19
|
+
context.report({
|
|
20
|
+
message: `${name} must be called with a second argument (dependency array).`,
|
|
21
|
+
node,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
ImportDeclaration(node) {
|
|
27
|
+
if (node.source.value === 'react') {
|
|
28
|
+
for (const specifier of node.specifiers) {
|
|
29
|
+
if (
|
|
30
|
+
specifier.type === 'ImportSpecifier' &&
|
|
31
|
+
specifier.imported.name === 'useEffect'
|
|
32
|
+
) {
|
|
33
|
+
useEffectNames.add(specifier.local.name);
|
|
34
|
+
} else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
35
|
+
useEffectNames.add(`${specifier.local.name}.useEffect`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
meta: {
|
|
43
|
+
fixable: false,
|
|
44
|
+
hasSuggestions: false,
|
|
45
|
+
type: 'problem',
|
|
46
|
+
},
|
|
47
|
+
};
|
package/test.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const RuleTester = require('eslint').RuleTester;
|
|
2
|
-
const rule = require('./rules/no-instanceof');
|
|
3
|
-
|
|
4
|
-
const ruleTester = new RuleTester();
|
|
5
|
-
|
|
6
|
-
ruleTester.run('@nkzw/no-instanceof', rule, {
|
|
7
|
-
valid: [
|
|
8
|
-
'if (value instanceof Error) {}',
|
|
9
|
-
'if (value instanceof CustomError) {}',
|
|
10
|
-
'if (value instanceof Exception) {}',
|
|
11
|
-
'if (value instanceof CustomException) {}',
|
|
12
|
-
],
|
|
13
|
-
invalid: [
|
|
14
|
-
{
|
|
15
|
-
code: 'if (value instanceof CustomClass) {}',
|
|
16
|
-
errors: [
|
|
17
|
-
{
|
|
18
|
-
message: 'The "instanceof" operator is not allowed.',
|
|
19
|
-
type: 'BinaryExpression',
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
});
|