Skip to content

Commit 1f11a20

Browse files
committed
Docs updates.
1 parent 111c850 commit 1f11a20

File tree

6 files changed

+140
-12
lines changed

6 files changed

+140
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ would like to use.
100100
|| 🔧 | [solid/prefer-for](docs/prefer-for.md) | Enforce using Solid's `<For />` component for mapping an array to JSX elements. |
101101
|| 🔧 | [solid/prefer-show](docs/prefer-show.md) | Enforce using Solid's `<Show />` component for conditionally showing content. |
102102
|| | [solid/reactivity](docs/reactivity.md) | Enforce that reactive expressions (props, signals, memos, etc.) are only used in tracked scopes; otherwise, they won't update the view as expected. |
103+
|| 🔧 | [solid/self-closing-comp](docs/self-closing-comp.md) | Disallow extra closing tags for components without children. |
103104
|| 🔧 | [solid/style-prop](docs/style-prop.md) | Require CSS properties in the `style` prop to be valid and kebab-cased (ex. 'font-size'), not camel-cased (ex. 'fontSize') like in React, and that property values with dimensions are strings, not numbers with implicit 'px' units. |
104105
<!-- AUTO-GENERATED-CONTENT:END -->
105106

docs/jsx-no-script-url.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@ This rule is **an error** by default.
1010
See [this issue](https://github.com/joshwilsonvu/eslint-plugin-solid/issues/24) for rationale.
1111

1212
<!-- AUTO-GENERATED-CONTENT:START (OPTIONS) -->
13-
## Rule Options
1413

15-
```
16-
"event-handlers": ["error", { "<key>": "<value>" }]
17-
```
18-
19-
Key | Type | Description
20-
:--- | :---: | :---
21-
ignoreCase | `boolean` | if true, don't warn on ambiguously named event handlers like `onclick` or `onchange`
2214
<!-- AUTO-GENERATED-CONTENT:END -->
2315

2416
<!-- AUTO-GENERATED-CONTENT:START (CASES) -->

docs/self-closing-comp.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!-- AUTO-GENERATED-CONTENT:START (HEADER) -->
2+
# solid/self-closing-comp
3+
Disallow extra closing tags for components without children.
4+
This rule is **a warning** by default.
5+
6+
[View source](../src/rules/self-closing-comp.ts) · [View tests](../test/rules/self-closing-comp.test.ts)
7+
8+
<!-- AUTO-GENERATED-CONTENT:END -->
9+
10+
<!-- AUTO-GENERATED-CONTENT:START (OPTIONS) -->
11+
## Rule Options
12+
13+
```
14+
"self-closing-comp": ["error", { "<key>": "<value>" }]
15+
```
16+
17+
Key | Type | Description
18+
:--- | :---: | :---
19+
component | `"all" | "none"` | *Default `"all"`*.
20+
html | `"all" | "void" | "none"` | *Default `"all"`*.
21+
<!-- AUTO-GENERATED-CONTENT:END -->
22+
23+
<!-- AUTO-GENERATED-CONTENT:START (CASES) -->
24+
### Invalid Examples
25+
26+
These snippets cause lint errors, and some can be auto-fixed.
27+
28+
```js
29+
let el = <div></div>;
30+
// after eslint --fix:
31+
let el = <div />;
32+
33+
let el = <img></img>;
34+
// after eslint --fix:
35+
let el = <img />;
36+
37+
/* eslint solid/self-closing-comp: ["error", { "html": "void" }] */
38+
let el = <div />;
39+
// after eslint --fix:
40+
let el = <div></div>;
41+
42+
/* eslint solid/self-closing-comp: ["error", { "html": "void" }] */
43+
let el = <div />;
44+
// after eslint --fix:
45+
let el = <div></div>;
46+
47+
/* eslint solid/self-closing-comp: ["error", { "html": "none" }] */
48+
let el = <img />;
49+
// after eslint --fix:
50+
let el = <img></img>;
51+
52+
/* eslint solid/self-closing-comp: ["error", { "html": "none" }] */
53+
let el = <img />;
54+
// after eslint --fix:
55+
let el = <img></img>;
56+
57+
let el = <div></div>;
58+
// after eslint --fix:
59+
let el = <div />;
60+
61+
let el = <Component></Component>;
62+
// after eslint --fix:
63+
let el = <Component />;
64+
65+
/* eslint solid/self-closing-comp: ["error", { "component": "none" }] */
66+
let el = <Component />;
67+
// after eslint --fix:
68+
let el = <Component></Component>;
69+
70+
```
71+
72+
### Valid Examples
73+
74+
These snippets don't cause lint errors.
75+
76+
```js
77+
let el = <Component name="Foo" />;
78+
79+
let el = <Compound.Component name="Foo" />;
80+
81+
let el = (
82+
<Component>
83+
<img src="picture.png" />
84+
</Component>
85+
);
86+
87+
let el = (
88+
<Compound.Component>
89+
<img src="picture.png" />
90+
</Compound.Component>
91+
);
92+
93+
let el = (
94+
<Component>
95+
<Component name="Foo" />
96+
</Component>
97+
);
98+
99+
let el = (
100+
<Compound.Component>
101+
<Compound.Component />
102+
</Compound.Component>
103+
);
104+
105+
let el = <Component name="Foo"> </Component>;
106+
107+
let el = <Compound.Component name="Foo"> </Compound.Component>;
108+
109+
let el = <Component name="Foo"> </Component>;
110+
111+
let el = <div>&nbsp;</div>;
112+
113+
let el = <div> </div>;
114+
115+
/* eslint solid/self-closing-comp: ["error", { "html": "none" }] */
116+
let el = <div></div>;
117+
118+
/* eslint solid/self-closing-comp: ["error", { "html": "none" }] */
119+
let el = <img></img>;
120+
121+
/* eslint solid/self-closing-comp: ["error", { "html": "void" }] */
122+
let el = <div></div>;
123+
124+
/* eslint solid/self-closing-comp: ["error", { "html": "none" }] */
125+
let el = <div></div>;
126+
127+
/* eslint solid/self-closing-comp: ["error", { "component": "none" }] */
128+
let el = <Component></Component>;
129+
130+
```
131+
<!-- AUTO-GENERATED-CONTENT:END -->

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import preferClasslist from "./rules/prefer-classlist";
1212
import preferFor from "./rules/prefer-for";
1313
import preferShow from "./rules/prefer-show";
1414
import reactivity from "./rules/reactivity";
15+
import selfClosingComp from "./rules/self-closing-comp";
1516
import styleProp from "./rules/style-prop";
17+
// import validateJsxNesting from "./rules/validate-jsx-nesting";
1618

1719
const allRules = {
1820
"components-return-once": componentsReturnOnce,
@@ -25,12 +27,13 @@ const allRules = {
2527
"no-innerhtml": noInnerHTML,
2628
"no-react-specific-props": noReactSpecificProps,
2729
"no-unknown-namespaces": noUnknownNamespaces,
28-
// noUselessKeys,
2930
"prefer-classlist": preferClasslist,
3031
"prefer-for": preferFor,
3132
"prefer-show": preferShow,
3233
reactivity,
34+
"self-closing-comp": selfClosingComp,
3335
"style-prop": styleProp,
36+
// "validate-jsx-nesting": validateJsxNesting
3437
};
3538

3639
// Must be module.exports for eslint to load everything
@@ -69,6 +72,7 @@ module.exports = {
6972
"solid/style-prop": 1,
7073
"solid/no-react-specific-props": 1,
7174
"solid/prefer-classlist": 1,
75+
"solid/self-closing-comp": 1,
7276
// handled by Solid compiler, opt-in style suggestion
7377
"solid/prefer-show": 0,
7478
},
@@ -97,6 +101,7 @@ module.exports = {
97101
"solid/style-prop": 1,
98102
"solid/no-react-specific-props": 1,
99103
"solid/prefer-classlist": 1,
104+
"solid/self-closing-comp": 1,
100105
// namespaces taken care of by TS
101106
"solid/no-unknown-namespaces": 0,
102107
// handled by Solid compiler, opt-in style suggestion

src/rules/jsx-no-script-url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TSESTree as T, TSESLint, ASTUtils } from "@typescript-eslint/utils";
1+
import { TSESLint, ASTUtils } from "@typescript-eslint/utils";
22
const { getStaticValue } = ASTUtils;
33

44
// A javascript: URL can contain leading C0 control or \u0020 SPACE,

src/rules/self-closing-comp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TSESTree as T, TSESLint } from "@typescript-eslint/utils";
2-
import { isDoStatement } from "typescript";
32
import { isDOMElementName } from "../utils";
43

54
function isComponent(node: T.JSXOpeningElement) {
@@ -41,7 +40,7 @@ const rule: TSESLint.RuleModule<
4140
meta: {
4241
type: "layout",
4342
docs: {
44-
description: "Disallow extra closing tags for components without children",
43+
description: "Disallow extra closing tags for components without children.",
4544
recommended: "warn",
4645
url: "https://github.com/joshwilsonvu/eslint-plugin-solid/blob/main/docs/self-closing-comp.md",
4746
},

0 commit comments

Comments
 (0)