最近我开始使用lint-staged我的前端构建工具链。当我检查有关它的文档时,我总是发现它的工作原理如下:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css}": [
"prettier --write",
"eslint --fix src/",
"tslint --fix --project .",
"git add"
]
},
Run Code Online (Sandbox Code Playgroud)
您可以在链接中找到更多类似的用法:https : //github.com/okonet/lint-staged
我的困惑点是最后一个命令git add,它的目的是什么?
我的理解是lint-staged仅 git add在git commit. 所以不明白为什么我们需要再添加一个git add。
这是我所做的:
git status 显示我的所有更改。git add -Agit commit -m "Foo". 预提交的 git 钩子用husky和触发lint-staged。git commit -m "Foo"一次,立即取消了。git status是干净的,git log并且git reflog不显示新的提交。为什么我的更改被还原?我如何恢复它们?
使用 Husky/lint-staged 挂钩时是否可以排除/忽略文件?
查看文档 atm 但没有任何运气找到任何关于此的内容。
希望有类似的东西
/*ignore*/
Run Code Online (Sandbox Code Playgroud)
我可以添加的标签。
使 lint-staged 忽略导致格式问题的某些文件。
对此的任何想法都非常感谢:)
我使用 husky 和 lint-staged 在具有此配置的 sass 文件上运行“stylelint --fix”
\n"husky": {\n "hooks": {\n "pre-commit": "lint-staged",\n "post-commit": "git update-index --again"\n }\n},\n"lint-staged": {\n "resources/sass/*.scss": [\n "stylelint --fix",\n "git add"\n ]\n}\nRun Code Online (Sandbox Code Playgroud)\nPhpStorm 阻止了我的提交并告诉我:
\nCommit failed with error, 0 file committed, 4 files failed to commit: test lintstaged husky > pre-commit (node v12.18.4) \xe2\x9a\xa0 Some of your tasks use `git add` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit …
我正在通过 Husky (v4.3.8) 运行 lint-staged (v11.0.0) 作为预提交挂钩的一部分。我的 lint-staged 执行 eslint (v7.27.0) 和 Prettier (v2.3.0)。但是,在 Prettier 运行后,“美化”文件不会添加到提交中。
作为 lint 暂存过程的一部分,Prettier 修改的文件如何自动添加到提交中?
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"{src,test}/**/*.ts": {
"eslint ./src --ext .ts",
"prettier ./src --write"
}
}
Run Code Online (Sandbox Code Playgroud) 我有这个设置:
// package.json
...
"scripts": {
...
"lint": "eslint --fix {src,test}/**/*.{js,ts,jsx,tsx} --no-error-on-unmatched-pattern",
"style": "prettier --write {src,test}/**/* ./*.{json,*.json} !package-lock.json -u --no-error-on-unmatched-pattern",
...
"lint-staged": {
"lint-staged": {
"{src,test}/**/*.{js,ts,jsx,tsx}": [
"npm run lint",
"npm run style"
],
"!**/*.{js,ts,jsx,tsx}": "npm run style"
},
}
...
Run Code Online (Sandbox Code Playgroud)
问题是,无论 glob 匹配什么文件,prettier 都会运行,prettier 还会在所有文件上双重运行并重写所有文件两次。
即使只更改了一个文件,运行npm run pre-commit也会花费大量时间。
package.json脚本:
"pre-commit": "lint-staged",
和 lint 阶段命令:
"lint-staged": {
"src/**/*.{ts,js,json}": [
"eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
],
"src/**/*.{js,ts,json}": [
"prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
]
},
Run Code Online (Sandbox Code Playgroud)
感觉eslint在整个项目中运行,如何才能使其只在更改的文件中运行?
我正在关注从其github README打包的 lint-staged 自定义配置文件 (lint-staged.config.js) 的第一个示例(复制/粘贴) ,但没有成功。我error Command failed with exit code 1.总是得到。
我尝试了三件事,对于每种情况,我都将其lint-staged.config.js放在根目录中。
error Command failed with exit code 1."lint-staged": {
"packages/**/*.{ts,tsx}": [
"yarn lint-staged --config ./lint-staged.config.js"
]
},
Run Code Online (Sandbox Code Playgroud)
error Command failed with exit code 1.npx lint-staged --config ../lint-staged.config.js
Run Code Online (Sandbox Code Playgroud)
error Command failed with exit code 1.yarn lint-staged --config lint-staged.config.js
Run Code Online (Sandbox Code Playgroud)
我只是在寻找运行自定义配置文件。
问题是执行失败,错误消息与命令相关,但命令本身正确为lint-staged [options](yarn/npx lint-staged -h),然后提供一个自定义配置文件,但它lint-staged [--config [path]]失败了(我什至提供路径的各种引号)。
我有一个涡轮 monorepo,带有packages/...和apps/app-a, apps/app-b。我已经设置了哈士奇pre-commit钩子,它将运行pnpm dlx lint-staged
我想lint-staged从最接近暂存文件的位置运行 lint 脚本package.json。例如:
foo.js自apps/app-a- 它将运行lint中描述的脚本apps/app-a/package.jsonbar.js从apps/app-b将运行lint从apps/app-b/package.jsonETC。
那可能吗?
我尝试lintsatgedrc.json在apps/app-a和apps/app-b文件夹中进行设置
{
"*.{ts,tsx}": ["pnpm run lint", "pnpm run check-types"]
}
Run Code Online (Sandbox Code Playgroud)
但它总是尝试从 monorepo 的 root运行lint和脚本。chack-typespackage.json
我正面临一个奇怪的lint-staged插件问题。早些时候它工作正常。
所以问题是当我运行npm run test它时会生成覆盖率报告。
"test": "cross-env CI=true react-scripts test --coverage",
但是当我使用husky预提交运行相同的命令时,lint-staged它不起作用。当我检查控制台时,我发现它正在针对已修改的文件运行。
> portal@0.1.0 test /Users/carlos/Desktop/portal
> cross-env CI=true react-scripts test --coverage "/Users/carlos/Desktop/portal/src/container/Auth/Login.page.js"
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/carlos/Desktop/portal
44 files checked.
testMatch: /Users/carlos/Desktop/portal/src/**/__tests__/**/*.{js,jsx,ts,tsx}, /Users/carlos/Desktop/portal/src/**/*.{spec,test}.{js,jsx,ts,tsx} - 6 matches
testPathIgnorePatterns: /node_modules/ - 44 matches
testRegex: - 0 matches
Pattern: /Users/carlos/Desktop/portal/src/container/Auth/Login.page.js - 0 matches
npm ERR! code ELIFECYCLE
npm ERR! errno 1
Run Code Online (Sandbox Code Playgroud)
有明显的区别
当我跑 …