Skip to content

Commit c842390

Browse files
committed
Update docs script, fixture timeouts.
1 parent 8372d35 commit c842390

File tree

9 files changed

+63
-57
lines changed

9 files changed

+63
-57
lines changed

README.md

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,25 @@ const [editedValue, setEditedValue] = createSignal(props.value);
119119
🔧: Fixable with [`eslint --fix`](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems)/IDE auto-fix.
120120

121121
<!-- AUTO-GENERATED-CONTENT:START (RULES) -->
122-
123-
|| 🔧 | Rule | Description |
124-
| :-: | :-: | :--------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
125-
|| 🔧 | [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. |
126-
|| 🔧 | [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. |
127-
|| 🔧 | [solid/imports](docs/imports.md) | Enforce consistent imports from "solid-js", "solid-js/web", and "solid-js/store". |
128-
|| | [solid/jsx-no-duplicate-props](docs/jsx-no-duplicate-props.md) | Disallow passing the same prop twice in JSX. |
129-
|| | [solid/jsx-no-script-url](docs/jsx-no-script-url.md) | Disallow javascript: URLs. |
130-
|| 🔧 | [solid/jsx-no-undef](docs/jsx-no-undef.md) | Disallow references to undefined variables in JSX. Handles custom directives. |
131-
|| | [solid/jsx-uses-vars](docs/jsx-uses-vars.md) | Prevent variables used in JSX from being marked as unused. |
132-
|| 🔧 | [solid/no-destructure](docs/no-destructure.md) | Disallow destructuring props. In Solid, props must be used with property accesses (`props.foo`) to preserve reactivity. This rule only tracks destructuring in the parameter list. |
133-
|| 🔧 | [solid/no-innerhtml](docs/no-innerhtml.md) | Disallow usage of the innerHTML attribute, which can often lead to security vulnerabilities. |
134-
|| 🔧 | [solid/no-react-specific-props](docs/no-react-specific-props.md) | Disallow usage of React-specific `className`/`htmlFor` props, which were deprecated in v1.4.0. |
135-
|| | [solid/no-unknown-namespaces](docs/no-unknown-namespaces.md) | Enforce using only Solid-specific namespaced attribute names (i.e. `'on:'` in `<div on:click={...} />`). |
136-
|| 🔧 | [solid/prefer-classlist](docs/prefer-classlist.md) | Enforce using the classlist prop over importing a classnames helper. The classlist prop accepts an object `{ [class: string]: boolean }` just like classnames. |
137-
|| 🔧 | [solid/prefer-for](docs/prefer-for.md) | Enforce using Solid's `<For />` component for mapping an array to JSX elements. |
138-
|| 🔧 | [solid/prefer-show](docs/prefer-show.md) | Enforce using Solid's `<Show />` component for conditionally showing content. Solid's compiler covers this case, so it's a stylistic rule only. |
139-
|| | [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. |
140-
|| 🔧 | [solid/self-closing-comp](docs/self-closing-comp.md) | Disallow extra closing tags for components without children. |
141-
|| 🔧 | [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. |
142-
122+
|| 🔧 | Rule | Description |
123+
| :---: | :---: | :--- | :--- |
124+
|| 🔧 | [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. |
125+
|| 🔧 | [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. |
126+
|| 🔧 | [solid/imports](docs/imports.md) | Enforce consistent imports from "solid-js", "solid-js/web", and "solid-js/store". |
127+
|| | [solid/jsx-no-duplicate-props](docs/jsx-no-duplicate-props.md) | Disallow passing the same prop twice in JSX. |
128+
|| | [solid/jsx-no-script-url](docs/jsx-no-script-url.md) | Disallow javascript: URLs. |
129+
|| 🔧 | [solid/jsx-no-undef](docs/jsx-no-undef.md) | Disallow references to undefined variables in JSX. Handles custom directives. |
130+
|| | [solid/jsx-uses-vars](docs/jsx-uses-vars.md) | Prevent variables used in JSX from being marked as unused. |
131+
|| 🔧 | [solid/no-destructure](docs/no-destructure.md) | Disallow destructuring props. In Solid, props must be used with property accesses (`props.foo`) to preserve reactivity. This rule only tracks destructuring in the parameter list. |
132+
|| 🔧 | [solid/no-innerhtml](docs/no-innerhtml.md) | Disallow usage of the innerHTML attribute, which can often lead to security vulnerabilities. |
133+
|| 🔧 | [solid/no-react-specific-props](docs/no-react-specific-props.md) | Disallow usage of React-specific `className`/`htmlFor` props, which were deprecated in v1.4.0. |
134+
|| | [solid/no-unknown-namespaces](docs/no-unknown-namespaces.md) | Enforce using only Solid-specific namespaced attribute names (i.e. `'on:'` in `<div on:click={...} />`). |
135+
|| 🔧 | [solid/prefer-classlist](docs/prefer-classlist.md) | Enforce using the classlist prop over importing a classnames helper. The classlist prop accepts an object `{ [class: string]: boolean }` just like classnames. |
136+
|| 🔧 | [solid/prefer-for](docs/prefer-for.md) | Enforce using Solid's `<For />` component for mapping an array to JSX elements. |
137+
|| 🔧 | [solid/prefer-show](docs/prefer-show.md) | Enforce using Solid's `<Show />` component for conditionally showing content. Solid's compiler covers this case, so it's a stylistic rule only. |
138+
|| | [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. |
139+
|| 🔧 | [solid/self-closing-comp](docs/self-closing-comp.md) | Disallow extra closing tags for components without children. |
140+
|| 🔧 | [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. |
143141
<!-- AUTO-GENERATED-CONTENT:END -->
144142

145143
## Versioning
@@ -149,10 +147,8 @@ stable across patch (`0.0.x`) versions, but may change across minor (`0.x`) vers
149147
If you want to pin a minor version, use a tilde in your `package.json`.
150148

151149
<!-- AUTO-GENERATED-CONTENT:START (TILDE) -->
152-
153150
```diff
154151
- "eslint-plugin-solid": "^0.7.4"
155152
+ "eslint-plugin-solid": "~0.7.4"
156153
```
157-
158154
<!-- AUTO-GENERATED-CONTENT:END -->

docs/imports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This rule is **a warning** by default.
1616

1717
### Invalid Examples
1818

19-
These snippets cause lint errors, and some can be auto-fixed.
19+
These snippets cause lint errors, and all of them can be auto-fixed.
2020

2121
```js
2222
import { createEffect } from "solid-js/web";

docs/no-destructure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This rule is **an error** by default.
1616

1717
### Invalid Examples
1818

19-
These snippets cause lint errors, and some can be auto-fixed.
19+
These snippets cause lint errors, and all of them can be auto-fixed.
2020

2121
```js
2222
let Component = ({}) => <div />;

docs/no-react-specific-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This rule is **a warning** by default.
1616

1717
### Invalid Examples
1818

19-
These snippets cause lint errors, and some can be auto-fixed.
19+
These snippets cause lint errors, and all of them can be auto-fixed.
2020

2121
```js
2222
let el = <div className="greeting">Hello world!</div>;

docs/prefer-classlist.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Options shown here are the defaults. Manually configuring an array will *replace
2828

2929
### Invalid Examples
3030

31-
These snippets cause lint errors, and some can be auto-fixed.
31+
These snippets cause lint errors, and all of them can be auto-fixed.
3232

3333
```js
3434
let el = <div class={cn({ red: true })}>Hello, world!</div>;

docs/prefer-show.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This rule is **off** by default.
1616

1717
### Invalid Examples
1818

19-
These snippets cause lint errors, and some can be auto-fixed.
19+
These snippets cause lint errors, and all of them can be auto-fixed.
2020

2121
```js
2222
function Component(props) {

docs/self-closing-comp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Options shown here are the defaults.
3030

3131
### Invalid Examples
3232

33-
These snippets cause lint errors, and some can be auto-fixed.
33+
These snippets cause lint errors, and all of them can be auto-fixed.
3434

3535
```js
3636
let el = <div></div>;

scripts/docs.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from "path";
33
import fs from "fs-extra";
44
import markdownMagic from "markdown-magic";
55
import prettier from "prettier";
6+
import type { TSESLint } from "@typescript-eslint/utils";
67
const plugin = require("../src/index");
78

89
const { rules, configs } = plugin;
@@ -59,11 +60,14 @@ const buildRulesTable = (rows: Array<string>) => {
5960
const buildHeader = (filename: string): string => {
6061
const ruleName = filename.replace(/\.md$/, "");
6162
if (!rules[ruleName]) return " ";
62-
const description = rules[ruleName].meta.docs.description;
63+
const meta: TSESLint.RuleMetaData<never> = rules[ruleName].meta;
6364
return [
6465
`# solid/${ruleName}`,
65-
description,
66-
`This rule is **${getLevelForRule(`solid/${ruleName}`, formatLevel)}** by default.\n`,
66+
meta.docs?.description,
67+
`This rule is ${meta.deprecated ? "**deprecated** and " : ""}**${getLevelForRule(
68+
`solid/${ruleName}`,
69+
formatLevel
70+
)}** by default.\n`,
6771
`[View source](../src/rules/${ruleName}.ts) · [View tests](../test/rules/${ruleName}.test.ts)\n`,
6872
].join("\n");
6973
};
@@ -94,9 +98,6 @@ const buildOptions = (filename: string): string => {
9498
return ` // ${properties[prop].description}\n ${prop}: ${JSON.stringify(_default)}, ${
9599
type !== "boolean" ? "// " + type : ""
96100
}`;
97-
// return `${prop} | \`${type}\` | ${properties[prop].description ?? ""}${
98-
// _default != null ? ` *Default \`${JSON.stringify(_default)}\`*.` : ""
99-
// }`;
100101
}),
101102
" }]",
102103
"}",
@@ -129,11 +130,14 @@ const buildCases = (content: string, filename: string) => {
129130
const valid = cases.valid?.map((c: any) => (typeof c === "string" ? { code: c } : c)) ?? [];
130131
const invalid = cases.invalid ?? [];
131132

133+
const allFixed = invalid.every((c: any) => c.output);
134+
const someFixed = !allFixed && invalid.some((c: any) => c.output);
135+
132136
const markdown = [
133137
"## Tests\n",
134138
"### Invalid Examples\n",
135-
`These snippets cause lint errors${
136-
invalid.some((c: any) => c.output) ? ", and some can be auto-fixed" : ""
139+
`These snippets cause lint errors${allFixed ? ", and all of them can be auto-fixed" : ""}${
140+
someFixed ? ", and some can be auto-fixed" : ""
137141
}.\n`,
138142
"```js",
139143
invalid.map((c: any) => [

test/fixture.test.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,35 @@ const getTestFiles = (dir: string): Array<string> => {
1212
};
1313

1414
describe("fixture", function () {
15-
it("loads the plugin without crashing", async () => {
16-
jest.setTimeout(100 * 1000);
17-
const exampleFile = path.join("test", "fixture", "invalid", "jsx-undef.jsx");
18-
const { exitCode } = await execa(eslintBinPath, ["--print-config", exampleFile], {
19-
shell: true,
20-
});
21-
expect(exitCode).toBe(0);
22-
});
23-
24-
it("produces reasonable lint errors", async () => {
25-
jest.setTimeout(100 * 1000);
26-
try {
15+
it(
16+
"loads the plugin without crashing",
17+
async () => {
2718
const exampleFile = path.join("test", "fixture", "invalid", "jsx-undef.jsx");
28-
await execa(eslintBinPath, [exampleFile], {
19+
const { exitCode } = await execa(eslintBinPath, ["--print-config", exampleFile], {
2920
shell: true,
3021
});
31-
} catch (error: any) {
32-
expect(error.exitCode).not.toBe(0);
33-
expect(error.stderr).toBe("");
34-
expect(error.stdout).toMatch(/'Component' is not defined/);
35-
expect(error.stdout).toMatch(/solid\/jsx-no-undef/);
36-
}
37-
});
22+
expect(exitCode).toBe(0);
23+
},
24+
100 * 1000
25+
);
26+
27+
it(
28+
"produces reasonable lint errors",
29+
async () => {
30+
try {
31+
const exampleFile = path.join("test", "fixture", "invalid", "jsx-undef.jsx");
32+
await execa(eslintBinPath, [exampleFile], {
33+
shell: true,
34+
});
35+
} catch (error: any) {
36+
expect(error.exitCode).not.toBe(0);
37+
expect(error.stderr).toBe("");
38+
expect(error.stdout).toMatch(/'Component' is not defined/);
39+
expect(error.stdout).toMatch(/solid\/jsx-no-undef/);
40+
}
41+
},
42+
100 * 1000
43+
);
3844

3945
describe("valid examples", () => {
4046
test.each(getTestFiles("valid").map((file) => [path.relative("test/fixture", file), file]))(

0 commit comments

Comments
 (0)