Skip to content

Commit

Permalink
feat: optional react support (#326)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
suppayami and antfu committed Nov 22, 2023
1 parent 8055331 commit 86ca184
Show file tree
Hide file tree
Showing 14 changed files with 1,035 additions and 24 deletions.
25 changes: 24 additions & 1 deletion README.md
Expand Up @@ -312,7 +312,7 @@ export default await antfu(
)
```

We also provided an `overrides` options to make it easier:
We also provided a `overrides` options to make it easier:

```js
// eslint.config.js
Expand All @@ -332,6 +332,29 @@ export default antfu({
})
```

### Optional Configs

#### React

We do include configs for React. But due to the install size of React plugins we didn't include the dependencies by default.

To enable React support, need to explicitly turn it on:

```js
// eslint.config.js
import antfu from '@antfu/eslint-config'

export default antfu({
react: true,
})
```

Running `npx eslint` should prompt you to install the required dependencies, otherwise you can install them manually:

```bash
npm i -D eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-refresh
```

### Optional Rules

This config also provides some optional plugins/rules for extended usages.
Expand Down
11 changes: 11 additions & 0 deletions eslint.config.js
@@ -1,9 +1,11 @@
// @ts-check
import styleMigrate from '@stylistic/eslint-plugin-migrate'
import antfu from './dist/index.js'

export default antfu(
{
vue: true,
// react: true,
typescript: true,
ignores: [
'fixtures',
Expand All @@ -16,4 +18,13 @@ export default antfu(
'perfectionist/sort-objects': 'error',
},
},
{
files: ['src/configs/*.ts'],
plugins: {
'style-migrate': styleMigrate,
},
rules: {
'style-migrate/migrate': ['error', { namespaceTo: 'style' }],
},
},
)
23 changes: 21 additions & 2 deletions package.json
Expand Up @@ -36,10 +36,25 @@
"prepare": "simple-git-hooks"
},
"peerDependencies": {
"eslint": ">=8.40.0"
"eslint": ">=8.40.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4"
},
"peerDependenciesMeta": {
"eslint-plugin-react": {
"optional": true
},
"eslint-plugin-react-hooks": {
"optional": true
},
"eslint-plugin-react-refresh": {
"optional": true
}
},
"dependencies": {
"@antfu/eslint-define-config": "^1.23.0-2",
"@antfu/install-pkg": "^0.2.0",
"@eslint-types/jsdoc": "46.8.2-1",
"@eslint-types/typescript-eslint": "^6.11.0",
"@eslint-types/unicorn": "^49.0.0",
Expand All @@ -61,7 +76,6 @@
"eslint-plugin-vitest": "^0.3.9",
"eslint-plugin-vue": "^9.18.1",
"eslint-plugin-yml": "^1.10.0",
"execa": "^8.0.1",
"globals": "^13.23.0",
"jsonc-eslint-parser": "^2.4.0",
"local-pkg": "^0.5.0",
Expand All @@ -75,6 +89,7 @@
"devDependencies": {
"@antfu/eslint-config": "workspace:*",
"@antfu/ni": "^0.21.9",
"@stylistic/eslint-plugin-migrate": "^1.4.0",
"@types/eslint": "^8.44.7",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.9.1",
Expand All @@ -83,7 +98,11 @@
"bumpp": "^9.2.0",
"eslint": "^8.54.0",
"eslint-flat-config-viewer": "^0.1.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"esno": "^4.0.0",
"execa": "^8.0.1",
"fast-glob": "^3.3.2",
"fs-extra": "^11.1.1",
"lint-staged": "^15.1.0",
Expand Down

0 comments on commit 86ca184

Please sign in to comment.