Skip to content

Commit 48caca6

Browse files
authored
add flat config export (#16)
1 parent 15c53ec commit 48caca6

File tree

13 files changed

+1253
-970
lines changed

13 files changed

+1253
-970
lines changed

CHANGELOG.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## v3.3.0
4+
5+
Adds ESLint's [new configuration system](https://eslint.org/blog/2022/08/new-config-system-part-1/), `flat config`. If you're using the new flat config:
6+
7+
`eslint.config.js`:
8+
9+
```js
10+
import eslint from "@eslint/js";
11+
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
12+
import preferFC from "eslint-plugin-react-prefer-function-component/config";
13+
14+
export default [
15+
{ files: ["**/*.{js,jsx}"] },
16+
eslint.configs.recommended,
17+
reactRecommended,
18+
preferFC.configs.recommended,
19+
];
20+
```
21+
322
## v3.2.0
423

524
- The plugin's recommended configuration has been fixed, so `plugins` can be dropped from your `.eslintrc` when using the recommended settings:
@@ -9,9 +28,9 @@
928
- plugins: ["react-prefer-function-component"],
1029
extends: ["plugin:react-prefer-function-component/recommended"],
1130
};
31+
```
1232

1333
Thanks @alecmev!
14-
```
1534

1635
## v3.1.0
1736

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,29 @@ I'm discussing this in an [open issue](https://github.com/yannickcr/eslint-plugi
5656

5757
## Installation & Usage 📦
5858

59+
1. Install:
60+
5961
```
6062
$ npm install eslint eslint-plugin-react-prefer-function-component --save-dev
6163
```
6264

65+
2. Update your `eslint.config.js`:
66+
67+
```js
68+
import eslint from "@eslint/js";
69+
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
70+
import preferFC from "eslint-plugin-react-prefer-function-component/config";
71+
72+
export default [
73+
{ files: ["**/*.{js,jsx}"] },
74+
eslint.configs.recommended,
75+
reactRecommended,
76+
preferFC.configs.recommended,
77+
];
78+
```
79+
80+
### ESLint Legacy Configuration
81+
6382
`.eslintrc` configuration:
6483

6584
```js

examples/custom-config/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"license": "ISC",
1010
"main": "index.js",
1111
"devDependencies": {
12-
"eslint": "^8.46.0",
13-
"eslint-plugin-react": "^7.33.1",
12+
"eslint": "^8.48.0",
13+
"eslint-plugin-react": "^7.33.2",
1414
"eslint-plugin-react-prefer-function-component": "workspace:*"
1515
}
1616
}

examples/flat-config/eslint.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import eslint from "@eslint/js";
2+
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
3+
import preferFC from "eslint-plugin-react-prefer-function-component/config";
4+
5+
export default [
6+
{ files: ["**/*.{js,jsx}"] },
7+
eslint.configs.recommended,
8+
reactRecommended,
9+
preferFC.configs.recommended,
10+
];

examples/flat-config/index.jsx

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { Component } from "react";
2+
3+
export class Foo extends Component {
4+
render() {
5+
return <div>{this.props.foo}</div>;
6+
}
7+
}
8+
9+
export const Bar = function (props) {
10+
return <div>{props.foo}</div>;
11+
};
12+
13+
export function Baz(props) {
14+
return <div>{props.foo}</div>;
15+
}
16+
17+
export class ErrorBoundary extends Component {
18+
componentDidCatch(error, errorInfo) {
19+
logErrorToMyService(error, errorInfo);
20+
}
21+
22+
render() {
23+
return <div>{this.props.foo}</div>;
24+
}
25+
}

examples/flat-config/package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "1.0.0",
3+
"type": "module",
4+
"description": "",
5+
"name": "flat-config",
6+
"scripts": {
7+
"lint": "eslint ."
8+
},
9+
"author": "Tate Thurston <[email protected]>",
10+
"license": "ISC",
11+
"main": "index.js",
12+
"devDependencies": {
13+
"eslint": "^8.48.0",
14+
"eslint-plugin-react": "^7.33.2",
15+
"eslint-plugin-react-prefer-function-component": "workspace:*"
16+
}
17+
}

examples/recommended-config/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"license": "ISC",
1010
"main": "index.js",
1111
"devDependencies": {
12-
"eslint": "^8.46.0",
13-
"eslint-plugin-react": "^7.33.1",
12+
"eslint": "^8.48.0",
13+
"eslint-plugin-react": "^7.33.2",
1414
"eslint-plugin-react-prefer-function-component": "workspace:*"
1515
}
1616
}

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@
2222
"typecheck": "pnpm run --recursive typecheck"
2323
},
2424
"devDependencies": {
25-
"@babel/preset-env": "^7.22.9",
25+
"@babel/preset-env": "^7.22.10",
2626
"@babel/preset-react": "^7.22.5",
27-
"@babel/preset-typescript": "^7.22.5",
28-
"@types/eslint": "^8.44.1",
27+
"@babel/preset-typescript": "^7.22.11",
28+
"@types/eslint": "^8.44.2",
2929
"@types/estree": "^1.0.1",
30-
"@types/jest": "^29.5.3",
31-
"@types/node": "^20.4.5",
32-
"@typescript-eslint/eslint-plugin": "^6.2.1",
33-
"@typescript-eslint/parser": "^6.2.1",
30+
"@types/jest": "^29.5.4",
31+
"@types/node": "^20.5.7",
32+
"@typescript-eslint/eslint-plugin": "^6.5.0",
33+
"@typescript-eslint/parser": "^6.5.0",
3434
"codecov": "^3.8.3",
35-
"eslint": "^8.46.0",
36-
"eslint-config-prettier": "^8.9.0",
37-
"eslint-plugin-react": "^7.33.1",
35+
"eslint": "^8.48.0",
36+
"eslint-config-prettier": "^9.0.0",
37+
"eslint-plugin-react": "^7.33.2",
3838
"eslint-plugin-react-hooks": "^4.6.0",
3939
"husky": "^8.0.3",
40-
"jest": "^29.6.2",
41-
"prettier": "^3.0.0",
40+
"jest": "^29.6.4",
41+
"prettier": "^3.0.3",
4242
"prettier-package-json": "^2.8.0",
43-
"typescript": "^5.1.6"
43+
"typescript": "^5.2.2"
4444
},
4545
"packageManager": "[email protected]"
4646
}

packages/eslint-plugin-react-prefer-function-component/package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-react-prefer-function-component",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "ESLint plugin that prevents the use of JSX class components",
55
"license": "MIT",
66
"author": "Tate <[email protected]>",
@@ -20,7 +20,7 @@
2020
"package:prune": "find dist -name test.* -delete",
2121
"typecheck": "tsc --noEmit"
2222
},
23-
"types": "index.d.ts",
23+
"types": "dist/index.d.ts",
2424
"keywords": [
2525
"eslint react no class",
2626
"eslint react class",
@@ -30,6 +30,11 @@
3030
"lint jsx class"
3131
],
3232
"devDependencies": {
33-
"eslint": "^8.46.0"
33+
"eslint": "^8.48.0"
34+
},
35+
"exports": {
36+
"./package.json": "./package.json",
37+
".": "./dist/index.js",
38+
"./config": "./dist/config.mjs"
3439
}
3540
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { ESLint } from "eslint";
2+
import preferFunctionComponent from "./prefer-function-component/index.js";
3+
4+
const plugin: ESLint.Plugin = {
5+
rules: {
6+
"prefer-function-component": preferFunctionComponent.default,
7+
},
8+
};
9+
10+
const config: ESLint.Plugin = {
11+
configs: {
12+
recommended: {
13+
plugins: {
14+
"prefer-function-component": plugin,
15+
},
16+
rules: {
17+
"prefer-function-component/prefer-function-component": "error",
18+
},
19+
},
20+
},
21+
};
22+
23+
export default config;

packages/eslint-plugin-react-prefer-function-component/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ESLint } from "eslint";
2-
import PreferFunctionComponent from "./prefer-function-component";
2+
import PreferFunctionComponent from "./prefer-function-component/index.js";
33

44
const plugin: ESLint.Plugin = {
55
configs: {

0 commit comments

Comments
 (0)