跳到主要内容

lint-staged

npm install --save-dev lint-staged
# package.json scripts 添加命令
npm pkg set scripts.lint-staged="lint-staged"
echo "npx --no-install lint-staged" >> .husky/pre-commit
.lintstagedrc.js
const path = require('path');

const buildEslintCommand = (filenames) =>
`next lint --fix --file ${filenames.map((f) => path.relative(process.cwd(), f)).join(' --file ')}`;

module.exports = {
'package.json': ['prettier --write'],
'*.{js,jsx,ts,tsx}': [buildEslintCommand],
};