Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added prettier, eslint-config-prettier, and plugin:react/recommended to extends #14

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
env: {browser: true, es2020: true},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:react/recommended",
"prettier",
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
},
}
settings: {
react: {
version: "detect",
},
},
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add the following two rules. The first one is needed since we're using React v17+ and therefore not importing React anymore, and we need the second one too as we are not really using prop-types very consistently (we will eventually refactor to TS so we're not bothering with that anymore):

rules: {
  "react/react-in-jsx-scope": "off",
  "react/prop-types": "off"
}

Add as well:

settings: {
  react: {
    version: "detect",
  },
},

to avoid getting a warning when running eslint

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# ESLint
.eslintcache
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"unlink-local": "yarn unlink && cd node_modules/react && yarn unlink && cd ../react-dom && yarn unlink",
"test:unit": "vitest",
"coverage": "vitest run --coverage",
"build:watch": "vite build --watch --config vite.config.local.ts"
"build:watch": "vite build --watch --config vite.config.local.ts",
"prepare": "husky install"
},
"dependencies": {
"@ant-design/pro-layout": "^7.16.4",
Expand Down Expand Up @@ -68,12 +69,17 @@
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^8.45.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"happy-dom": "^12.2.1",
"husky": ">=6",
"less": "^4.1.3",
"lint-staged": ">=10",
"lodash-es": "^4.17.21",
"prettier": "3.1.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -86,5 +92,9 @@
"peerDependencies": {
"react": ">=18.2.0",
"react-dom": ">=18.2.0"
},
"lint-staged": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be something like this:

"lint-staged": {
    "*.{ts,tsx,js,jsx}": "eslint --cache --fix",
    "*.{ts,tsx,js,jsx,css,less,md,html}": "prettier --write"
  }

since we want eslint to check js,jsx files too and prettier to format ts,tsx,jsx,less,html files as well. Also .eslintcache file should be added to .gitignore.

"*.{ts,tsx,js,jsx}": "eslint --cache --fix",
"*.{ts,tsx,js,jsx,css,less,md,html}": "prettier --write"
}
}
}
Loading