我遇到overcommit
中的预提交挂钩问题,该挂钩已配置为运行rubocop
和rails_best_practices
。
简而言之,下面列出的所有三个命令都通过了,但是overcommit
不允许我使用git。对于为什么/如何规避此问题的任何建议,将不胜感激。
# These passed
rubocop -a
rails_best_practices .
overcommit --run
# Git commit failed
$ overcommit --run
Running pre-commit hooks
Analyze with RailsBestPractices..................[RailsBestPractices] OK
Analyze with RuboCop........................................[RuboCop] OK
✓ All pre-commit hooks passed
$ git commit -m 'Ensure lower case with Attr API'
Running pre-commit hooks
Analyze with RailsBestPractices..................[RailsBestPractices] FAILED
Errors on modified lines:
/Users/USER_NAME/projects/APP_NAME/app/models/lower_case_string.rb:2 - remove unused methods (LowerCaseString#cast)
Analyze with RuboCop........................................[RuboCop] FAILED
Errors on modified lines:
/Users/USER_NAME/projects/APP_NAME/app/models/lower_case_string.rb:3:3: C: Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
✗ One or more pre-commit hooks failed
现在,我读到here时,overcommit --run
并没有像您实际尝试提交时那样触发钩子(整个项目vs仅提交更改)。但是,我不确定这将如何影响我的情况,尤其是因为rubocop
和rails_best_practices
都分别通过了。顺便说一下,这里提出的错误都是虚假警报。 rails_best_practices
不应首先检查未使用的方法,因为该检查已在config/rails_best_practices.yml
中关闭。
答案 0 :(得分:1)
在使用这些宝石几周后,我想我已经解决了。对于那些遇到类似问题的人,我会在这里留下一些提示。
1。在进行overcommit --run
正如comment和docs所说,--run
命令不会检查未跟踪的文件。
2。将gemfile
选项添加到.overcommit.yml
我遇到的一个问题是overcommit
无法读取我的config/rails_best_practices.yml
(最初不应该检查unused methods
,因为该检查已关闭在配置文件中。)
似乎当我尝试git commit
时,overcommit
使用的是系统中安装的gem(而不是Gemfile
中的gem),结果以某种方式无法读取我的配置文件。因此,我按照文档中的建议添加了gemfile
选项,并确保overcommit
使用Gemfile
/ bundler
版本。从那以后我再也没有得到过主题错误。正如文档所说:
如果您正在使用Bundler管理Ruby gem依赖项,则可能需要使用gemfile选项来控制钩子运行期间可用的gem版本。
我的.overcommit.yml
文件供参考:
gemfile: Gemfile
PreCommit:
RuboCop:
enabled: true
on_warn: fail
RailsBestPractices:
enabled: true
on_warn: fail
command: ['bundle', 'exec', 'rails_best_practices', '-c', 'config/rails_best_practices.yml']
作为旁注-我没有尝试过,但是显然,如果您觉得加载原始Gemfile
的速度变慢,也可以仅为overcommit
的目的创建一个单独的Gemfile
下钩执行(docs)。