sh 用于eslint的pre-commit钩子,linting * only * staged更改。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 用于eslint的pre-commit钩子,linting * only * staged更改。相关的知识,希望对你有一定的参考价值。

#!/bin/bash

for file in $(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|jsx)$')
do
  git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
  if [ $? -ne 0 ]; then
    echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
    exit 1 # exit with failure status
  fi
done

以上是关于sh 用于eslint的pre-commit钩子,linting * only * staged更改。的主要内容,如果未能解决你的问题,请参考以下文章

项目实现eslint+prettier+pre-commit自动化

pre-commit钩子,代码质量检查

Git pre-commit钩子修复尾部空白

Git钩子:'.git/hooks/pre-commit':不允许操作

Svn 钩子 限制上传文件的大小及类型

git绕过错误强制commit