Context:我没有太多使用预提交挂钩的经验。我在 vercell 样板列表页面中找到了这个项目样板,但它有点过时了,我必须更新依赖项并进行一些调整。然后,当我尝试提交时,lint-staged 预提交失败。目前我收到此错误消息:
✖ Failed to read config from file "C:/Users/NoteBoo/Desktop/BLOG/Testes/next_plus_notion/lint-staged.config.js".
✔ Preparing lint-staged...
⚠ Running tasks for staged files...
❯ package.json — 4 files
❯ *.gitignore — 1 file
✖ prettier --write [FAILED]
↓ Skipped because of errors from tasks.
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...
✖ prettier --write:
[error] No parser could be inferred for file "C:\Users\NoteBoo\Desktop\BLOG\Testes\next_plus_notion\.husky\.gitignore".
lint-staged.config.js 文件(放置在项目根目录中):
const escape = require('shell-quote').quote
const isWin = process.platform === 'win32'
module.exports = {
'**/*.{js,jsx,ts,tsx,json,md,mdx,css,html,yml,yaml,scss,sass}': filenames => {
const escapedFileNames = filenames
.map(filename => `"${isWin ? filename : escape([filename])}"`)
.join(' ')
return [
`prettier --ignore-path='.gitignore' --write ${escapedFileNames}`,
`git add ${escapedFileNames}`,
]
},
}
package.json 文件:
{
"name": "notion-blog",
"version": "0.1.0",
"scripts": {
"dev": "next dev",
"start": "next start",
"build": "next build && node .next/server/build-rss.js",
"format": "prettier --write \"**/*.{js,jsx,json,ts,tsx,md,mdx,css,html,yml,yaml,scss,sass}\" --ignore-path .gitignore",
"lint-staged": "lint-staged",
"prepare": "husky install"
},
"lint-staged": {
"*.gitignore": "prettier --write"
},
"pre-commit": "lint-staged",
"dependencies": {
"@zeit/react-jsx-parser": "^2.0.0",
"async-sema": "^3.1.1",
"github-slugger": "^2.0.0",
"katex": "^0.16.10",
"next": "^14.2.4",
"prismjs": "^1.29.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"uuid": "^10.0.0"
},
"devDependencies": {
"@types/katex": "^0.16.7",
"@types/node": "^20.14.8",
"@types/react": "^18.3.3",
"lint-staged": "^15.2.7",
"mrm": "2",
"pre-commit": "^1.2.2",
"prettier": "^3.3.2",
"typescript": "^5.5.2"
}
}
原项目链接: https://vercel.com/templates/next.js/notion-blog
如何正确设置 lint-staged 验证,以便它可以与指定的 lint-staged.config.js 文件一起使用?
运行
lint-staged --debug
以获得详细输出。
我遇到了同样的问题,并意识到我有一个拼写错误(点而不是逗号)。