Skip to content

Commit 921faaa

Browse files
authored
Merge pull request #149 from JoshuaKGoldberg/typescript-eslint-8
fix: allow typescript-eslint@8 as dependency
2 parents 29ed2cc + 64aa84b commit 921faaa

31 files changed

+4514
-3169
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup pnpm
1919
uses: pnpm/action-setup@v3
2020
with:
21-
version: 8
21+
version: 9
2222
- uses: actions/setup-node@v4
2323
with:
2424
node-version: ${{ matrix.node }}

README.md

Lines changed: 0 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -1,225 +0,0 @@
1-
<p>
2-
<img width="100%" src="https://assets.solidjs.com/banner?type=ESLint%20Plugin&background=tiles&project=%20" alt="Solid ESLint Extension">
3-
</p>
4-
5-
# Solid ESLint Plugin
6-
7-
[![npm version](https://img.shields.io/npm/v/eslint-plugin-solid?style=for-the-badge)](https://npmjs.com/package/eslint-plugin-solid)
8-
[![GitHub package version](https://img.shields.io/github/package-json/v/solidjs-community/eslint-plugin-solid?style=for-the-badge)](https://github.com/solidjs-community/eslint-plugin-solid)
9-
![ESLint peer dependency](https://img.shields.io/badge/eslint-6.x--8.x-blue?style=for-the-badge)
10-
[![CI](https://github.com/solidjs-community/eslint-plugin-solid/actions/workflows/ci.yml/badge.svg?style=for-the-badge)](https://github.com/solidjs-community/eslint-plugin-solid/actions/workflows/ci.yml)
11-
12-
This package contains [Solid](https://www.solidjs.com/)-specific linting rules for ESLint. It can
13-
ease Solid's learning curve by finding and fixing problems around Solid's reactivity system, and can
14-
migrate some React patterns to Solid code.
15-
16-
It's approaching a `1.0.0` release, and it's well tested and should be helpful in Solid projects
17-
today.
18-
19-
<!-- AUTO-GENERATED-CONTENT:START (TOC) -->
20-
- [Installation](#installation)
21-
- [Configuration](#configuration)
22-
- [TypeScript](#typescript)
23-
- [Manual Configuration](#manual-configuration)
24-
- [Flat Configuration](#flat-configuration)
25-
- [Rules](#rules)
26-
- [Troubleshooting](#troubleshooting)
27-
- [Versioning](#versioning)
28-
<!-- AUTO-GENERATED-CONTENT:END -->
29-
30-
## Installation
31-
32-
Install `eslint` and `eslint-plugin-solid` locally.
33-
34-
```sh
35-
npm install --save-dev eslint eslint-plugin-solid
36-
# or
37-
pnpm add --save-dev eslint eslint-plugin-solid
38-
yarn add --dev eslint eslint-plugin-solid
39-
40-
# optional, to create an ESLint config file
41-
npx eslint --init
42-
# or
43-
pnpm eslint --init
44-
yarn eslint --init
45-
```
46-
47-
If you're using VSCode, you'll want to install the [ESLint
48-
extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint). You're
49-
encouraged to enable auto-fixing problems on save by adding the following to your `settings.json`
50-
file.
51-
52-
```json
53-
{
54-
"editor.codeActionsOnSave": {
55-
"source.fixAll": true
56-
}
57-
}
58-
```
59-
60-
If you're using Vite, you may want to install
61-
[vite-plugin-eslint](https://github.com/gxmari007/vite-plugin-eslint).
62-
63-
You may also want to check out
64-
[eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y), which provides
65-
useful rules for writing accessible HTML.
66-
67-
## Configuration
68-
69-
Use the `"plugin:solid/recommended"` configuration to get reasonable defaults as shown [below](#rules).
70-
71-
```json
72-
{
73-
"plugins": ["solid"],
74-
"extends": ["eslint:recommended", "plugin:solid/recommended"]
75-
}
76-
```
77-
78-
### TypeScript
79-
80-
If you're using TypeScript, use the `"plugin:solid/typescript"` configuration instead.
81-
This disables some features that overlap with type checking.
82-
83-
```json
84-
{
85-
"parser": "@typescript-eslint/parser",
86-
"plugins": ["solid"],
87-
"extends": ["eslint:recommended", "plugin:solid/typescript"]
88-
}
89-
```
90-
91-
### Manual Configuration
92-
93-
If you don't want to use a preset, you can configure rules individually. Add the `"solid"` plugin,
94-
enable JSX with the parser options (or use the equivalent options for `@typescript-eslint/parser` or
95-
`@babel/eslint-parser`), and configure the rules you would like to use. Some rules have additional
96-
options you can set.
97-
98-
```json
99-
{
100-
"plugins": ["solid"],
101-
"parserOptions": {
102-
"ecmaFeatures": {
103-
"jsx": true
104-
}
105-
},
106-
"rules": {
107-
"solid/reactivity": "warn",
108-
"solid/no-destructure": "warn",
109-
"solid/jsx-no-undef": "error"
110-
}
111-
}
112-
```
113-
114-
### Flat Configuration
115-
116-
ESLint's new configuration system, [Flat
117-
Configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new#using-configurations-included-in-plugins),
118-
is available starting in ESLint [v8.23.0](https://github.com/eslint/eslint/releases/tag/v8.23.0). To
119-
use it, create an `eslint.config.js` file at the root of your project, instead of `.eslintrc.*`
120-
and/or `.eslintignore`.
121-
122-
```js
123-
import js from "@eslint/js";
124-
import solid from "eslint-plugin-solid/configs/recommended";
125-
126-
export default [
127-
js.configs.recommended, // replaces eslint:recommended
128-
solid,
129-
];
130-
```
131-
132-
For TypeScript:
133-
134-
```js
135-
import js from "@eslint/js";
136-
import solid from "eslint-plugin-solid/configs/typescript";
137-
import * as tsParser from "@typescript-eslint/parser";
138-
139-
export default [
140-
js.configs.recommended,
141-
{
142-
files: ["**/*.{ts,tsx}"],
143-
...solid,
144-
languageOptions: {
145-
parser: tsParser,
146-
parserOptions: {
147-
project: "tsconfig.json",
148-
},
149-
},
150-
},
151-
];
152-
```
153-
154-
These configurations do not configure global variables in ESLint. You can do this yourself manually
155-
or with a package like [globals](https://www.npmjs.com/package/globals) by creating a configuration
156-
with a `languageOptions.globals` object. We recommend setting up global variables for Browser APIs
157-
as well as at least ES2015.
158-
159-
Note for the ESLint VSCode Extension: Enable the "Use Flat Config" setting for your workspace to
160-
enable Flat Config support.
161-
162-
Flat configs are also available as `plugin.configs['flat/recommended']` and `plugin.configs['flat/typescript']`, after using `import plugin from 'eslint-plugin-solid'`.
163-
164-
## Rules
165-
166-
✔: Enabled in the `recommended` configuration.
167-
168-
🔧: Fixable with [`eslint --fix`](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems)/IDE auto-fix.
169-
170-
<!-- AUTO-GENERATED-CONTENT:START (RULES) -->
171-
|| 🔧 | Rule | Description |
172-
| :---: | :---: | :--- | :--- |
173-
|| 🔧 | [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. |
174-
|| 🔧 | [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. |
175-
|| 🔧 | [solid/imports](docs/imports.md) | Enforce consistent imports from "solid-js", "solid-js/web", and "solid-js/store". |
176-
|| | [solid/jsx-no-duplicate-props](docs/jsx-no-duplicate-props.md) | Disallow passing the same prop twice in JSX. |
177-
|| | [solid/jsx-no-script-url](docs/jsx-no-script-url.md) | Disallow javascript: URLs. |
178-
|| 🔧 | [solid/jsx-no-undef](docs/jsx-no-undef.md) | Disallow references to undefined variables in JSX. Handles custom directives. |
179-
|| | [solid/jsx-uses-vars](docs/jsx-uses-vars.md) | Prevent variables used in JSX from being marked as unused. |
180-
| | | [solid/no-array-handlers](docs/no-array-handlers.md) | Disallow usage of type-unsafe event handlers. |
181-
|| 🔧 | [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. |
182-
|| 🔧 | [solid/no-innerhtml](docs/no-innerhtml.md) | Disallow usage of the innerHTML attribute, which can often lead to security vulnerabilities. |
183-
| | | [solid/no-proxy-apis](docs/no-proxy-apis.md) | Disallow usage of APIs that use ES6 Proxies, only to target environments that don't support them. |
184-
|| 🔧 | [solid/no-react-deps](docs/no-react-deps.md) | Disallow usage of dependency arrays in `createEffect` and `createMemo`. |
185-
|| 🔧 | [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. |
186-
|| | [solid/no-unknown-namespaces](docs/no-unknown-namespaces.md) | Enforce using only Solid-specific namespaced attribute names (i.e. `'on:'` in `<div on:click={...} />`). |
187-
| | 🔧 | [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. |
188-
|| 🔧 | [solid/prefer-for](docs/prefer-for.md) | Enforce using Solid's `<For />` component for mapping an array to JSX elements. |
189-
| | 🔧 | [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. |
190-
|| | [solid/reactivity](docs/reactivity.md) | Enforce that reactivity (props, signals, memos, etc.) is properly used, so changes in those values will be tracked and update the view as expected. |
191-
|| 🔧 | [solid/self-closing-comp](docs/self-closing-comp.md) | Disallow extra closing tags for components without children. |
192-
|| 🔧 | [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. |
193-
<!-- AUTO-GENERATED-CONTENT:END -->
194-
195-
## Troubleshooting
196-
197-
The rules in this plugin provide sensible guidelines as well as possible, but there may be times
198-
where you know better than the rule and want to ignore a warning. To do that, [add a
199-
comment](https://eslint.org/docs/latest/user-guide/configuring/rules#disabling-rules) like the
200-
following:
201-
202-
```jsx
203-
// eslint-disable-next-line solid/reactivity
204-
const [editedValue, setEditedValue] = createSignal(props.value);
205-
```
206-
207-
_Please note_: there may also be times where a rule correctly warns about a subtle problem,
208-
even if it looks like a false positive at first. With `solid/reactivity`, please look at the
209-
[reactivity docs](./docs/reactivity.md#troubleshooting) before deciding to disable the rule.
210-
211-
When in doubt, feel free to [file an
212-
issue](https://github.com/solidjs-community/eslint-plugin-solid/issues/new/choose).
213-
214-
## Versioning
215-
216-
Pre-1.0.0, the rules and the `recommended` and `typescript` configuations will be
217-
stable across patch (`0.0.x`) versions, but may change across minor (`0.x`) versions.
218-
If you want to pin a minor version, use a tilde in your `package.json`.
219-
220-
<!-- AUTO-GENERATED-CONTENT:START (TILDE) -->
221-
```diff
222-
- "eslint-plugin-solid": "^0.14.1"
223-
+ "eslint-plugin-solid": "~0.14.1"
224-
```
225-
<!-- AUTO-GENERATED-CONTENT:END -->

docs/components-return-once.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
<!-- AUTO-GENERATED-CONTENT:START (HEADER) -->
1+
<!-- doc-gen HEADER -->
22
# solid/components-return-once
33
Disallow early returns in components. Solid components only run once, and so conditionals should be inside JSX.
44
This rule is **a warning** by default.
55

66
[View source](../src/rules/components-return-once.ts) · [View tests](../test/rules/components-return-once.test.ts)
7-
8-
<!-- AUTO-GENERATED-CONTENT:END -->
7+
<!-- end-doc-gen -->
98

109
See [this issue](https://github.com/solidjs-community/eslint-plugin-solid/issues/24) for rationale.
1110

12-
<!-- AUTO-GENERATED-CONTENT:START (OPTIONS) -->
13-
14-
<!-- AUTO-GENERATED-CONTENT:END -->
11+
<!-- doc-gen OPTIONS -->
12+
13+
<!-- end-doc-gen -->
1514

16-
<!-- AUTO-GENERATED-CONTENT:START (CASES) -->
15+
<!-- doc-gen CASES -->
1716
## Tests
1817

1918
### Invalid Examples
@@ -27,36 +26,32 @@ function Component() {
2726
}
2827
return <span />;
2928
}
30-
29+
3130
const Component = () => {
3231
if (condition) {
3332
return <div />;
3433
}
3534
return <span />;
3635
};
37-
36+
3837
function Component() {
3938
return Math.random() > 0.5 ? <div>Big!</div> : <div>Small!</div>;
4039
}
4140
// after eslint --fix:
4241
function Component() {
4342
return <>{Math.random() > 0.5 ? <div>Big!</div> : <div>Small!</div>}</>;
4443
}
45-
44+
4645
function Component() {
4746
return Math.random() > 0.5 ? <div>Big!</div> : "Small!";
4847
}
4948
// after eslint --fix:
5049
function Component() {
5150
return <>{Math.random() > 0.5 ? <div>Big!</div> : "Small!"}</>;
5251
}
53-
52+
5453
function Component() {
55-
return Math.random() > 0.5 ? (
56-
<div>Big! No, really big!</div>
57-
) : (
58-
<div>Small!</div>
59-
);
54+
return Math.random() > 0.5 ? <div>Big! No, really big!</div> : <div>Small!</div>;
6055
}
6156
// after eslint --fix:
6257
function Component() {
@@ -66,7 +61,7 @@ function Component() {
6661
</Show>
6762
);
6863
}
69-
64+
7065
function Component(props) {
7166
return props.cond1 ? (
7267
<div>Condition 1</div>
@@ -89,7 +84,7 @@ function Component(props) {
8984
</Switch>
9085
);
9186
}
92-
87+
9388
function Component(props) {
9489
return !!props.cond && <div>Conditional</div>;
9590
}
@@ -101,18 +96,17 @@ function Component(props) {
10196
</Show>
10297
);
10398
}
104-
99+
105100
function Component(props) {
106101
return props.primary || <div>{props.secondaryText}</div>;
107102
}
108-
103+
109104
HOC(() => {
110105
if (condition) {
111106
return <div />;
112107
}
113108
return <div />;
114109
});
115-
116110
```
117111

118112
### Valid Examples
@@ -172,6 +166,5 @@ function Component() {
172166
};
173167
return <></>;
174168
}
175-
176169
```
177-
<!-- AUTO-GENERATED-CONTENT:END -->
170+
<!-- end-doc-gen -->

0 commit comments

Comments
 (0)