Skip to content

Commit

Permalink
feat: add support for react hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Feb 26, 2024
1 parent 30b6b50 commit 7a3034f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHANGELOG.md
package-lock.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Adjust `env` according to your use case, obviously.
ESLint requires plugins to be peer dependencies (they resolve relative to the end-user project), as such you need to install an additional dependency if you're using React:

```bash
npm install --save-dev eslint-plugin-react
npm install --save-dev eslint-plugin-react eslint-plugin-react-hooks
```

Then, make sure to extend `sanity/react` in your `.eslintrc`:
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 44 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@
"name": "eslint-config-sanity",
"version": "7.0.3",
"description": "Shared eslint configs for sanity-io",
"main": "index.js",
"scripts": {
"test": "eslint ."
},
"engines": {
"node": ">=14.0.0"
},
"files": [
"import.js",
"index.js",
"react.js",
"typescript.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/sanity-io/eslint-config-sanity.git"
},
"keywords": [
"sanity",
"cms",
Expand All @@ -29,12 +12,48 @@
"eslint",
"eslintconfig"
],
"author": "Sanity.io <[email protected]>",
"license": "MIT",
"homepage": "https://www.sanity.io/",
"bugs": {
"url": "https://github.com/sanity-io/eslint-config-sanity/issues"
},
"homepage": "https://www.sanity.io/",
"repository": {
"type": "git",
"url": "git+https://github.com/sanity-io/eslint-config-sanity.git"
},
"license": "MIT",
"author": "Sanity.io <[email protected]>",
"main": "index.js",
"files": [
"import.js",
"index.js",
"react.js",
"typescript.js"
],
"scripts": {
"test": "eslint ."
},
"prettier": {
"bracketSpacing": false,
"plugins": [
"prettier-plugin-packagejson"
],
"printWidth": 100,
"semi": false,
"singleQuote": true
},
"dependencies": {
"eslint-plugin-simple-import-sort": "^12.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^3.2.5",
"prettier-plugin-packagejson": "^2.4.12"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^6.7.5 || ^7.0.0",
"@typescript-eslint/parser": "^6.7.5 || ^7.0.0",
Expand All @@ -54,24 +73,12 @@
},
"eslint-plugin-react": {
"optional": true
},
"eslint-plugin-react-hooks": {
"optional": true
}
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.33.2",
"prettier": "^3.2.5",
"prettier-plugin-packagejson": "^2.4.12"
},
"prettier": {
"semi": false,
"printWidth": 100,
"bracketSpacing": false,
"singleQuote": true
},
"dependencies": {
"eslint-plugin-simple-import-sort": "^12.0.0"
"engines": {
"node": ">=14.0.0"
}
}
11 changes: 9 additions & 2 deletions react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ module.exports = {
node: true,
browser: true,
},
extends: ['plugin:react/recommended', 'plugin:react/jsx-runtime', './index'],
extends: [
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:react/jsx-runtime',
'./index',
],
plugins: ['react'],
parserOptions: {
ecmaFeatures: {
Expand Down Expand Up @@ -72,12 +77,14 @@ module.exports = {
//@@@ deprecated in favor of the eslint-plugin-import extensions rule
// "react/require-extension": "...",
'react/require-optimization': 'off',
'react/require-default-props': 'warn',
'react/prefer-stateless-function': ['warn', {ignorePureComponents: true}],
'react/sort-comp': 'off',
'react/sort-prop-types': 'off',
'react/self-closing-comp': 'error',
'react/style-prop-object': 'error',
'react/void-dom-elements-no-children': 'error',
// Handle hooks
'react-hooks/exhaustive-deps': 'error',
'react-hooks/rules-of-hooks': 'error',
},
}
11 changes: 5 additions & 6 deletions typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
// If using both TypeScript + React:
// make sure you load `sanity/react` _before_ `sanity/typescript`
module.exports = {
extends: ['plugin:@typescript-eslint/recommended', './index'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended',
'./index',
],
env: {
node: true,
browser: true,
},
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
rules: {
// --- typescript types over prop types in typescript projects
'react/prop-types': 'off',
'react/require-default-props': 'off',
// ---

// --- causing parse errors with d.ts files
// --- see https://github.com/typescript-eslint/typescript-eslint/issues/420
'no-useless-constructor': 'off',
Expand Down

0 comments on commit 7a3034f

Please sign in to comment.