[英]How to inherit a gem's class but use configurations from github? (Rubocop gem)
在实现 Super-Linter 时,我注意到它继承自rubocop-github
gem,如下所示: https://github.com/github/super-linter/blob/main/TEMPLATES/.ruby-lint.yml
---
#######################
# Rubocop Config file #
#######################
inherit_gem:
rubocop-github:
- config/default.yml
然而, rubocop-github
gem 似乎有点过时了,最近的更新是从 6 月 24 日开始的,而default.yml
配置文件是两年多前的。
最终,我要做的是继承 rubocop gem,然后覆盖一些默认值。 这是我现在拥有的:
---
inherit_gem:
rubocop-github:
- config/default.yml
inherit_from:
- https://raw.githubusercontent.com/rubocop/rubocop/master/config/default.yml
- .rubocop-custom.yml
这个问题是rubocop-github
gem(过时的)与我的rubocop
gem(更新的)冲突,所以它不起作用。 如果我能做这样的事情会很棒:
# Common configuration.
---
inherit_gem:
rubocop:
- https://raw.githubusercontent.com/rubocop/rubocop/master/config/default.yml
inherit_from:
- .rubocop-custom.yml
但这不起作用。 我在 VS 代码中收到以下错误:
can't inherit configuration from the rubocop gem /home/ubuntu/.rvm/gems/ruby-
...
想出了解决这个问题的办法,虽然现在又出现了新问题。 gem rubocop
实际上已经在 gems 目录中附带了config/default.yml
; 但是,有一段代码实际上不允许您预加载配置文件。
这对我有用,至少在 gem 文件出现问题之前:
# Common configuration.
---
inherit_gem:
rubocop:
- config/default.yml
inherit_from:
- https://raw.githubusercontent.com/rubocop/rubocop/master/config/default.yml
- .rubocop-custom.yml
由此产生的错误:
can't inherit configuration from the rubocop gem
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/lib/rubocop/config_loader_resolver.rb:63:in `block in resolve_inheritance_from_gems'
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/lib/rubocop/config_loader_resolver.rb:61:in `each_pair'
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/lib/rubocop/config_loader_resolver.rb:61:in `resolve_inheritance_from_gems'
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/lib/rubocop/config_loader.rb:50:in `load_file'
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/lib/rubocop/config_store.rb:29:in `options_config='
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/lib/rubocop/cli.rb:90:in `act_on_options'
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/lib/rubocop/cli.rb:38:in `run'
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/exe/rubocop:12:in `block in <top (required)>'
/usr/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
/usr/lib/ruby/gems/3.0.0/gems/rubocop-1.13.0/exe/rubocop:12:in `<top (required)>'
/usr/bin/rubocop:25:in `load'
/usr/bin/rubocop:25:in `<main>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.