Skip to content

Commit aa0e95c

Browse files
committed
Add components-return-once to build.
1 parent 4dcb1a4 commit aa0e95c

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ would like to use.
8484
<!-- AUTO-GENERATED-CONTENT:START (RULES) -->
8585
|| 🔧 | Rule | Description |
8686
| :---: | :---: | :--- | :--- |
87+
|| 🔧 | [solid/components-return-once](docs/components-return-once.md) | Disallow early returns in components. Solid components only run once, and so conditionals should be inside JSX. |
8788
|| 🔧 | [solid/event-handlers](docs/event-handlers.md) | Enforce naming DOM element event handlers consistently and prevent Solid's analysis from misunderstanding whether a prop should be an event handler. |
8889
|| 🔧 | [solid/jsx-no-undef](docs/jsx-no-undef.md) | Disallow references to undefined variables in JSX. Handles custom directives. |
8990
|| | [solid/jsx-uses-vars](docs/jsx-uses-vars.md) | Prevent variables used in JSX from being marked as unused. |

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import componentsReturnOnce from "./rules/components-return-once";
12
import eventHandlers from "./rules/event-handlers";
23
import jsxNoUndef from "./rules/jsx-no-undef";
34
import jsxUsesVars from "./rules/jsx-uses-vars";
@@ -13,6 +14,7 @@ import reactivity from "./rules/reactivity";
1314
import styleProp from "./rules/style-prop";
1415

1516
const allRules = {
17+
"components-return-once": componentsReturnOnce,
1618
"event-handlers": eventHandlers,
1719
"jsx-no-undef": jsxNoUndef,
1820
"jsx-uses-vars": jsxUsesVars,
@@ -53,6 +55,7 @@ module.exports = {
5355
// incorrect usages of innerHTML are security errors
5456
"solid/no-innerhtml": [2, { allowStatic: true }],
5557
// reactivity
58+
"solid/components-return-once": 1,
5659
"solid/no-destructure": 2,
5760
"solid/prefer-for": 2,
5861
"solid/reactivity": 1,
@@ -78,6 +81,7 @@ module.exports = {
7881
// incorrect usages of innerHTML and <For /> are security or logic errors
7982
"solid/no-innerhtml": [2, { allowStatic: true }],
8083
// reactivity
84+
"solid/components-return-once": 1,
8185
"solid/no-destructure": 2,
8286
"solid/prefer-for": 2,
8387
"solid/reactivity": 1,

test/rules/components-return-once.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ export const cases = run("components-return-once", rule, {
2323
// Early returns
2424
{
2525
code: `function Component() {
26-
if (condition) {
27-
return <div />;
28-
};
29-
return <span />;
30-
}`,
26+
if (condition) {
27+
return <div />;
28+
};
29+
return <span />;
30+
}`,
31+
errors: [{ messageId: "noEarlyReturn" }],
32+
},
33+
{
34+
code: `const Component = () => {
35+
if (condition) {
36+
return <div />;
37+
}
38+
return <span />;
39+
}`,
3140
errors: [{ messageId: "noEarlyReturn" }],
3241
},
3342
// Balanced ternaries

0 commit comments

Comments
 (0)