Skip to content

Commit 1d5126a

Browse files
authored
Flat config support (#223)
1 parent 10f105f commit 1d5126a

15 files changed

+1280
-1068
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This plugin depends on TypeScript to check whether the component is a Chakra com
1111

1212
TypeScript 4.4 or higher is supported. We don't test 4.3 or below but it probably works.
1313

14-
typescript-eslint v6 or higher is supported. **v5 or below is NOT supported**.
14+
typescript-eslint v8 or higher is supported. **v7 or below is NOT supported**.
1515

1616
## Installation
1717

@@ -27,23 +27,30 @@ Next, install `eslint-plugin-chakra-ui`, `@typescript-eslint/parser`.
2727
npm install eslint-plugin-chakra-ui @typescript-eslint/parser --save-dev
2828
```
2929

30-
Then set the `parser` property and add `chakra-ui` to the `plugins` property of your `.eslintrc.js` configuration file. You also need to set `project` and `tsconfigRootDir` in `parserOptions` to [enable TypeScript information](https://typescript-eslint.io/linting/typed-linting).
30+
Then set the `parser` property and add `chakra-ui` to the `plugins` property of your `eslint.congig.{js,mjs,cjs}` configuration file. You also need to set `project` and `tsconfigRootDir` in `parserOptions` to [enable TypeScript information](https://typescript-eslint.io/getting-started/typed-linting/).
3131

3232
```js
33-
module.exports = {
34-
parser: "@typescript-eslint/parser",
35-
plugins: ["chakra-ui"],
36-
parserOptions: {
37-
project: true,
38-
tsconfigRootDir: __dirname,
33+
import parser from "@typescript-eslint/parser";
34+
import chakraUiPlugin from "eslint-plugin-chakra-ui";
35+
36+
export default {
37+
plugins: {
38+
"chakra-ui": chakraUiPlugin,
39+
},
40+
languageOptions: {
41+
parserOptions: {
42+
parser,
43+
project: ["./tsconfig.json"],
44+
tsconfigRootDir: __dirname, // or import.meta.dirname
45+
},
3946
},
4047
};
4148
```
4249

4350
Now you can add chakra-ui rules:
4451

4552
```js
46-
module.exports = {
53+
export default {
4754
// ...
4855
rules: {
4956
"chakra-ui/props-order": "error",
@@ -53,6 +60,17 @@ module.exports = {
5360
};
5461
```
5562

63+
You can also load rules in bulk by accessing recommended:
64+
65+
```js
66+
export default {
67+
// ...
68+
rules: {
69+
...chakraUiPlugin.configs.recommended,
70+
},
71+
};
72+
```
73+
5674
## Supported Rules
5775

5876
Every rule is fixable with `eslint --fix`.

eslint.config.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import js from "@eslint/js";
2+
import tseslint from "typescript-eslint";
3+
import parser from "@typescript-eslint/parser";
4+
import plugins from "@typescript-eslint/eslint-plugin";
5+
import unusedImports from "eslint-plugin-unused-imports";
6+
import globals from "globals";
7+
8+
export default tseslint.config(
9+
{ ignores: ["dist"] },
10+
{
11+
languageOptions: {
12+
parserOptions: {
13+
parser,
14+
ecmaVersion: 12,
15+
sourceType: "module",
16+
project: ["./tsconfig.json"],
17+
tsconfigRootDir: import.meta.dirname,
18+
globals: globals.node,
19+
},
20+
},
21+
},
22+
{
23+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
24+
files: ["**/*.ts"],
25+
plugins: {
26+
"unused-imports": unusedImports,
27+
},
28+
rules: {
29+
"@typescript-eslint/no-unused-vars": "off",
30+
"unused-imports/no-unused-imports": "error",
31+
"unused-imports/no-unused-vars": [
32+
"warn",
33+
{ vars: "all", varsIgnorePattern: "^_", args: "after-used", argsIgnorePattern: "^_" },
34+
],
35+
},
36+
},
37+
{
38+
files: ["__tests__/**/*.js", "__tests__/**/*.{ts,tsx}"],
39+
languageOptions: {
40+
parserOptions: {
41+
globals: globals.mocha,
42+
},
43+
},
44+
},
45+
);

package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"main": "dist/index.js",
1818
"scripts": {
1919
"lint": "run-p lint:*",
20-
"lint:eslint": "eslint --ext .ts,.tsx ./src",
20+
"lint:eslint": "eslint ./src",
2121
"lint:tsc": "tsc --noEmit",
2222
"lint:prettier": "prettier --check ./src",
2323
"fix:prettier": "prettier --write ./src",
@@ -27,22 +27,24 @@
2727
"prepublishOnly": "pnpm run build"
2828
},
2929
"dependencies": {
30-
"@typescript-eslint/utils": "^6.21.0"
30+
"@typescript-eslint/utils": "^8.19.1"
3131
},
3232
"devDependencies": {
3333
"@swc/cli": "^0.1.62",
3434
"@swc/core": "^1.4.1",
3535
"@types/node": "^18.19.67",
36-
"@typescript-eslint/eslint-plugin": "^6.21.0",
37-
"@typescript-eslint/parser": "^6.21.0",
38-
"@typescript-eslint/rule-tester": "^6.21.0",
39-
"@typescript-eslint/types": "^6.21.0",
40-
"eslint": "^8.56.0",
41-
"eslint-plugin-eslint-plugin": "^5.3.0",
42-
"eslint-plugin-unused-imports": "^3.0.0",
36+
"@typescript-eslint/eslint-plugin": "^8.19.1",
37+
"@typescript-eslint/parser": "^8.19.1",
38+
"@typescript-eslint/rule-tester": "^8.19.1",
39+
"@typescript-eslint/types": "^8.19.1",
40+
"eslint": "^9.18.0",
41+
"eslint-plugin-eslint-plugin": "^6.4.0",
42+
"eslint-plugin-unused-imports": "^4.1.4",
43+
"globals": "15.14.0",
4344
"npm-run-all": "^4.1.5",
4445
"prettier": "^3.2.5",
4546
"typescript": "^5.3.3",
47+
"typescript-eslint": "8.19.1",
4648
"vite": "^4.5.2",
4749
"vitest": "^0.34.6",
4850
"watchlist": "^0.3.1"

0 commit comments

Comments
 (0)