@codelaw/rules-js 0.1.0 → 0.2.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.
Files changed (82) hide show
  1. package/NOTICE +0 -9
  2. package/README.md +14 -47
  3. package/codelaw-pack.toml +3 -3
  4. package/corpus.toml +76 -0
  5. package/package.json +2 -2
  6. package/presets/js/conventions.toml +0 -4
  7. package/presets/js/project.toml +4 -0
  8. package/presets/js/typescript.toml +7 -0
  9. package/data/node/deprecated-api.json +0 -83
  10. package/data/react/dom-property-aliases.json +0 -131
  11. package/presets/node/recommended.toml +0 -13
  12. package/presets/react/recommended.toml +0 -22
  13. package/presets/stencil/recommended.toml +0 -18
  14. package/presets/ts/recommended.toml +0 -27
  15. package/rules/node/hashbang.md +0 -71
  16. package/rules/node/no-deprecated-api.md +0 -91
  17. package/rules/node/no-exports-assign.md +0 -92
  18. package/rules/node/no-extraneous-import.md +0 -118
  19. package/rules/node/no-extraneous-require.md +0 -117
  20. package/rules/node/no-missing-import.md +0 -118
  21. package/rules/node/no-missing-require.md +0 -117
  22. package/rules/node/no-process-exit.md +0 -99
  23. package/rules/node/no-unpublished-import.md +0 -134
  24. package/rules/node/no-unpublished-require.md +0 -133
  25. package/rules/react/display-name.md +0 -91
  26. package/rules/react/exhaustive-deps.md +0 -116
  27. package/rules/react/hook-prefix.md +0 -108
  28. package/rules/react/jsx-key.md +0 -99
  29. package/rules/react/jsx-no-comment-textnodes.md +0 -87
  30. package/rules/react/jsx-no-duplicate-props.md +0 -66
  31. package/rules/react/jsx-no-target-blank.md +0 -78
  32. package/rules/react/jsx-no-undef.md +0 -78
  33. package/rules/react/no-children-prop.md +0 -80
  34. package/rules/react/no-danger-with-children.md +0 -83
  35. package/rules/react/no-deprecated.md +0 -84
  36. package/rules/react/no-direct-mutation-state.md +0 -102
  37. package/rules/react/no-find-dom-node.md +0 -72
  38. package/rules/react/no-is-mounted.md +0 -109
  39. package/rules/react/no-render-return-value.md +0 -75
  40. package/rules/react/no-string-refs.md +0 -72
  41. package/rules/react/no-unescaped-entities.md +0 -69
  42. package/rules/react/no-unknown-property.md +0 -69
  43. package/rules/react/props-type-name.md +0 -43
  44. package/rules/react/require-render-return.md +0 -91
  45. package/rules/react/rules-of-hooks.md +0 -128
  46. package/rules/stencil/ban-default-true.md +0 -70
  47. package/rules/stencil/ban-exported-const-enums.md +0 -60
  48. package/rules/stencil/ban-prefix.md +0 -76
  49. package/rules/stencil/decorators-context.md +0 -61
  50. package/rules/stencil/host-data-deprecated.md +0 -73
  51. package/rules/stencil/methods-must-be-public.md +0 -69
  52. package/rules/stencil/no-unused-watch.md +0 -68
  53. package/rules/stencil/own-methods-must-be-private.md +0 -68
  54. package/rules/stencil/own-props-must-be-private.md +0 -60
  55. package/rules/stencil/prefer-vdom-listener.md +0 -67
  56. package/rules/stencil/prop-readonly.md +0 -63
  57. package/rules/stencil/props-must-be-public.md +0 -68
  58. package/rules/stencil/required-jsdoc.md +0 -66
  59. package/rules/stencil/reserved-member-names.md +0 -70
  60. package/rules/stencil/strict-mutable.md +0 -75
  61. package/rules/stencil/tag-prefix.md +0 -75
  62. package/rules/ts/ban-ts-comment.md +0 -64
  63. package/rules/ts/no-array-constructor.md +0 -58
  64. package/rules/ts/no-duplicate-enum-values.md +0 -65
  65. package/rules/ts/no-empty-object-type.md +0 -65
  66. package/rules/ts/no-explicit-any.md +0 -61
  67. package/rules/ts/no-extra-non-null-assertion.md +0 -50
  68. package/rules/ts/no-misused-new.md +0 -70
  69. package/rules/ts/no-namespace.md +0 -65
  70. package/rules/ts/no-non-null-asserted-optional-chain.md +0 -55
  71. package/rules/ts/no-require-imports.md +0 -54
  72. package/rules/ts/no-this-alias.md +0 -68
  73. package/rules/ts/no-unnecessary-type-constraint.md +0 -64
  74. package/rules/ts/no-unsafe-declaration-merging.md +0 -73
  75. package/rules/ts/no-unsafe-function-type.md +0 -57
  76. package/rules/ts/no-unused-expressions.md +0 -61
  77. package/rules/ts/no-unused-vars.md +0 -68
  78. package/rules/ts/no-wrapper-object-types.md +0 -49
  79. package/rules/ts/prefer-as-const.md +0 -47
  80. package/rules/ts/prefer-namespace-keyword.md +0 -63
  81. package/rules/ts/triple-slash-reference.md +0 -60
  82. package/rules/ts/type-only-imports.md +0 -57
@@ -1,91 +0,0 @@
1
- ---
2
- id: node/no-deprecated-api
3
- title: "No deprecated Node.js APIs"
4
- languages: [javascript, jsx, typescript, tsx]
5
- fix: manual
6
- fix_reason: "each deprecated API has its own replacement"
7
- stability: preview
8
- ported_from: [eslint-plugin-n/no-deprecated-api]
9
- since: 0.1.0
10
- ---
11
-
12
- Code doesn't use Node.js APIs the documentation deprecates — `new Buffer()`, `fs.exists`,
13
- `url.parse`, `util.isArray`, the `domain` module and the rest — whether reached by `import`,
14
- `require()` or a global.
15
-
16
- **Why:** Deprecated APIs are unsafe, slow or due for removal, and each has a documented replacement.
17
-
18
- ```codelaw
19
- native: node/no-deprecated-api
20
- ```
21
-
22
- ## How to fix
23
-
24
- 1. Replace the call with the API the message names.
25
-
26
- ## Examples
27
-
28
- ### JavaScript
29
-
30
- #### Don't
31
-
32
- ```js
33
- import { isArray } from "node:util";
34
- export const ok = isArray([]);
35
- ```
36
-
37
- #### Do
38
-
39
- ```js
40
- export const ok = Array.isArray([]);
41
- ```
42
-
43
- ### JSX
44
-
45
- #### Don't
46
-
47
- ```jsx
48
- import { isArray } from "node:util";
49
- export const ok = isArray([]);
50
- ```
51
-
52
- #### Do
53
-
54
- ```jsx
55
- export const ok = Array.isArray([]);
56
- ```
57
-
58
- ### TypeScript
59
-
60
- #### Don't
61
-
62
- ```ts
63
- import { isArray } from "node:util";
64
- export const ok = isArray([]);
65
- ```
66
-
67
- #### Do
68
-
69
- ```ts
70
- export const ok = Array.isArray([]);
71
- ```
72
-
73
- ### TSX
74
-
75
- #### Don't
76
-
77
- ```tsx
78
- import { isArray } from "node:util";
79
- export const ok = isArray([]);
80
- ```
81
-
82
- #### Do
83
-
84
- ```tsx
85
- export const ok = Array.isArray([]);
86
- ```
87
-
88
- ## Differences from the source
89
-
90
- The pack's `node/deprecated-api` data table lists the APIs; the Node.js version a project supports
91
- is not read.
@@ -1,92 +0,0 @@
1
- ---
2
- id: node/no-exports-assign
3
- title: "No assigning to exports"
4
- languages: [javascript, jsx, typescript, tsx]
5
- fix: manual
6
- fix_reason: "whether `module.exports` or a property was meant needs the author"
7
- stability: preview
8
- ported_from: [eslint-plugin-n/no-exports-assign]
9
- since: 0.1.0
10
- ---
11
-
12
- Code doesn't assign to the CommonJS `exports` variable; `exports = module.exports = …` is allowed.
13
-
14
- **Why:** Assigning to `exports` only rebinds a local variable, so nothing is exported.
15
-
16
- ```codelaw
17
- match:
18
- kind: assignment_expression
19
- has: { field: left, kind: identifier, regex: ^exports$, pattern: $E }
20
- not:
21
- any:
22
- - has: { field: right, regex: '^module\.exports\b' }
23
- - inside:
24
- stopBy: neighbor
25
- kind: assignment_expression
26
- has: { field: left, regex: '^module\.exports$' }
27
- where:
28
- $E: undeclared
29
- message: "Assigning to `exports` exports nothing; assign to `module.exports`"
30
- ```
31
-
32
- ## How to fix
33
-
34
- 1. Assign to `module.exports`, or set properties on `exports` (`exports.name = …`).
35
-
36
- ## Examples
37
-
38
- ### JavaScript
39
-
40
- #### Don't
41
-
42
- ```js
43
- exports = { start };
44
- ```
45
-
46
- #### Do
47
-
48
- ```js
49
- module.exports = { start };
50
- ```
51
-
52
- ### JSX
53
-
54
- #### Don't
55
-
56
- ```jsx
57
- exports = { start };
58
- ```
59
-
60
- #### Do
61
-
62
- ```jsx
63
- module.exports = { start };
64
- ```
65
-
66
- ### TypeScript
67
-
68
- #### Don't
69
-
70
- ```ts
71
- exports = { start };
72
- ```
73
-
74
- #### Do
75
-
76
- ```ts
77
- module.exports = { start };
78
- ```
79
-
80
- ### TSX
81
-
82
- #### Don't
83
-
84
- ```tsx
85
- exports = { start };
86
- ```
87
-
88
- #### Do
89
-
90
- ```tsx
91
- module.exports = { start };
92
- ```
@@ -1,118 +0,0 @@
1
- ---
2
- id: node/no-extraneous-import
3
- title: "Imported packages must be declared"
4
- languages: [javascript, jsx, typescript, tsx]
5
- scope: project
6
- fix: manual
7
- fix_reason: "which dependency field and version to add is the package owner's choice"
8
- stability: preview
9
- ported_from: [eslint-plugin-n/no-extraneous-import]
10
- since: 0.1.0
11
- ---
12
-
13
- Every package an `import`, `export … from` or `import()` names is declared in the nearest `package.json`: `dependencies`, `devDependencies`, `peerDependencies` or `optionalDependencies`.
14
-
15
- **Why:** an undeclared package works only while something else happens to install it — a hoisted monorepo dependency or a transitive one — and breaks for every user who doesn't have it.
16
-
17
- ```codelaw
18
- graph:
19
- import:
20
- form: [import, export, dynamic]
21
- declared: false
22
- message: "`$PACKAGE` is imported but not declared in `$MANIFEST`"
23
- ```
24
-
25
- ## How to fix
26
-
27
- 1. Add the package to the nearest `package.json` (`dependencies` if the shipped code needs it, `devDependencies` if only tests and tooling do), with your package manager's `add` command.
28
- 2. A type-only import is satisfied by its `@types/` package.
29
-
30
- ## Examples
31
-
32
- ### JavaScript
33
-
34
- #### Don't
35
-
36
- ```js files
37
- // package.json
38
- { "name": "app", "dependencies": { "react": "19.0.0" } }
39
- // src/app.js
40
- import lodash from "lodash";
41
- console.log(lodash);
42
- ```
43
-
44
- #### Do
45
-
46
- ```js files
47
- // package.json
48
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
49
- // src/app.js
50
- import lodash from "lodash";
51
- console.log(lodash);
52
- ```
53
-
54
- ### JSX
55
-
56
- #### Don't
57
-
58
- ```jsx files
59
- // package.json
60
- { "name": "app", "dependencies": { "react": "19.0.0" } }
61
- // src/app.jsx
62
- import lodash from "lodash";
63
- export const App = () => <p>{String(lodash)}</p>;
64
- ```
65
-
66
- #### Do
67
-
68
- ```jsx files
69
- // package.json
70
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
71
- // src/app.jsx
72
- import lodash from "lodash";
73
- export const App = () => <p>{String(lodash)}</p>;
74
- ```
75
-
76
- ### TypeScript
77
-
78
- #### Don't
79
-
80
- ```ts files
81
- // package.json
82
- { "name": "app", "dependencies": { "react": "19.0.0" } }
83
- // src/app.ts
84
- import lodash from "lodash";
85
- console.log(lodash);
86
- ```
87
-
88
- #### Do
89
-
90
- ```ts files
91
- // package.json
92
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
93
- // src/app.ts
94
- import lodash from "lodash";
95
- console.log(lodash);
96
- ```
97
-
98
- ### TSX
99
-
100
- #### Don't
101
-
102
- ```tsx files
103
- // package.json
104
- { "name": "app", "dependencies": { "react": "19.0.0" } }
105
- // src/app.tsx
106
- import lodash from "lodash";
107
- export const App = () => <p>{String(lodash)}</p>;
108
- ```
109
-
110
- #### Do
111
-
112
- ```tsx files
113
- // package.json
114
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
115
- // src/app.tsx
116
- import lodash from "lodash";
117
- export const App = () => <p>{String(lodash)}</p>;
118
- ```
@@ -1,117 +0,0 @@
1
- ---
2
- id: node/no-extraneous-require
3
- title: "Required packages must be declared"
4
- languages: [javascript, jsx, typescript, tsx]
5
- scope: project
6
- fix: manual
7
- fix_reason: "which dependency field and version to add is the package owner's choice"
8
- stability: preview
9
- ported_from: [eslint-plugin-n/no-extraneous-require]
10
- since: 0.1.0
11
- ---
12
-
13
- Every package a `require()` names is declared in the nearest `package.json`: `dependencies`, `devDependencies`, `peerDependencies` or `optionalDependencies`.
14
-
15
- **Why:** an undeclared package works only while something else happens to install it, and breaks for every user who doesn't have it.
16
-
17
- ```codelaw
18
- graph:
19
- import:
20
- form: [require]
21
- declared: false
22
- message: "`$PACKAGE` is required but not declared in `$MANIFEST`"
23
- ```
24
-
25
- ## How to fix
26
-
27
- 1. Add the package to the nearest `package.json` (`dependencies` if the shipped code needs it, `devDependencies` if only tests and tooling do), with your package manager's `add` command.
28
-
29
- ## Examples
30
-
31
- ### JavaScript
32
-
33
- #### Don't
34
-
35
- ```js files
36
- // package.json
37
- { "name": "app", "dependencies": { "react": "19.0.0" } }
38
- // src/app.js
39
- const lodash = require("lodash");
40
- console.log(lodash);
41
- ```
42
-
43
- #### Do
44
-
45
- ```js files
46
- // package.json
47
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
48
- // src/app.js
49
- const lodash = require("lodash");
50
- console.log(lodash);
51
- ```
52
-
53
- ### JSX
54
-
55
- #### Don't
56
-
57
- ```jsx files
58
- // package.json
59
- { "name": "app", "dependencies": { "react": "19.0.0" } }
60
- // src/app.jsx
61
- const lodash = require("lodash");
62
- export const App = () => <p>{String(lodash)}</p>;
63
- ```
64
-
65
- #### Do
66
-
67
- ```jsx files
68
- // package.json
69
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
70
- // src/app.jsx
71
- const lodash = require("lodash");
72
- export const App = () => <p>{String(lodash)}</p>;
73
- ```
74
-
75
- ### TypeScript
76
-
77
- #### Don't
78
-
79
- ```ts files
80
- // package.json
81
- { "name": "app", "dependencies": { "react": "19.0.0" } }
82
- // src/app.ts
83
- const lodash = require("lodash");
84
- console.log(lodash);
85
- ```
86
-
87
- #### Do
88
-
89
- ```ts files
90
- // package.json
91
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
92
- // src/app.ts
93
- const lodash = require("lodash");
94
- console.log(lodash);
95
- ```
96
-
97
- ### TSX
98
-
99
- #### Don't
100
-
101
- ```tsx files
102
- // package.json
103
- { "name": "app", "dependencies": { "react": "19.0.0" } }
104
- // src/app.tsx
105
- const lodash = require("lodash");
106
- export const App = () => <p>{String(lodash)}</p>;
107
- ```
108
-
109
- #### Do
110
-
111
- ```tsx files
112
- // package.json
113
- { "name": "app", "dependencies": { "react": "19.0.0", "lodash": "4.17.21" } }
114
- // src/app.tsx
115
- const lodash = require("lodash");
116
- export const App = () => <p>{String(lodash)}</p>;
117
- ```
@@ -1,118 +0,0 @@
1
- ---
2
- id: node/no-missing-import
3
- title: "Imported project paths must exist"
4
- languages: [javascript, jsx, typescript, tsx]
5
- scope: project
6
- fix: manual
7
- fix_reason: "the right path depends on where the module went"
8
- stability: preview
9
- ported_from: [eslint-plugin-n/no-missing-import]
10
- since: 0.1.0
11
- ---
12
-
13
- An `import`, `export … from` or `import()` path of the project — relative, absolute or a tsconfig `paths` alias — names a file that exists.
14
-
15
- **Why:** a path that names no file fails at build or load time, and only on the code path that reaches it.
16
-
17
- ```codelaw
18
- graph:
19
- import:
20
- form: [import, export, dynamic]
21
- resolves: false
22
- message: "`$SOURCE` names no file of this project"
23
- ```
24
-
25
- ## How to fix
26
-
27
- 1. Point the specifier at the file that exists (check the extension and the folder), or restore the missing file.
28
- 2. A path to a generated file the repo doesn't hold is reported too: generate it before `codelaw check`, or suppress the line with a reason.
29
-
30
- ## Examples
31
-
32
- ### JavaScript
33
-
34
- #### Don't
35
-
36
- ```js files
37
- // src/app.js
38
- import { helper } from "./helpers";
39
- console.log(helper);
40
- // src/helper.js
41
- export const helper = 1;
42
- ```
43
-
44
- #### Do
45
-
46
- ```js files
47
- // src/app.js
48
- import { helper } from "./helper";
49
- console.log(helper);
50
- // src/helper.js
51
- export const helper = 1;
52
- ```
53
-
54
- ### JSX
55
-
56
- #### Don't
57
-
58
- ```jsx files
59
- // src/app.jsx
60
- import { helper } from "./helpers";
61
- export const App = () => <p>{String(helper)}</p>;
62
- // src/helper.jsx
63
- export const helper = 1;
64
- ```
65
-
66
- #### Do
67
-
68
- ```jsx files
69
- // src/app.jsx
70
- import { helper } from "./helper";
71
- export const App = () => <p>{String(helper)}</p>;
72
- // src/helper.jsx
73
- export const helper = 1;
74
- ```
75
-
76
- ### TypeScript
77
-
78
- #### Don't
79
-
80
- ```ts files
81
- // src/app.ts
82
- import { helper } from "./helpers";
83
- console.log(helper);
84
- // src/helper.ts
85
- export const helper = 1;
86
- ```
87
-
88
- #### Do
89
-
90
- ```ts files
91
- // src/app.ts
92
- import { helper } from "./helper";
93
- console.log(helper);
94
- // src/helper.ts
95
- export const helper = 1;
96
- ```
97
-
98
- ### TSX
99
-
100
- #### Don't
101
-
102
- ```tsx files
103
- // src/app.tsx
104
- import { helper } from "./helpers";
105
- export const App = () => <p>{String(helper)}</p>;
106
- // src/helper.tsx
107
- export const helper = 1;
108
- ```
109
-
110
- #### Do
111
-
112
- ```tsx files
113
- // src/app.tsx
114
- import { helper } from "./helper";
115
- export const App = () => <p>{String(helper)}</p>;
116
- // src/helper.tsx
117
- export const helper = 1;
118
- ```
@@ -1,117 +0,0 @@
1
- ---
2
- id: node/no-missing-require
3
- title: "Required project paths must exist"
4
- languages: [javascript, jsx, typescript, tsx]
5
- scope: project
6
- fix: manual
7
- fix_reason: "the right path depends on where the module went"
8
- stability: preview
9
- ported_from: [eslint-plugin-n/no-missing-require]
10
- since: 0.1.0
11
- ---
12
-
13
- A `require()` path of the project — relative, absolute or a tsconfig `paths` alias — names a file that exists.
14
-
15
- **Why:** a path that names no file throws `MODULE_NOT_FOUND`, and only when that line runs.
16
-
17
- ```codelaw
18
- graph:
19
- import:
20
- form: [require]
21
- resolves: false
22
- message: "`$SOURCE` names no file of this project"
23
- ```
24
-
25
- ## How to fix
26
-
27
- 1. Point the specifier at the file that exists (check the extension and the folder), or restore the missing file.
28
-
29
- ## Examples
30
-
31
- ### JavaScript
32
-
33
- #### Don't
34
-
35
- ```js files
36
- // src/app.js
37
- const { helper } = require("./helpers");
38
- console.log(helper);
39
- // src/helper.js
40
- export const helper = 1;
41
- ```
42
-
43
- #### Do
44
-
45
- ```js files
46
- // src/app.js
47
- const { helper } = require("./helper");
48
- console.log(helper);
49
- // src/helper.js
50
- export const helper = 1;
51
- ```
52
-
53
- ### JSX
54
-
55
- #### Don't
56
-
57
- ```jsx files
58
- // src/app.jsx
59
- const { helper } = require("./helpers");
60
- export const App = () => <p>{String(helper)}</p>;
61
- // src/helper.jsx
62
- export const helper = 1;
63
- ```
64
-
65
- #### Do
66
-
67
- ```jsx files
68
- // src/app.jsx
69
- const { helper } = require("./helper");
70
- export const App = () => <p>{String(helper)}</p>;
71
- // src/helper.jsx
72
- export const helper = 1;
73
- ```
74
-
75
- ### TypeScript
76
-
77
- #### Don't
78
-
79
- ```ts files
80
- // src/app.ts
81
- const { helper } = require("./helpers");
82
- console.log(helper);
83
- // src/helper.ts
84
- export const helper = 1;
85
- ```
86
-
87
- #### Do
88
-
89
- ```ts files
90
- // src/app.ts
91
- const { helper } = require("./helper");
92
- console.log(helper);
93
- // src/helper.ts
94
- export const helper = 1;
95
- ```
96
-
97
- ### TSX
98
-
99
- #### Don't
100
-
101
- ```tsx files
102
- // src/app.tsx
103
- const { helper } = require("./helpers");
104
- export const App = () => <p>{String(helper)}</p>;
105
- // src/helper.tsx
106
- export const helper = 1;
107
- ```
108
-
109
- #### Do
110
-
111
- ```tsx files
112
- // src/app.tsx
113
- const { helper } = require("./helper");
114
- export const App = () => <p>{String(helper)}</p>;
115
- // src/helper.tsx
116
- export const helper = 1;
117
- ```