如何使用 husky 和 ​​lint-staged 运行“stylelint --fix”而不阻止提交

Ale*_*ola 5 pre-commit-hook githooks stylelint husky 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}\n
Run Code Online (Sandbox Code Playgroud)\n

PhpStorm 阻止了我的提交并告诉我:

\n

Commit 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 index. [STARTED] Preparing... [SUCCESS] Preparing... [STARTED] Running tasks... [STARTED] Running tasks for resources/sass/*.scss [STARTED] stylelint --fix [FAILED] stylelint --fix [FAILED] [FAILED] stylelint --fix [FAILED] [SUCCESS] Running tasks... [STARTED] Applying modifications... [SKIPPED] Skipped because of errors from tasks. [STARTED] Reverting to original state because of errors... [SUCCESS] Reverting to original state because of errors... [STARTED] Cleaning up... [SUCCESS] Cleaning up... \xe2\x9c\x96 stylelint --fix: resources/sass/_custom.scss 614:1 \xe2\x9c\x96 Unexpected duplicate selector "body", first used at line 116 no-duplicate-selectors 974:11 \xe2\x9c\x96 Unexpected unknown type selector "readonly" selector-type-no-unknown 988:1 \xe2\x9c\x96 Unexpected duplicate selector "body", first used at line 116 no-duplicate-selectors 1313:1 \xe2\x9c\x96 Unexpected duplicate selector ".btn.clear", first used at line 418 no-duplicate-selectors husky > pre-commit hook failed (add --no-verify to bypass)

\n

我在文档中读到,使用命令“--no-verify”会跳过“stylelint --fix”,但我想运行“stylelint --fix”来修复 stylelint 可以修复的错误并跳过阻止犯罪。

\n

换句话说,我想修复可以自动修复的错误并提交,即使有来自 stylelint 的一些警告。

\n

可以这样做吗?

\n