@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.
- package/NOTICE +0 -9
- package/README.md +14 -47
- package/codelaw-pack.toml +3 -3
- package/corpus.toml +76 -0
- package/package.json +2 -2
- package/presets/js/conventions.toml +0 -4
- package/presets/js/project.toml +4 -0
- package/presets/js/typescript.toml +7 -0
- package/data/node/deprecated-api.json +0 -83
- package/data/react/dom-property-aliases.json +0 -131
- package/presets/node/recommended.toml +0 -13
- package/presets/react/recommended.toml +0 -22
- package/presets/stencil/recommended.toml +0 -18
- package/presets/ts/recommended.toml +0 -27
- package/rules/node/hashbang.md +0 -71
- package/rules/node/no-deprecated-api.md +0 -91
- package/rules/node/no-exports-assign.md +0 -92
- package/rules/node/no-extraneous-import.md +0 -118
- package/rules/node/no-extraneous-require.md +0 -117
- package/rules/node/no-missing-import.md +0 -118
- package/rules/node/no-missing-require.md +0 -117
- package/rules/node/no-process-exit.md +0 -99
- package/rules/node/no-unpublished-import.md +0 -134
- package/rules/node/no-unpublished-require.md +0 -133
- package/rules/react/display-name.md +0 -91
- package/rules/react/exhaustive-deps.md +0 -116
- package/rules/react/hook-prefix.md +0 -108
- package/rules/react/jsx-key.md +0 -99
- package/rules/react/jsx-no-comment-textnodes.md +0 -87
- package/rules/react/jsx-no-duplicate-props.md +0 -66
- package/rules/react/jsx-no-target-blank.md +0 -78
- package/rules/react/jsx-no-undef.md +0 -78
- package/rules/react/no-children-prop.md +0 -80
- package/rules/react/no-danger-with-children.md +0 -83
- package/rules/react/no-deprecated.md +0 -84
- package/rules/react/no-direct-mutation-state.md +0 -102
- package/rules/react/no-find-dom-node.md +0 -72
- package/rules/react/no-is-mounted.md +0 -109
- package/rules/react/no-render-return-value.md +0 -75
- package/rules/react/no-string-refs.md +0 -72
- package/rules/react/no-unescaped-entities.md +0 -69
- package/rules/react/no-unknown-property.md +0 -69
- package/rules/react/props-type-name.md +0 -43
- package/rules/react/require-render-return.md +0 -91
- package/rules/react/rules-of-hooks.md +0 -128
- package/rules/stencil/ban-default-true.md +0 -70
- package/rules/stencil/ban-exported-const-enums.md +0 -60
- package/rules/stencil/ban-prefix.md +0 -76
- package/rules/stencil/decorators-context.md +0 -61
- package/rules/stencil/host-data-deprecated.md +0 -73
- package/rules/stencil/methods-must-be-public.md +0 -69
- package/rules/stencil/no-unused-watch.md +0 -68
- package/rules/stencil/own-methods-must-be-private.md +0 -68
- package/rules/stencil/own-props-must-be-private.md +0 -60
- package/rules/stencil/prefer-vdom-listener.md +0 -67
- package/rules/stencil/prop-readonly.md +0 -63
- package/rules/stencil/props-must-be-public.md +0 -68
- package/rules/stencil/required-jsdoc.md +0 -66
- package/rules/stencil/reserved-member-names.md +0 -70
- package/rules/stencil/strict-mutable.md +0 -75
- package/rules/stencil/tag-prefix.md +0 -75
- package/rules/ts/ban-ts-comment.md +0 -64
- package/rules/ts/no-array-constructor.md +0 -58
- package/rules/ts/no-duplicate-enum-values.md +0 -65
- package/rules/ts/no-empty-object-type.md +0 -65
- package/rules/ts/no-explicit-any.md +0 -61
- package/rules/ts/no-extra-non-null-assertion.md +0 -50
- package/rules/ts/no-misused-new.md +0 -70
- package/rules/ts/no-namespace.md +0 -65
- package/rules/ts/no-non-null-asserted-optional-chain.md +0 -55
- package/rules/ts/no-require-imports.md +0 -54
- package/rules/ts/no-this-alias.md +0 -68
- package/rules/ts/no-unnecessary-type-constraint.md +0 -64
- package/rules/ts/no-unsafe-declaration-merging.md +0 -73
- package/rules/ts/no-unsafe-function-type.md +0 -57
- package/rules/ts/no-unused-expressions.md +0 -61
- package/rules/ts/no-unused-vars.md +0 -68
- package/rules/ts/no-wrapper-object-types.md +0 -49
- package/rules/ts/prefer-as-const.md +0 -47
- package/rules/ts/prefer-namespace-keyword.md +0 -63
- package/rules/ts/triple-slash-reference.md +0 -60
- package/rules/ts/type-only-imports.md +0 -57
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: react/rules-of-hooks
|
|
3
|
-
title: "Hooks are called at the top level of components and hooks"
|
|
4
|
-
languages: [javascript, jsx, typescript, tsx]
|
|
5
|
-
fix: manual
|
|
6
|
-
fix_reason: "moving a hook can change what the code does on the renders that skipped it"
|
|
7
|
-
stability: preview
|
|
8
|
-
ported_from: [eslint-plugin-react-hooks/rules-of-hooks]
|
|
9
|
-
since: 0.1.0
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
Hooks (`useState`, `useEffect`, any `use…`) are called only at the top level of a function component
|
|
13
|
-
or a custom hook: not in conditions, loops, nested functions, after an early return, in classes, or
|
|
14
|
-
in plain functions.
|
|
15
|
-
|
|
16
|
-
**Why:** React matches hook calls to state by their order, so a hook that runs on some renders and
|
|
17
|
-
not others mixes up every hook after it.
|
|
18
|
-
|
|
19
|
-
```codelaw
|
|
20
|
-
native: react/rules-of-hooks
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## How to fix
|
|
24
|
-
|
|
25
|
-
1. Move the hook call to the top level of the component or hook, before any early return.
|
|
26
|
-
2. Put the condition inside the hook (e.g. inside the effect) instead of around it.
|
|
27
|
-
|
|
28
|
-
## Examples
|
|
29
|
-
|
|
30
|
-
### JavaScript
|
|
31
|
-
|
|
32
|
-
#### Don't
|
|
33
|
-
|
|
34
|
-
```js
|
|
35
|
-
function Profile({ id }) {
|
|
36
|
-
if (!id) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
const [user] = useState(null);
|
|
40
|
-
return user;
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
#### Do
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
function Profile({ id }) {
|
|
48
|
-
const [user] = useState(null);
|
|
49
|
-
if (!id) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return user;
|
|
53
|
-
}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### JSX
|
|
57
|
-
|
|
58
|
-
#### Don't
|
|
59
|
-
|
|
60
|
-
```jsx
|
|
61
|
-
function Profile({ id }) {
|
|
62
|
-
if (!id) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
const [user] = useState(null);
|
|
66
|
-
return user;
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
#### Do
|
|
71
|
-
|
|
72
|
-
```jsx
|
|
73
|
-
function Profile({ id }) {
|
|
74
|
-
const [user] = useState(null);
|
|
75
|
-
if (!id) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
return user;
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### TypeScript
|
|
83
|
-
|
|
84
|
-
#### Don't
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
function useProfile(id: string) {
|
|
88
|
-
if (!id) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
return useState(id);
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### Do
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
function useProfile(id: string) {
|
|
99
|
-
const state = useState(id);
|
|
100
|
-
return id ? state : null;
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### TSX
|
|
105
|
-
|
|
106
|
-
#### Don't
|
|
107
|
-
|
|
108
|
-
```tsx
|
|
109
|
-
function Profile({ id }) {
|
|
110
|
-
if (!id) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
const [user] = useState(null);
|
|
114
|
-
return user;
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
#### Do
|
|
119
|
-
|
|
120
|
-
```tsx
|
|
121
|
-
function Profile({ id }) {
|
|
122
|
-
const [user] = useState(null);
|
|
123
|
-
if (!id) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
return user;
|
|
127
|
-
}
|
|
128
|
-
```
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/ban-default-true
|
|
3
|
-
title: "A boolean @Prop defaults to false"
|
|
4
|
-
languages: [typescript, tsx]
|
|
5
|
-
fix: manual
|
|
6
|
-
fix_reason: "inverting the prop renames it for every user"
|
|
7
|
-
stability: preview
|
|
8
|
-
ported_from: [stencil/ban-default-true]
|
|
9
|
-
since: 0.1.0
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
A `@Prop()` of a Stencil component doesn't default to `true`.
|
|
13
|
-
|
|
14
|
-
**Why:** An HTML boolean attribute can only switch something on; a prop that starts `true` can't be
|
|
15
|
-
turned off from markup.
|
|
16
|
-
|
|
17
|
-
```codelaw
|
|
18
|
-
native: stencil/ban-default-true
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## How to fix
|
|
22
|
-
|
|
23
|
-
1. Invert the prop's meaning so it defaults to `false` (e.g. `closable` → `hideClose`).
|
|
24
|
-
2. Update the component's markup users.
|
|
25
|
-
|
|
26
|
-
## Examples
|
|
27
|
-
|
|
28
|
-
### TypeScript
|
|
29
|
-
|
|
30
|
-
#### Don't
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
@Component({ tag: 'my-card' })
|
|
34
|
-
export class Card {
|
|
35
|
-
/** Shows the close button. */
|
|
36
|
-
@Prop() readonly closable = true;
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
#### Do
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
@Component({ tag: 'my-card' })
|
|
44
|
-
export class Card {
|
|
45
|
-
/** Hides the close button. */
|
|
46
|
-
@Prop() readonly hideClose = false;
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### TSX
|
|
51
|
-
|
|
52
|
-
#### Don't
|
|
53
|
-
|
|
54
|
-
```tsx
|
|
55
|
-
@Component({ tag: 'my-card' })
|
|
56
|
-
export class Card {
|
|
57
|
-
/** Shows the close button. */
|
|
58
|
-
@Prop() readonly closable = true;
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
#### Do
|
|
63
|
-
|
|
64
|
-
```tsx
|
|
65
|
-
@Component({ tag: 'my-card' })
|
|
66
|
-
export class Card {
|
|
67
|
-
/** Hides the close button. */
|
|
68
|
-
@Prop() readonly hideClose = false;
|
|
69
|
-
}
|
|
70
|
-
```
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/ban-exported-const-enums
|
|
3
|
-
title: "No exported const enums"
|
|
4
|
-
languages: [typescript, tsx]
|
|
5
|
-
fix: auto
|
|
6
|
-
stability: preview
|
|
7
|
-
ported_from: [stencil/ban-exported-const-enums]
|
|
8
|
-
since: 0.1.0
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
An exported enum is a plain `enum`, not a `const enum`.
|
|
12
|
-
|
|
13
|
-
**Why:** A `const enum` is erased at compile time, so code that imports it from the built bundle
|
|
14
|
-
finds nothing.
|
|
15
|
-
|
|
16
|
-
```codelaw
|
|
17
|
-
native: stencil/ban-exported-const-enums
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Examples
|
|
21
|
-
|
|
22
|
-
### TypeScript
|
|
23
|
-
|
|
24
|
-
#### Don't
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
export const enum Size {
|
|
28
|
-
Small,
|
|
29
|
-
Large,
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
#### Do
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
export enum Size {
|
|
37
|
-
Small,
|
|
38
|
-
Large,
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### TSX
|
|
43
|
-
|
|
44
|
-
#### Don't
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
export const enum Size {
|
|
48
|
-
Small,
|
|
49
|
-
Large,
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
#### Do
|
|
54
|
-
|
|
55
|
-
```tsx
|
|
56
|
-
export enum Size {
|
|
57
|
-
Small,
|
|
58
|
-
Large,
|
|
59
|
-
}
|
|
60
|
-
```
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/ban-prefix
|
|
3
|
-
title: "A component tag doesn't use a reserved 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
|
-
prefixes: { type: "string[]", default: ["stencil", "stnl", "st"] }
|
|
10
|
-
ported_from: [stencil/ban-prefix]
|
|
11
|
-
since: 0.1.0
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
A component's `tag` doesn't start with a prefix Stencil reserves (`stencil-`, `stnl-`, `st-` by
|
|
15
|
-
default; the `prefixes` option changes the list).
|
|
16
|
-
|
|
17
|
-
**Why:** Reserved prefixes may clash with Stencil's own elements.
|
|
18
|
-
|
|
19
|
-
```codelaw
|
|
20
|
-
native: stencil/ban-prefix
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## How to fix
|
|
24
|
-
|
|
25
|
-
1. Choose a prefix of your own and rename the tag.
|
|
26
|
-
2. Update every usage of the element.
|
|
27
|
-
|
|
28
|
-
## Examples
|
|
29
|
-
|
|
30
|
-
### TypeScript
|
|
31
|
-
|
|
32
|
-
#### Don't
|
|
33
|
-
|
|
34
|
-
```ts
|
|
35
|
-
@Component({ tag: 'stencil-card' })
|
|
36
|
-
export class Card {
|
|
37
|
-
render() {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
#### Do
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
@Component({ tag: 'acme-card' })
|
|
47
|
-
export class Card {
|
|
48
|
-
render() {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### TSX
|
|
55
|
-
|
|
56
|
-
#### Don't
|
|
57
|
-
|
|
58
|
-
```tsx
|
|
59
|
-
@Component({ tag: 'stencil-card' })
|
|
60
|
-
export class Card {
|
|
61
|
-
render() {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
#### Do
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
@Component({ tag: 'acme-card' })
|
|
71
|
-
export class Card {
|
|
72
|
-
render() {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/decorators-context
|
|
3
|
-
title: "Stencil decorators only inside @Component classes"
|
|
4
|
-
languages: [typescript, tsx]
|
|
5
|
-
fix: manual
|
|
6
|
-
fix_reason: "whether the class should be a component needs the author"
|
|
7
|
-
stability: preview
|
|
8
|
-
ported_from: [stencil/decorators-context]
|
|
9
|
-
since: 0.1.0
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
`@Prop`, `@State`, `@Element`, `@Method`, `@Watch`, `@Listen`, `@Event` and `@AttachInternals`
|
|
13
|
-
appear only in a class decorated with `@Component`.
|
|
14
|
-
|
|
15
|
-
**Why:** Outside a component Stencil ignores them, so the code silently does nothing.
|
|
16
|
-
|
|
17
|
-
```codelaw
|
|
18
|
-
native: stencil/decorators-context
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## How to fix
|
|
22
|
-
|
|
23
|
-
1. Make the class a `@Component`, or remove the Stencil decorators.
|
|
24
|
-
|
|
25
|
-
## Examples
|
|
26
|
-
|
|
27
|
-
### TypeScript
|
|
28
|
-
|
|
29
|
-
#### Don't
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
export class Store {
|
|
33
|
-
@State() count = 0;
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
#### Do
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
export class Store {
|
|
41
|
-
count = 0;
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### TSX
|
|
46
|
-
|
|
47
|
-
#### Don't
|
|
48
|
-
|
|
49
|
-
```tsx
|
|
50
|
-
export class Store {
|
|
51
|
-
@State() count = 0;
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### Do
|
|
56
|
-
|
|
57
|
-
```tsx
|
|
58
|
-
export class Store {
|
|
59
|
-
count = 0;
|
|
60
|
-
}
|
|
61
|
-
```
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/host-data-deprecated
|
|
3
|
-
title: "No hostData()"
|
|
4
|
-
languages: [typescript, tsx]
|
|
5
|
-
fix: manual
|
|
6
|
-
fix_reason: "the attributes move into `render()` by hand"
|
|
7
|
-
stability: preview
|
|
8
|
-
ported_from: [stencil/host-data-deprecated]
|
|
9
|
-
since: 0.1.0
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
A component doesn't define `hostData()`.
|
|
13
|
-
|
|
14
|
-
**Why:** `hostData()` is deprecated; the host element's attributes are set by rendering `<Host>`.
|
|
15
|
-
|
|
16
|
-
```codelaw
|
|
17
|
-
native: stencil/host-data-deprecated
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## How to fix
|
|
21
|
-
|
|
22
|
-
1. Render a `<Host>` element in `render()` with the attributes `hostData()` returned.
|
|
23
|
-
2. Remove `hostData()`.
|
|
24
|
-
|
|
25
|
-
## Examples
|
|
26
|
-
|
|
27
|
-
### TypeScript
|
|
28
|
-
|
|
29
|
-
#### Don't
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
@Component({ tag: 'my-card' })
|
|
33
|
-
export class Card {
|
|
34
|
-
hostData() {
|
|
35
|
-
return { class: 'card' };
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
#### Do
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
@Component({ tag: 'my-card' })
|
|
44
|
-
export class Card {
|
|
45
|
-
render() {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### TSX
|
|
52
|
-
|
|
53
|
-
#### Don't
|
|
54
|
-
|
|
55
|
-
```tsx
|
|
56
|
-
@Component({ tag: 'my-card' })
|
|
57
|
-
export class Card {
|
|
58
|
-
hostData() {
|
|
59
|
-
return { class: 'card' };
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
#### Do
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
@Component({ tag: 'my-card' })
|
|
68
|
-
export class Card {
|
|
69
|
-
render() {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
```
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/methods-must-be-public
|
|
3
|
-
title: "@Method() members are public"
|
|
4
|
-
languages: [typescript, tsx]
|
|
5
|
-
fix: manual
|
|
6
|
-
fix_reason: "whether the method is public API needs the author"
|
|
7
|
-
stability: preview
|
|
8
|
-
ported_from: [stencil/methods-must-be-public]
|
|
9
|
-
since: 0.1.0
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
A `@Method()` isn't marked `private` or `protected`.
|
|
13
|
-
|
|
14
|
-
**Why:** A `@Method()` is part of the element's public API; hiding it in TypeScript contradicts
|
|
15
|
-
that.
|
|
16
|
-
|
|
17
|
-
```codelaw
|
|
18
|
-
native: stencil/methods-must-be-public
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## How to fix
|
|
22
|
-
|
|
23
|
-
1. Remove `private`/`protected`, or remove `@Method()` if it isn't public API.
|
|
24
|
-
|
|
25
|
-
## Examples
|
|
26
|
-
|
|
27
|
-
### TypeScript
|
|
28
|
-
|
|
29
|
-
#### Don't
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
@Component({ tag: 'my-card' })
|
|
33
|
-
export class Card {
|
|
34
|
-
/** Opens the card. */
|
|
35
|
-
@Method() private async open() {}
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
#### Do
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
@Component({ tag: 'my-card' })
|
|
43
|
-
export class Card {
|
|
44
|
-
/** Opens the card. */
|
|
45
|
-
@Method() async open() {}
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### TSX
|
|
50
|
-
|
|
51
|
-
#### Don't
|
|
52
|
-
|
|
53
|
-
```tsx
|
|
54
|
-
@Component({ tag: 'my-card' })
|
|
55
|
-
export class Card {
|
|
56
|
-
/** Opens the card. */
|
|
57
|
-
@Method() private async open() {}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
#### Do
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
64
|
-
@Component({ tag: 'my-card' })
|
|
65
|
-
export class Card {
|
|
66
|
-
/** Opens the card. */
|
|
67
|
-
@Method() async open() {}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/no-unused-watch
|
|
3
|
-
title: "@Watch watches a @Prop or @State"
|
|
4
|
-
languages: [typescript, tsx]
|
|
5
|
-
fix: manual
|
|
6
|
-
fix_reason: "which member was meant needs the author"
|
|
7
|
-
stability: preview
|
|
8
|
-
ported_from: [stencil/no-unused-watch]
|
|
9
|
-
since: 0.1.0
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
`@Watch('name')` names a `@Prop` or `@State` of the same component.
|
|
13
|
-
|
|
14
|
-
**Why:** Watching anything else never fires, so the handler is dead code.
|
|
15
|
-
|
|
16
|
-
```codelaw
|
|
17
|
-
native: stencil/no-unused-watch
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## How to fix
|
|
21
|
-
|
|
22
|
-
1. Correct the name to the @Prop or @State it should watch, or remove the watcher.
|
|
23
|
-
|
|
24
|
-
## Examples
|
|
25
|
-
|
|
26
|
-
### TypeScript
|
|
27
|
-
|
|
28
|
-
#### Don't
|
|
29
|
-
|
|
30
|
-
```ts
|
|
31
|
-
@Component({ tag: 'my-card' })
|
|
32
|
-
export class Card {
|
|
33
|
-
@State() open = false;
|
|
34
|
-
@Watch('opened') onOpen() {}
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
#### Do
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
@Component({ tag: 'my-card' })
|
|
42
|
-
export class Card {
|
|
43
|
-
@State() open = false;
|
|
44
|
-
@Watch('open') onOpen() {}
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### TSX
|
|
49
|
-
|
|
50
|
-
#### Don't
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
@Component({ tag: 'my-card' })
|
|
54
|
-
export class Card {
|
|
55
|
-
@State() open = false;
|
|
56
|
-
@Watch('opened') onOpen() {}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
#### Do
|
|
61
|
-
|
|
62
|
-
```tsx
|
|
63
|
-
@Component({ tag: 'my-card' })
|
|
64
|
-
export class Card {
|
|
65
|
-
@State() open = false;
|
|
66
|
-
@Watch('open') onOpen() {}
|
|
67
|
-
}
|
|
68
|
-
```
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: stencil/own-methods-must-be-private
|
|
3
|
-
title: "A component's own methods are private"
|
|
4
|
-
languages: [typescript, tsx]
|
|
5
|
-
fix: auto
|
|
6
|
-
stability: preview
|
|
7
|
-
ported_from: [stencil/own-methods-must-be-private]
|
|
8
|
-
since: 0.1.0
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
A method of a component that isn't a `@Method()`, a lifecycle method or `render()` is `private`.
|
|
12
|
-
|
|
13
|
-
**Why:** Only `@Method()` members reach users of the element; a public own method suggests an API
|
|
14
|
-
that isn't there.
|
|
15
|
-
|
|
16
|
-
```codelaw
|
|
17
|
-
native: stencil/own-methods-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
|
-
helper() {
|
|
30
|
-
return 1;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
#### Do
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
@Component({ tag: 'my-card' })
|
|
39
|
-
export class Card {
|
|
40
|
-
private helper() {
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### TSX
|
|
47
|
-
|
|
48
|
-
#### Don't
|
|
49
|
-
|
|
50
|
-
```tsx
|
|
51
|
-
@Component({ tag: 'my-card' })
|
|
52
|
-
export class Card {
|
|
53
|
-
helper() {
|
|
54
|
-
return 1;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
#### Do
|
|
60
|
-
|
|
61
|
-
```tsx
|
|
62
|
-
@Component({ tag: 'my-card' })
|
|
63
|
-
export class Card {
|
|
64
|
-
private helper() {
|
|
65
|
-
return 1;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
```
|