@elnop/oxlint-config-react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/ReactConfig.d.ts +104 -0
- package/dist/ReactConfig.js +34 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/plugin.js +2 -0
- package/package.json +39 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 elnop
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @elnop/oxlint-config-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Oxlint config for React with TypeScript. It extends [@elnop/oxlint-config-typescript](https://www.npmjs.com/package/@elnop/oxlint-config-typescript) and adds:
|
|
4
|
+
|
|
5
|
+
- the `react` plugin and the `browser` env
|
|
6
|
+
- `react/rules-of-hooks`, `react/exhaustive-deps` and `react/only-export-components`
|
|
7
|
+
- a component types its props with a named type called after it: `function Card({ title }: CardProps)`. Untyped props, inline object types and other type names are reported.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev oxlint @elnop/oxlint-config-react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { reactConfig } from '@elnop/oxlint-config-react';
|
|
15
|
+
import { defineConfig } from 'oxlint';
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
extends: [reactConfig],
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For a Vite app, [@elnop/oxlint-config-react-vite](https://www.npmjs.com/package/@elnop/oxlint-config-react-vite) adds the Vite specific settings on top.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export declare const reactConfig: {
|
|
2
|
+
extends: {
|
|
3
|
+
plugins: ("import" | "oxc" | "typescript" | "unicorn")[];
|
|
4
|
+
jsPlugins: {
|
|
5
|
+
name: string;
|
|
6
|
+
specifier: string;
|
|
7
|
+
}[];
|
|
8
|
+
categories: {
|
|
9
|
+
correctness: "error";
|
|
10
|
+
suspicious: "error";
|
|
11
|
+
};
|
|
12
|
+
env: {
|
|
13
|
+
es2024: true;
|
|
14
|
+
};
|
|
15
|
+
rules: {
|
|
16
|
+
'import/no-cycle': "error";
|
|
17
|
+
'import/no-self-import': "error";
|
|
18
|
+
'import/no-duplicates': "error";
|
|
19
|
+
'typescript/no-floating-promises': "error";
|
|
20
|
+
'typescript/no-misused-promises': "error";
|
|
21
|
+
'typescript/await-thenable': "error";
|
|
22
|
+
'typescript/no-unnecessary-type-assertion': "error";
|
|
23
|
+
'typescript/consistent-type-imports': "error";
|
|
24
|
+
'typescript/no-explicit-any': "error";
|
|
25
|
+
'no-shadow': "off";
|
|
26
|
+
'unicorn/consistent-function-scoping': "off";
|
|
27
|
+
'typescript/consistent-return': "off";
|
|
28
|
+
'oxc/no-barrel-file': ["error", {
|
|
29
|
+
threshold: number;
|
|
30
|
+
}];
|
|
31
|
+
'unicorn/filename-case': ["error", {
|
|
32
|
+
cases: {
|
|
33
|
+
camelCase: boolean;
|
|
34
|
+
pascalCase: boolean;
|
|
35
|
+
};
|
|
36
|
+
}];
|
|
37
|
+
'no-comments/disallowComments': ["error", {
|
|
38
|
+
allow: ("/ <reference " | "/usr/bin/env " | "@ts-expect-error" | "@ts-ignore" | "@ts-nocheck" | "eslint-" | "oxlint-")[];
|
|
39
|
+
}];
|
|
40
|
+
'check-file/no-index': ["error", {
|
|
41
|
+
errorMessage: "Barrel files ({{ target }}) are not allowed: import each module by its own path";
|
|
42
|
+
}];
|
|
43
|
+
'check-file/filename-blocklist': ["error", {
|
|
44
|
+
'**/types.ts': "*Types.ts";
|
|
45
|
+
}];
|
|
46
|
+
'file-named-after-export/file-named-after-export': "error";
|
|
47
|
+
};
|
|
48
|
+
overrides: ({
|
|
49
|
+
files: string[];
|
|
50
|
+
rules: {
|
|
51
|
+
'export-placement/no-restricted-syntax': ["error", ...{
|
|
52
|
+
selector: string;
|
|
53
|
+
message: string;
|
|
54
|
+
}[]];
|
|
55
|
+
'typescript/no-floating-promises'?: undefined;
|
|
56
|
+
'file-named-after-export/file-named-after-export'?: undefined;
|
|
57
|
+
};
|
|
58
|
+
} | {
|
|
59
|
+
files: string[];
|
|
60
|
+
rules: {
|
|
61
|
+
'typescript/no-floating-promises': "off";
|
|
62
|
+
'export-placement/no-restricted-syntax'?: undefined;
|
|
63
|
+
'file-named-after-export/file-named-after-export'?: undefined;
|
|
64
|
+
};
|
|
65
|
+
} | {
|
|
66
|
+
files: string[];
|
|
67
|
+
rules: {
|
|
68
|
+
'typescript/no-floating-promises'?: undefined;
|
|
69
|
+
'export-placement/no-restricted-syntax': "off";
|
|
70
|
+
'file-named-after-export/file-named-after-export': "off";
|
|
71
|
+
};
|
|
72
|
+
})[];
|
|
73
|
+
}[];
|
|
74
|
+
plugins: ("import" | "oxc" | "react" | "typescript" | "unicorn")[];
|
|
75
|
+
jsPlugins: {
|
|
76
|
+
name: string;
|
|
77
|
+
specifier: string;
|
|
78
|
+
}[];
|
|
79
|
+
env: {
|
|
80
|
+
browser: true;
|
|
81
|
+
es2024: true;
|
|
82
|
+
};
|
|
83
|
+
rules: {
|
|
84
|
+
'react/rules-of-hooks': "error";
|
|
85
|
+
'react/hooks': "off";
|
|
86
|
+
'react/exhaustive-deps': "error";
|
|
87
|
+
'react/only-export-components': "error";
|
|
88
|
+
'react/react-in-jsx-scope': "off";
|
|
89
|
+
};
|
|
90
|
+
overrides: ({
|
|
91
|
+
files: string[];
|
|
92
|
+
rules: {
|
|
93
|
+
'component-props/no-restricted-syntax': ["error", ...{
|
|
94
|
+
selector: string;
|
|
95
|
+
message: string;
|
|
96
|
+
}[]];
|
|
97
|
+
};
|
|
98
|
+
} | {
|
|
99
|
+
files: string[];
|
|
100
|
+
rules: {
|
|
101
|
+
'component-props/no-restricted-syntax': "off";
|
|
102
|
+
};
|
|
103
|
+
})[];
|
|
104
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { typescriptConfig } from '@elnop/oxlint-config-typescript';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { defineConfig } from 'oxlint';
|
|
4
|
+
const COMPONENT_PROPS = [
|
|
5
|
+
{
|
|
6
|
+
selector: ':matches(FunctionDeclaration[id.name=/^[A-Z]/], VariableDeclarator[id.name=/^[A-Z]/] > :matches(ArrowFunctionExpression, FunctionExpression)) > :matches(ObjectPattern, Identifier).params[typeAnnotation=null]',
|
|
7
|
+
message: 'A component types its props with a named type called after it: ComponentProps.',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
selector: ':matches(FunctionDeclaration[id.name=/^[A-Z]/], VariableDeclarator[id.name=/^[A-Z]/] > :matches(ArrowFunctionExpression, FunctionExpression)) > :matches(ObjectPattern, Identifier).params > TSTypeAnnotation > TSTypeLiteral',
|
|
11
|
+
message: 'A component types its props with a named type called after it: ComponentProps.',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
selector: ':matches(FunctionDeclaration[id.name=/^[A-Z]/], VariableDeclarator[id.name=/^[A-Z]/] > :matches(ArrowFunctionExpression, FunctionExpression)) > :matches(ObjectPattern, Identifier).params > TSTypeAnnotation > TSTypeReference > Identifier.typeName[name!=/^[A-Z]\\w*Props$/]',
|
|
15
|
+
message: 'A component types its props with a named type called after it: ComponentProps.',
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
export const reactConfig = defineConfig({
|
|
19
|
+
extends: [typescriptConfig],
|
|
20
|
+
plugins: ['typescript', 'react', 'import', 'oxc', 'unicorn'],
|
|
21
|
+
jsPlugins: [{ name: 'component-props', specifier: fileURLToPath(new URL('./plugin.js', import.meta.url)) }],
|
|
22
|
+
env: { browser: true, es2024: true },
|
|
23
|
+
rules: {
|
|
24
|
+
'react/rules-of-hooks': 'error',
|
|
25
|
+
'react/hooks': 'off',
|
|
26
|
+
'react/exhaustive-deps': 'error',
|
|
27
|
+
'react/only-export-components': 'error',
|
|
28
|
+
'react/react-in-jsx-scope': 'off',
|
|
29
|
+
},
|
|
30
|
+
overrides: [
|
|
31
|
+
{ files: ['**/*.tsx'], rules: { 'component-props/no-restricted-syntax': ['error', ...COMPONENT_PROPS] } },
|
|
32
|
+
{ files: ['**/*.test.tsx', 'e2e/**'], rules: { 'component-props/no-restricted-syntax': 'off' } },
|
|
33
|
+
],
|
|
34
|
+
});
|
package/dist/plugin.d.ts
ADDED
package/dist/plugin.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elnop/oxlint-config-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Oxlint config for React with TypeScript: hooks rules and named XProps types for components.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"oxlint",
|
|
7
|
+
"oxlint-config",
|
|
8
|
+
"react",
|
|
9
|
+
"typescript",
|
|
10
|
+
"lint"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/Elnop/eslint-plugins/tree/main/packages/configs/oxlint-config-react#readme",
|
|
13
|
+
"bugs": "https://github.com/Elnop/eslint-plugins/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/Elnop/eslint-plugins.git",
|
|
17
|
+
"directory": "packages/configs/oxlint-config-react"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "elnop",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"!dist/tsconfig.tsbuildinfo"
|
|
25
|
+
],
|
|
26
|
+
"exports": "./dist/ReactConfig.js",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "node --test '**/*.test.ts'"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@elnop/oxlint-config-typescript": "^0.1.0",
|
|
32
|
+
"oxlint-plugin-eslint": "^1.91.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"oxlint": "^1.91.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@elnop/lint-utils": "^0.1.0",
|
|
39
|
+
"oxlint": "^1.91.0"
|
|
40
|
+
}
|
|
41
|
+
}
|