@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,60 +0,0 @@
1
- ---
2
- id: stencil/own-props-must-be-private
3
- title: "A component's own fields are private"
4
- languages: [typescript, tsx]
5
- fix: auto
6
- stability: preview
7
- ported_from: [stencil/own-props-must-be-private]
8
- since: 0.1.0
9
- ---
10
-
11
- A class field of a component without a Stencil decorator is `private`.
12
-
13
- **Why:** Only `@Prop()` fields reach users of the element; a public plain field suggests an API that
14
- isn't there.
15
-
16
- ```codelaw
17
- native: stencil/own-props-must-be-private
18
- ```
19
-
20
- ## Examples
21
-
22
- ### TypeScript
23
-
24
- #### Don't
25
-
26
- ```ts
27
- @Component({ tag: 'my-card' })
28
- export class Card {
29
- cache = new Map();
30
- }
31
- ```
32
-
33
- #### Do
34
-
35
- ```ts
36
- @Component({ tag: 'my-card' })
37
- export class Card {
38
- private cache = new Map();
39
- }
40
- ```
41
-
42
- ### TSX
43
-
44
- #### Don't
45
-
46
- ```tsx
47
- @Component({ tag: 'my-card' })
48
- export class Card {
49
- cache = new Map();
50
- }
51
- ```
52
-
53
- #### Do
54
-
55
- ```tsx
56
- @Component({ tag: 'my-card' })
57
- export class Card {
58
- private cache = new Map();
59
- }
60
- ```
@@ -1,67 +0,0 @@
1
- ---
2
- id: stencil/prefer-vdom-listener
3
- title: "DOM events are handled in render(), not with @Listen"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "the handler moves into the rendered markup by hand"
7
- stability: preview
8
- ported_from: [stencil/prefer-vdom-listener]
9
- since: 0.1.0
10
- ---
11
-
12
- A component handles DOM events on itself (`click`, `keydown`, …) with an `on…` handler in
13
- `render()`, not `@Listen`; `@Listen` with a `target` is fine.
14
-
15
- **Why:** Handlers in `render()` are scoped to the element they're on and cheaper than a host-wide
16
- listener.
17
-
18
- ```codelaw
19
- native: stencil/prefer-vdom-listener
20
- ```
21
-
22
- ## How to fix
23
-
24
- 1. Attach the handler in `render()` (e.g. `onClick={…}` on `<Host>`).
25
- 2. Remove the `@Listen`.
26
-
27
- ## Examples
28
-
29
- ### TypeScript
30
-
31
- #### Don't
32
-
33
- ```ts
34
- @Component({ tag: 'my-card' })
35
- export class Card {
36
- @Listen('click') onClick() {}
37
- }
38
- ```
39
-
40
- #### Do
41
-
42
- ```ts
43
- @Component({ tag: 'my-card' })
44
- export class Card {
45
- @Listen('resize', { target: 'window' }) onResize() {}
46
- }
47
- ```
48
-
49
- ### TSX
50
-
51
- #### Don't
52
-
53
- ```tsx
54
- @Component({ tag: 'my-card' })
55
- export class Card {
56
- @Listen('click') onClick() {}
57
- }
58
- ```
59
-
60
- #### Do
61
-
62
- ```tsx
63
- @Component({ tag: 'my-card' })
64
- export class Card {
65
- @Listen('resize', { target: 'window' }) onResize() {}
66
- }
67
- ```
@@ -1,63 +0,0 @@
1
- ---
2
- id: stencil/prop-readonly
3
- title: "@Prop() members are readonly unless mutable"
4
- languages: [typescript, tsx]
5
- fix: auto
6
- stability: preview
7
- ported_from: [stencil/props-must-be-readonly]
8
- since: 0.1.0
9
- ---
10
-
11
- A `@Prop()` is `readonly`, unless its options say `mutable: true`.
12
-
13
- **Why:** Props are set from outside; a component that writes one by accident fights its parent.
14
-
15
- ```codelaw
16
- native: stencil/prop-readonly
17
- ```
18
-
19
- ## Examples
20
-
21
- ### TypeScript
22
-
23
- #### Don't
24
-
25
- ```ts
26
- @Component({ tag: 'my-card' })
27
- export class Card {
28
- /** The heading. */
29
- @Prop() heading: string;
30
- }
31
- ```
32
-
33
- #### Do
34
-
35
- ```ts
36
- @Component({ tag: 'my-card' })
37
- export class Card {
38
- /** The heading. */
39
- @Prop() readonly heading: string;
40
- }
41
- ```
42
-
43
- ### TSX
44
-
45
- #### Don't
46
-
47
- ```tsx
48
- @Component({ tag: 'my-card' })
49
- export class Card {
50
- /** The heading. */
51
- @Prop() heading: string;
52
- }
53
- ```
54
-
55
- #### Do
56
-
57
- ```tsx
58
- @Component({ tag: 'my-card' })
59
- export class Card {
60
- /** The heading. */
61
- @Prop() readonly heading: string;
62
- }
63
- ```
@@ -1,68 +0,0 @@
1
- ---
2
- id: stencil/props-must-be-public
3
- title: "@Prop() members are public"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "whether the field is public API needs the author"
7
- stability: preview
8
- ported_from: [stencil/props-must-be-public]
9
- since: 0.1.0
10
- ---
11
-
12
- A `@Prop()` isn't marked `private` or `protected`.
13
-
14
- **Why:** A prop is set from outside the component; hiding it in TypeScript contradicts that.
15
-
16
- ```codelaw
17
- native: stencil/props-must-be-public
18
- ```
19
-
20
- ## How to fix
21
-
22
- 1. Remove `private`/`protected`, or make it a `@State()` if it is internal.
23
-
24
- ## Examples
25
-
26
- ### TypeScript
27
-
28
- #### Don't
29
-
30
- ```ts
31
- @Component({ tag: 'my-card' })
32
- export class Card {
33
- /** The heading. */
34
- @Prop() private readonly heading: string;
35
- }
36
- ```
37
-
38
- #### Do
39
-
40
- ```ts
41
- @Component({ tag: 'my-card' })
42
- export class Card {
43
- /** The heading. */
44
- @Prop() readonly heading: string;
45
- }
46
- ```
47
-
48
- ### TSX
49
-
50
- #### Don't
51
-
52
- ```tsx
53
- @Component({ tag: 'my-card' })
54
- export class Card {
55
- /** The heading. */
56
- @Prop() private readonly heading: string;
57
- }
58
- ```
59
-
60
- #### Do
61
-
62
- ```tsx
63
- @Component({ tag: 'my-card' })
64
- export class Card {
65
- /** The heading. */
66
- @Prop() readonly heading: string;
67
- }
68
- ```
@@ -1,66 +0,0 @@
1
- ---
2
- id: stencil/required-jsdoc
3
- title: "Public members have JSDoc"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "the documentation text needs the author"
7
- stability: preview
8
- ported_from: [stencil/required-jsdoc]
9
- since: 0.1.0
10
- ---
11
-
12
- Every `@Prop()`, `@Method()` and `@Event()` has a `/** … */` comment.
13
-
14
- **Why:** Stencil turns these comments into the component's documentation and editor hints.
15
-
16
- ```codelaw
17
- native: stencil/required-jsdoc
18
- ```
19
-
20
- ## How to fix
21
-
22
- 1. Write a `/** … */` comment above the member saying what it is for.
23
-
24
- ## Examples
25
-
26
- ### TypeScript
27
-
28
- #### Don't
29
-
30
- ```ts
31
- @Component({ tag: 'my-card' })
32
- export class Card {
33
- @Prop() readonly heading: string;
34
- }
35
- ```
36
-
37
- #### Do
38
-
39
- ```ts
40
- @Component({ tag: 'my-card' })
41
- export class Card {
42
- /** The heading shown at the top. */
43
- @Prop() readonly heading: string;
44
- }
45
- ```
46
-
47
- ### TSX
48
-
49
- #### Don't
50
-
51
- ```tsx
52
- @Component({ tag: 'my-card' })
53
- export class Card {
54
- @Prop() readonly heading: string;
55
- }
56
- ```
57
-
58
- #### Do
59
-
60
- ```tsx
61
- @Component({ tag: 'my-card' })
62
- export class Card {
63
- /** The heading shown at the top. */
64
- @Prop() readonly heading: string;
65
- }
66
- ```
@@ -1,70 +0,0 @@
1
- ---
2
- id: stencil/reserved-member-names
3
- title: "Public members don't reuse HTML element names"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "renaming a public member changes every user"
7
- stability: preview
8
- ported_from: [stencil/reserved-member-names]
9
- since: 0.1.0
10
- ---
11
-
12
- A `@Prop()` or `@Method()` isn't named after an HTML global attribute or an `HTMLElement` member
13
- (`title`, `hidden`, `id`, `click`, …).
14
-
15
- **Why:** The element already has a member of that name, so the component's version clashes with it.
16
-
17
- ```codelaw
18
- native: stencil/reserved-member-names
19
- ```
20
-
21
- ## How to fix
22
-
23
- 1. Rename the member.
24
- 2. Update its users.
25
-
26
- ## Examples
27
-
28
- ### TypeScript
29
-
30
- #### Don't
31
-
32
- ```ts
33
- @Component({ tag: 'my-card' })
34
- export class Card {
35
- /** The card's title. */
36
- @Prop() readonly title: string;
37
- }
38
- ```
39
-
40
- #### Do
41
-
42
- ```ts
43
- @Component({ tag: 'my-card' })
44
- export class Card {
45
- /** The card's heading. */
46
- @Prop() readonly heading: string;
47
- }
48
- ```
49
-
50
- ### TSX
51
-
52
- #### Don't
53
-
54
- ```tsx
55
- @Component({ tag: 'my-card' })
56
- export class Card {
57
- /** The card's title. */
58
- @Prop() readonly title: string;
59
- }
60
- ```
61
-
62
- #### Do
63
-
64
- ```tsx
65
- @Component({ tag: 'my-card' })
66
- export class Card {
67
- /** The card's heading. */
68
- @Prop() readonly heading: string;
69
- }
70
- ```
@@ -1,75 +0,0 @@
1
- ---
2
- id: stencil/strict-mutable
3
- title: "mutable: true only on props the component changes"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "whether the component should change the prop needs the author"
7
- stability: preview
8
- ported_from: [stencil/strict-mutable]
9
- since: 0.1.0
10
- ---
11
-
12
- A `@Prop({ mutable: true })` is assigned somewhere in the component.
13
-
14
- **Why:** `mutable: true` says the component changes the prop; if it never does, the flag only hides
15
- that the prop should be `readonly`.
16
-
17
- ```codelaw
18
- native: stencil/strict-mutable
19
- ```
20
-
21
- ## How to fix
22
-
23
- 1. Remove `mutable: true` and make the prop `readonly`, or assign it where the component means to.
24
-
25
- ## Examples
26
-
27
- ### TypeScript
28
-
29
- #### Don't
30
-
31
- ```ts
32
- @Component({ tag: 'my-card' })
33
- export class Card {
34
- /** The count. */
35
- @Prop({ mutable: true }) count = 0;
36
- }
37
- ```
38
-
39
- #### Do
40
-
41
- ```ts
42
- @Component({ tag: 'my-card' })
43
- export class Card {
44
- /** The count. */
45
- @Prop({ mutable: true }) count = 0;
46
- private inc() {
47
- this.count++;
48
- }
49
- }
50
- ```
51
-
52
- ### TSX
53
-
54
- #### Don't
55
-
56
- ```tsx
57
- @Component({ tag: 'my-card' })
58
- export class Card {
59
- /** The count. */
60
- @Prop({ mutable: true }) count = 0;
61
- }
62
- ```
63
-
64
- #### Do
65
-
66
- ```tsx
67
- @Component({ tag: 'my-card' })
68
- export class Card {
69
- /** The count. */
70
- @Prop({ mutable: true }) count = 0;
71
- private inc() {
72
- this.count++;
73
- }
74
- }
75
- ```
@@ -1,75 +0,0 @@
1
- ---
2
- id: stencil/tag-prefix
3
- title: "Component tags start with the project's prefix"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "renaming a tag changes every page that uses it"
7
- stability: preview
8
- options:
9
- prefix: { type: string, default: "", description: "the prefix every tag must start with" }
10
- since: 0.1.0
11
- ---
12
-
13
- Every component's `tag` starts with the project's prefix (the `prefix` option); with no prefix set,
14
- a tag still needs one.
15
-
16
- **Why:** One prefix keeps a project's elements apart from other libraries'.
17
-
18
- ```codelaw
19
- native: stencil/tag-prefix
20
- ```
21
-
22
- ## How to fix
23
-
24
- 1. Rename the tag to start with the project's prefix.
25
- 2. Update every usage of the element.
26
-
27
- ## Examples
28
-
29
- ### TypeScript
30
-
31
- #### Don't
32
-
33
- ```ts
34
- @Component({ tag: 'card' })
35
- export class Card {
36
- render() {
37
- return null;
38
- }
39
- }
40
- ```
41
-
42
- #### Do
43
-
44
- ```ts
45
- @Component({ tag: 'acme-card' })
46
- export class Card {
47
- render() {
48
- return null;
49
- }
50
- }
51
- ```
52
-
53
- ### TSX
54
-
55
- #### Don't
56
-
57
- ```tsx
58
- @Component({ tag: 'card' })
59
- export class Card {
60
- render() {
61
- return null;
62
- }
63
- }
64
- ```
65
-
66
- #### Do
67
-
68
- ```tsx
69
- @Component({ tag: 'acme-card' })
70
- export class Card {
71
- render() {
72
- return null;
73
- }
74
- }
75
- ```
@@ -1,64 +0,0 @@
1
- ---
2
- id: ts/ban-ts-comment
3
- title: "No @ts-ignore or @ts-nocheck; @ts-expect-error says why"
4
- languages: [typescript, tsx]
5
- fix: manual
6
- fix_reason: "the reason the error is expected has to come from the author"
7
- stability: preview
8
- ported_from: [typescript-eslint/ban-ts-comment]
9
- since: 0.1.0
10
- ---
11
-
12
- Type-checking is never switched off with `@ts-ignore` or `@ts-nocheck`, and a `@ts-expect-error`
13
- says why the error is expected.
14
-
15
- **Why:** `@ts-ignore` hides an error for good, even after the code it excused changes; `@ts-expect-
16
- error` fails as soon as the error is gone.
17
-
18
- ```codelaw
19
- match:
20
- kind: comment
21
- any:
22
- - regex: ^(//|/\*)\s*@ts-(ignore|nocheck)\b
23
- - regex: ^(//|/\*)\s*@ts-expect-error\s*(\*/)?$
24
- message: "Don't silence the compiler with `@ts-ignore` or `@ts-nocheck`; use `@ts-expect-error: <why>`"
25
- ```
26
-
27
- ## How to fix
28
-
29
- 1. Fix the type error if you can.
30
- 2. Otherwise replace the comment with `// @ts-expect-error: <why>`.
31
-
32
- ## Examples
33
-
34
- ### TypeScript
35
-
36
- #### Don't
37
-
38
- ```ts
39
- // @ts-ignore
40
- const n: number = "1";
41
- ```
42
-
43
- #### Do
44
-
45
- ```ts
46
- // @ts-expect-error: the fixture checks the compiler's message
47
- const n: number = "1";
48
- ```
49
-
50
- ### TSX
51
-
52
- #### Don't
53
-
54
- ```tsx
55
- // @ts-ignore
56
- const n: number = "1";
57
- ```
58
-
59
- #### Do
60
-
61
- ```tsx
62
- // @ts-expect-error: the fixture checks the compiler's message
63
- const n: number = "1";
64
- ```
@@ -1,58 +0,0 @@
1
- ---
2
- id: ts/no-array-constructor
3
- title: "No Array constructor with several arguments"
4
- languages: [typescript, tsx]
5
- fix: auto
6
- stability: preview
7
- ported_from: [typescript-eslint/no-array-constructor, eslint/no-array-constructor]
8
- since: 0.1.0
9
- ---
10
-
11
- Arrays are built with literals; `new Array(n)` with one argument (a length) is allowed.
12
-
13
- **Why:** `new Array(a, b)` and `new Array(n)` mean different things, and the literal says what it
14
- means.
15
-
16
- ```codelaw
17
- match:
18
- any:
19
- - pattern: new Array($$$ARGS)
20
- - pattern: Array($$$ARGS)
21
- not:
22
- any:
23
- - pattern: new Array($ONE)
24
- - pattern: Array($ONE)
25
- - has: { field: type_arguments, pattern: $T }
26
- message: "Use an array literal instead of the Array constructor"
27
- fix: "[$$$ARGS]"
28
- ```
29
-
30
- ## Examples
31
-
32
- ### TypeScript
33
-
34
- #### Don't
35
-
36
- ```ts
37
- const xs = new Array(1, 2, 3);
38
- ```
39
-
40
- #### Do
41
-
42
- ```ts
43
- const xs = [1, 2, 3];
44
- ```
45
-
46
- ### TSX
47
-
48
- #### Don't
49
-
50
- ```tsx
51
- const xs = new Array(1, 2, 3);
52
- ```
53
-
54
- #### Do
55
-
56
- ```tsx
57
- const xs = [1, 2, 3];
58
- ```