@nkzw/eslint-plugin 1.8.0 → 3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2023 Christoph Nakazawa
3
+ Copyright (c) 2023 Nakazawa Tech
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # `@nkzw/eslint-plugin`
2
2
 
3
- ESLint rules for Nakazawa Tech. Use this plugin together with [`@nkzw/eslint-config`](https://github.com/cpojer/eslint-config).
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,17 @@
1
- const noInstanceof = require('./rules/no-instanceof');
1
+ import noInstanceof from './rules/no-instanceof.js';
2
+ import requireUseEffectArguments from './rules/require-use-effect-arguments.js';
2
3
 
3
- module.exports = {
4
+ export default {
4
5
  configs: {
5
6
  strict: {
6
7
  rules: {
7
8
  '@nkzw/no-instanceof': 2,
9
+ '@nkzw/require-use-effect-arguments': 2,
8
10
  },
9
11
  },
10
12
  },
11
13
  rules: {
12
14
  'no-instanceof': noInstanceof,
15
+ 'require-use-effect-arguments': requireUseEffectArguments,
13
16
  },
14
17
  };
package/package.json CHANGED
@@ -1,20 +1,30 @@
1
1
  {
2
2
  "name": "@nkzw/eslint-plugin",
3
- "version": "1.8.0",
4
- "description": "ESLint plugins for Nakazawa Tech.",
3
+ "version": "3.0.0",
4
+ "description": "ESLint plugin for Nakazawa Tech.",
5
+ "keywords": [],
6
+ "license": "MIT",
5
7
  "author": "Christoph Nakazawa <christoph.pojer@gmail.com>",
6
8
  "repository": {
7
9
  "type": "git",
8
- "url": "git://github.com/cpojer/eslint-plugin.git"
10
+ "url": "git://github.com/nkzw-tech/eslint-plugin.git"
9
11
  },
12
+ "files": [
13
+ "index.js",
14
+ "rules"
15
+ ],
16
+ "type": "module",
10
17
  "main": "index.js",
11
- "keywords": [],
12
- "license": "MIT",
13
18
  "devDependencies": {
14
- "eslint": "^8.50.0"
19
+ "eslint": "^9.0.0"
15
20
  },
16
21
  "peerDependencies": {
17
- "eslint": ">= 8"
22
+ "eslint": ">= 9"
23
+ },
24
+ "peerDependenciesMeta": {
25
+ "eslint": {
26
+ "optional": true
27
+ }
18
28
  },
19
29
  "scripts": {
20
30
  "test": "node test test.js"
@@ -1,6 +1,4 @@
1
- 'use strict';
2
-
3
- module.exports = {
1
+ export default {
4
2
  create(context) {
5
3
  return {
6
4
  BinaryExpression(node) {
@@ -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
- });