Skip to content

Commit 350f78d

Browse files
migrate react config (#245)
* migrate react config Signed-off-by: Kangrui Johann Ye <kangrui.ye@cloudflight.io> * migrate react hooks config Signed-off-by: Kangrui Johann Ye <kangrui.ye@cloudflight.io> * migrate jsx a11y config Signed-off-by: Kangrui Johann Ye <kangrui.ye@cloudflight.io> * fix typescript version for internal types Signed-off-by: Kangrui Johann Ye <kangrui.ye@cloudflight.io> * bump version Signed-off-by: Kangrui Johann Ye <kangrui.ye@cloudflight.io> --------- Signed-off-by: Kangrui Johann Ye <kangrui.ye@cloudflight.io>
1 parent 7ece559 commit 350f78d

24 files changed

Lines changed: 706 additions & 266 deletions

File tree

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default tseslint.config(
1515
// until we are done with migrating everything to v9
1616
ignores: [
1717
'packages/eslint-plugin-angular/src/configs/format-template.ts',
18-
'packages/eslint-plugin-react/*',
1918
'packages/eslint-plugin-typescript/src/configs/index.ts',
2019
'packages/eslint-plugin-typescript/src/configs/json.ts',
2120
'packages/eslint-plugin-typescript/src/configs/package.ts',

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudflight/eslint-plugin",
3-
"version": "1.0.0-rc7",
3+
"version": "1.0.0-rc8",
44
"private": true,
55
"volta": {
66
"node": "20.12.2",
@@ -44,11 +44,11 @@
4444
"eslint-import-resolver-typescript": "3.6.3",
4545
"eslint-plugin-import-x": "4.3.1",
4646
"eslint-plugin-json-es": "1.6.0",
47-
"eslint-plugin-jsx-a11y": "6.8.0",
47+
"eslint-plugin-jsx-a11y": "6.10.0",
4848
"eslint-plugin-n": "17.10.3",
4949
"eslint-plugin-no-unsanitized": "4.1.2",
50-
"eslint-plugin-react": "7.34.1",
51-
"eslint-plugin-react-hooks": "4.6.2",
50+
"eslint-plugin-react": "7.37.1",
51+
"eslint-plugin-react-hooks": "5.0.0",
5252
"eslint-plugin-rxjs": "5.0.3",
5353
"eslint-plugin-security": "3.0.1",
5454
"eslint-plugin-vue": "9.28.0",

packages/eslint-plugin-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudflight/eslint-plugin-angular",
3-
"version": "1.0.0-rc7",
3+
"version": "1.0.0-rc8",
44
"description": "Cloudflight eslint-plugin & eslint-config for angular",
55
"volta": {
66
"extends": "../../package.json"

packages/eslint-plugin-angular/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const cloudflightAngularTypescriptConfig = tseslint.config(
1414
...angular.configs.tsRecommended,
1515
],
1616
processor: angular.processInlineTemplates,
17+
name: 'cloudflight/angular/typescript/rules',
1718
rules: {
1819
...eslintRules,
1920
...typescriptEslintRules,
@@ -29,6 +30,7 @@ export const cloudflightAngularTemplateConfig = tseslint.config(
2930
...angular.configs.templateRecommended,
3031
...angular.configs.templateAccessibility,
3132
],
33+
name: 'cloudflight/angular/template/rules',
3234
rules: {
3335
...angularTemplateEslintRules,
3436
// todo: this should be its own config

packages/eslint-plugin-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudflight/eslint-plugin-node",
3-
"version": "1.0.0-rc7",
3+
"version": "1.0.0-rc8",
44
"description": "Cloudflight eslint-plugin & eslint-config for node",
55
"volta": {
66
"extends": "../../package.json"

packages/eslint-plugin-node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const cloudflightNodeConfig = tseslint.config(
1616
nounsanitized.configs.recommended,
1717
pluginSecurity.configs.recommended,
1818
],
19+
name: 'cloudflight/node/rules',
1920
rules: {
2021
...nodeRules,
2122
...securityRules,

packages/eslint-plugin-react/README.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ You can find the directory of all rules including their reasoning [here](src/con
99
The following dependencies are required:
1010

1111
```
12-
"@cloudflight/eslint-plugin-typescript": ">=0.26.0",
1312
"eslint": ">=9.0.0 < 10.0.0"
1413
```
1514

@@ -25,19 +24,40 @@ In your `package.json` add the following:
2524
}
2625
```
2726

28-
The plugin provides 1 configuration:
29-
30-
- @cloudflight/react/recommended
31-
- Contains rules for React files
32-
33-
Now open your `.eslintrc.js` and add one of the configurations:
34-
27+
Now open your `eslint.config.mjs` and add one of the configurations:
28+
29+
```ts
30+
import { cloudflightReactConfig } from '@cloudflight/eslint-plugin-react';
31+
import { includeIgnoreFile } from '@eslint/compat';
32+
import { dirname, normalize, resolve } from 'node:path';
33+
import { fileURLToPath } from 'node:url';
34+
35+
const directory = dirname(fileURLToPath(import.meta.url));
36+
const gitignorePath = normalize(resolve(directory, '.gitignore'));
37+
38+
export default [
39+
includeIgnoreFile(gitignorePath),
40+
...cloudflightReactConfig,
41+
{
42+
languageOptions: {
43+
parserOptions: {
44+
project: ['tsconfig*(.*).json'],
45+
tsconfigRootDir: import.meta.dirname,
46+
},
47+
},
48+
settings: {
49+
'import-x/resolver': {
50+
typescript: {
51+
alwaysTryTypes: true,
52+
project: ['tsconfig*(.*).json'],
53+
},
54+
},
55+
react: {
56+
version: 'detect',
57+
},
58+
},
59+
},
60+
];
3561
```
36-
require('@rushstack/eslint-patch/modern-module-resolution');
3762

38-
module.exports = {
39-
...
40-
extends: ['plugin:@cloudflight/react/recommended'],
41-
...
42-
};
43-
```
63+
When executing your next `eslint .` it will now validate your code against the cloudflight-recommended rules.

packages/eslint-plugin-react/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudflight/eslint-plugin-react",
3-
"version": "1.0.0-rc7",
3+
"version": "1.0.0-rc8",
44
"description": "Cloudflight eslint-plugin & eslint-config for React",
55
"volta": {
66
"extends": "../../package.json"
@@ -22,20 +22,22 @@
2222
"publishConfig": {
2323
"access": "public"
2424
},
25-
"private": true,
2625
"scripts": {
27-
"build-packagex": "tsc"
26+
"build-package": "tsc"
2827
},
2928
"dependencies": {
30-
"eslint-plugin-jsx-a11y": "^6.8.0",
31-
"eslint-plugin-react": "^7.34.1",
32-
"eslint-plugin-react-hooks": "^4.6.2"
29+
"@cloudflight/eslint-plugin-typescript": "workspace:*",
30+
"@typescript-eslint/parser": "^8.8.0",
31+
"eslint-plugin-jsx-a11y": "^6.10.0",
32+
"eslint-plugin-react": "^7.37.1",
33+
"eslint-plugin-react-hooks": "^5.0.0"
3334
},
3435
"peerDependencies": {
35-
"@cloudflight/eslint-plugin-typescript": "workspace:*",
3636
"eslint": ">=9.0.0 < 10.0.0"
3737
},
3838
"devDependencies": {
39+
"@types/eslint-plugin-jsx-a11y": "workspace:*",
40+
"@types/eslint-plugin-react-hooks": "workspace:*",
3941
"typescript": "5.5.4"
4042
}
4143
}

packages/eslint-plugin-react/src/configs/index.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {TSESLint} from '@typescript-eslint/utils';
2+
3+
export const reactRules: TSESLint.Linter.RulesRecord = {
4+
'react/static-property-placement': ['error', 'static public field'],
5+
'react/jsx-fragments': ['error', 'element'],
6+
'react/sort-comp': [
7+
1,
8+
{
9+
order: [
10+
'type-annotations',
11+
'static-variables',
12+
'instance-variables',
13+
'lifecycle',
14+
'static-methods',
15+
'instance-methods',
16+
'everything-else',
17+
'render',
18+
],
19+
},
20+
],
21+
'react/no-array-index-key': ['error'],
22+
};

0 commit comments

Comments
 (0)