安裝以下版本的 ESLint + Prettier + lint-staged + husky + commitlint
"devDependencies": {
// ...
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@typescript-eslint/parser": "^8.14.0",
"eslint": "^8.57.0",
"eslint-config-expo": "^7.1.2",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
},
ESLint
.eslintrc.cjs
// https://docs.expo.dev/guides/using-eslint/
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
requireConfigFile: false,
babelOptions: {
parserOpts: {
plugins: ['jsx'],
},
},
},
extends: [
'expo',
'prettier',
'eslint:recommended',
'plugin:react/recommended',
],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
'react/react-in-jsx-scope': 'off',
'react-native/no-inline-styles': 'off',
'react/no-unstable-nested-components': 'off',
'react-hooks/rules-of-hooks': 'warn', // Checks rules of Hooks
'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies
},
}
.eslintignore
node_modules/
/.expo
babel.config.js
.prettierrc.cjs
.eslintrc.cjs
Prettier
.prettierrc.cjs
// https://prettier.io/docs/en/index.html
// js=> cjs
/** @type {import("prettier").Options} */
const config = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
singleQuote: true,
quoteProps: 'consistent',
semi: false,
trailingComma: 'all',
bracketSpacing: true,
arrowParens: 'always',
rangeStart: 0,
rangeEnd: Number.POSITIVE_INFINITY,
endOfLine: 'lf',
};
module.exports = config;
.prettierignore
node_modules/
.prettierrc.cjs
.eslintrc.cjs
expo-env.d.ts
husky
npx husky init
commit-msg
npx --no -- commitlint --edit ${1}
pre-commit
npx lint-staged
pre-push
npx lint
lint-staged
package.json
"scripts": {
"start": "expo start",
"reset-project": "node ./scripts/reset-project.js",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"test": "jest --watchAll",
"lint": "eslint --ext .js,.ts,.tsx .",
"format": "prettier --write \"**/*.{js,ts,tsx,json,md}\""
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix",
"prettier --write"
]
},
commitlint
echo "module.exports = { extends: ['@commitlint/config-conventional'] }" > commitlint.config.cjs