@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,57 +0,0 @@
1
- ---
2
- id: ts/no-unsafe-function-type
3
- title: "No Function type"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "the right signature needs the author"
7
- stability: preview
8
- ported_from: [typescript-eslint/no-unsafe-function-type]
9
- since: 0.1.0
10
- ---
11
-
12
- The built-in `Function` type is not used as a type.
13
-
14
- **Why:** `Function` accepts any function and its calls are unchecked, like `any` for functions.
15
-
16
- ```codelaw
17
- match:
18
- kind: type_identifier
19
- regex: ^Function$
20
- where:
21
- $$MATCH: builtin
22
- message: "`Function` accepts any function and calls it unchecked; write the signature"
23
- ```
24
-
25
- ## How to fix
26
-
27
- 1. Write the function's real signature, e.g. `(event: Event) => void`.
28
-
29
- ## Examples
30
-
31
- ### TypeScript
32
-
33
- #### Don't
34
-
35
- ```ts
36
- let handler: Function;
37
- ```
38
-
39
- #### Do
40
-
41
- ```ts
42
- let handler: (event: Event) => void;
43
- ```
44
-
45
- ### TSX
46
-
47
- #### Don't
48
-
49
- ```tsx
50
- let handler: Function;
51
- ```
52
-
53
- #### Do
54
-
55
- ```tsx
56
- let handler: (event: Event) => void;
57
- ```
@@ -1,61 +0,0 @@
1
- ---
2
- id: ts/no-unused-expressions
3
- title: "No expression statements that do nothing"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "whether a call, an assignment or nothing was meant needs the author"
7
- stability: preview
8
- ported_from: [typescript-eslint/no-unused-expressions, eslint/no-unused-expressions]
9
- since: 0.1.0
10
- ---
11
-
12
- Every expression statement does something: a call, an assignment, an update, `await`, `yield`,
13
- `delete` or `void`. Directives such as `"use strict"` are allowed.
14
-
15
- **Why:** An expression whose value is thrown away is usually a forgotten call or assignment.
16
-
17
- ```codelaw
18
- native: ts/no-unused-expressions
19
- ```
20
-
21
- ## How to fix
22
-
23
- 1. Add the call or assignment that was meant, or remove the statement.
24
-
25
- ## Examples
26
-
27
- ### TypeScript
28
-
29
- #### Don't
30
-
31
- ```ts
32
- function close(conn: Connection) {
33
- conn.close;
34
- }
35
- ```
36
-
37
- #### Do
38
-
39
- ```ts
40
- function close(conn: Connection) {
41
- conn.close();
42
- }
43
- ```
44
-
45
- ### TSX
46
-
47
- #### Don't
48
-
49
- ```tsx
50
- function close(conn: Connection) {
51
- conn.close;
52
- }
53
- ```
54
-
55
- #### Do
56
-
57
- ```tsx
58
- function close(conn: Connection) {
59
- conn.close();
60
- }
61
- ```
@@ -1,68 +0,0 @@
1
- ---
2
- id: ts/no-unused-vars
3
- title: "Every declared name is used"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "removing a declaration can drop the side effects of its initialiser"
7
- stability: preview
8
- options:
9
- vars: { type: string, default: all }
10
- args: { type: string, default: after-used }
11
- caughtErrors: { type: string, default: all }
12
- ignoreRestSiblings: { type: boolean, default: false }
13
- varsIgnorePattern: { type: string }
14
- argsIgnorePattern: { type: string }
15
- caughtErrorsIgnorePattern: { type: string }
16
- destructuredArrayIgnorePattern: { type: string }
17
- ported_from: [typescript-eslint/no-unused-vars, eslint/no-unused-vars]
18
- since: 0.1.0
19
- ---
20
-
21
- Every variable, function, class, type, interface, enum, import, parameter and caught error is used
22
- somewhere. Parameters before the last used one are allowed (`args: after-used`).
23
-
24
- **Why:** An unused declaration is dead code or a sign the code doesn't do what it was meant to.
25
-
26
- ```codelaw
27
- native: ts/no-unused-vars
28
- ```
29
-
30
- ## How to fix
31
-
32
- 1. Check the initialiser has no side effect that matters.
33
- 2. Remove the declaration, or use it where it was meant to be used.
34
- 3. For a parameter that must stay for its position, prefix it with `_` and set `argsIgnorePattern: "^_"`.
35
-
36
- ## Examples
37
-
38
- ### TypeScript
39
-
40
- #### Don't
41
-
42
- ```ts
43
- import { readFile, writeFile } from "node:fs";
44
- export const load = (path: string) => readFile(path);
45
- ```
46
-
47
- #### Do
48
-
49
- ```ts
50
- import { readFile } from "node:fs";
51
- export const load = (path: string) => readFile(path);
52
- ```
53
-
54
- ### TSX
55
-
56
- #### Don't
57
-
58
- ```tsx
59
- import { readFile, writeFile } from "node:fs";
60
- export const load = (path: string) => readFile(path);
61
- ```
62
-
63
- #### Do
64
-
65
- ```tsx
66
- import { readFile } from "node:fs";
67
- export const load = (path: string) => readFile(path);
68
- ```
@@ -1,49 +0,0 @@
1
- ---
2
- id: ts/no-wrapper-object-types
3
- title: "Primitive types, not wrapper object types"
4
- languages: [typescript, tsx]
5
- fix: auto
6
- stability: preview
7
- ported_from: [typescript-eslint/no-wrapper-object-types]
8
- since: 0.1.0
9
- ---
10
-
11
- Types use `string`, `number`, `boolean`, `symbol`, `bigint` and `object`, not the wrapper objects
12
- `String`, `Number`, `Boolean`, `Symbol`, `BigInt` and `Object`.
13
-
14
- **Why:** The wrapper types describe boxed objects almost no code uses, and accept values the
15
- primitive types reject.
16
-
17
- ```codelaw
18
- native: ts/no-wrapper-object-types
19
- ```
20
-
21
- ## Examples
22
-
23
- ### TypeScript
24
-
25
- #### Don't
26
-
27
- ```ts
28
- let label: String = "a";
29
- ```
30
-
31
- #### Do
32
-
33
- ```ts
34
- let label: string = "a";
35
- ```
36
-
37
- ### TSX
38
-
39
- #### Don't
40
-
41
- ```tsx
42
- let label: String = "a";
43
- ```
44
-
45
- #### Do
46
-
47
- ```tsx
48
- let label: string = "a";
49
- ```
@@ -1,47 +0,0 @@
1
- ---
2
- id: ts/prefer-as-const
3
- title: "as const instead of repeating a literal as its type"
4
- languages: [typescript, tsx]
5
- fix: auto
6
- stability: preview
7
- ported_from: [typescript-eslint/prefer-as-const]
8
- since: 0.1.0
9
- ---
10
-
11
- A literal cast to its own literal type (`"a" as "a"`) uses `as const` instead.
12
-
13
- **Why:** `as const` says the same thing once, and stays right when the literal changes.
14
-
15
- ```codelaw
16
- native: ts/prefer-as-const
17
- ```
18
-
19
- ## Examples
20
-
21
- ### TypeScript
22
-
23
- #### Don't
24
-
25
- ```ts
26
- const mode = "dark" as "dark";
27
- ```
28
-
29
- #### Do
30
-
31
- ```ts
32
- const mode = "dark" as const;
33
- ```
34
-
35
- ### TSX
36
-
37
- #### Don't
38
-
39
- ```tsx
40
- const mode = "dark" as "dark";
41
- ```
42
-
43
- #### Do
44
-
45
- ```tsx
46
- const mode = "dark" as const;
47
- ```
@@ -1,63 +0,0 @@
1
- ---
2
- id: ts/prefer-namespace-keyword
3
- title: "namespace, not module, for a TypeScript namespace"
4
- languages: [typescript, tsx]
5
- fix: auto
6
- stability: preview
7
- ported_from: [typescript-eslint/prefer-namespace-keyword]
8
- since: 0.1.0
9
- ---
10
-
11
- A TypeScript namespace is declared with `namespace`, not `module`; `declare module "x"` is
12
- unaffected.
13
-
14
- **Why:** `module Foo {}` is the old spelling and is easy to confuse with an external module
15
- declaration.
16
-
17
- ```codelaw
18
- match:
19
- kind: module
20
- all:
21
- - has: { field: name, kind: identifier, pattern: $NAME }
22
- - has: { field: body, pattern: $BODY }
23
- message: "Write `namespace` for a TypeScript namespace; `module` is for declaring external modules"
24
- fix: "namespace $NAME $BODY"
25
- ```
26
-
27
- ## Examples
28
-
29
- ### TypeScript
30
-
31
- #### Don't
32
-
33
- ```ts
34
- module Shapes {
35
- export const sides = 4;
36
- }
37
- ```
38
-
39
- #### Do
40
-
41
- ```ts
42
- namespace Shapes {
43
- export const sides = 4;
44
- }
45
- ```
46
-
47
- ### TSX
48
-
49
- #### Don't
50
-
51
- ```tsx
52
- module Shapes {
53
- export const sides = 4;
54
- }
55
- ```
56
-
57
- #### Do
58
-
59
- ```tsx
60
- namespace Shapes {
61
- export const sides = 4;
62
- }
63
- ```
@@ -1,60 +0,0 @@
1
- ---
2
- id: ts/triple-slash-reference
3
- title: "No /// <reference path> directives"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "the matching import needs the module path and what it provides"
7
- stability: preview
8
- ported_from: [typescript-eslint/triple-slash-reference]
9
- since: 0.1.0
10
- ---
11
-
12
- Files are connected with `import`, not `/// <reference path="…" />`.
13
-
14
- **Why:** Reference directives predate ES modules and hide dependencies from bundlers and other
15
- tools.
16
-
17
- ```codelaw
18
- match:
19
- kind: comment
20
- regex: ^///\s*<reference\s+path=
21
- message: "Use an `import` instead of a `/// <reference path>` directive"
22
- ```
23
-
24
- ## How to fix
25
-
26
- 1. Replace the directive with an `import` of the module it pointed to.
27
-
28
- ## Examples
29
-
30
- ### TypeScript
31
-
32
- #### Don't
33
-
34
- ```ts
35
- /// <reference path="./globals.d.ts" />
36
- export const x = 1;
37
- ```
38
-
39
- #### Do
40
-
41
- ```ts
42
- import "./globals";
43
- export const x = 1;
44
- ```
45
-
46
- ### TSX
47
-
48
- #### Don't
49
-
50
- ```tsx
51
- /// <reference path="./globals.d.ts" />
52
- export const x = 1;
53
- ```
54
-
55
- #### Do
56
-
57
- ```tsx
58
- import "./globals";
59
- export const x = 1;
60
- ```
@@ -1,57 +0,0 @@
1
- ---
2
- id: ts/type-only-imports
3
- title: "Names used only as types are imported with type"
4
- languages: [typescript, tsx]
5
- fix: suggest
6
- fix_reason: "a type-only import is erased, so code that relied on the module's side effects changes"
7
- stability: preview
8
- since: 0.1.0
9
- ---
10
-
11
- An imported name that the file uses only in type positions is marked `type`.
12
-
13
- **Why:** Type-only imports are erased at compile time, which keeps runtime imports honest and helps
14
- bundlers drop unused modules.
15
-
16
- ```codelaw
17
- native: ts/type-only-imports
18
- ```
19
-
20
- ## Examples
21
-
22
- ### TypeScript
23
-
24
- #### Don't
25
-
26
- ```ts
27
- import { Config, load } from "./config";
28
- export const c: Config = load();
29
- ```
30
-
31
- #### Do
32
-
33
- ```ts
34
- import { type Config, load } from "./config";
35
- export const c: Config = load();
36
- ```
37
-
38
- ### TSX
39
-
40
- #### Don't
41
-
42
- ```tsx
43
- import { Config, load } from "./config";
44
- export const c: Config = load();
45
- ```
46
-
47
- #### Do
48
-
49
- ```tsx
50
- import { type Config, load } from "./config";
51
- export const c: Config = load();
52
- ```
53
-
54
- ## Differences from the source
55
-
56
- Only within the file, without type information: a name used as a value anywhere is left alone.
57
- Default and namespace imports are reported without a fix.