[英]How to inherit a gem's class but use configurations from github? (Rubocop gem)
While implementing Super-Linter, I noticed that it's inheriting from the rubocop-github
gem, as shown here: https://github.com/github/super-linter/blob/main/TEMPLATES/.ruby-lint.yml在实现 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
However, the rubocop-github
gem seems to be a bit dated, with recent updates from June 24th and a default.yml
config file from over 2 years ago.然而, rubocop-github
gem 似乎有点过时了,最近的更新是从 6 月 24 日开始的,而default.yml
配置文件是两年多前的。
Ultimately, what I'm trying to do is inherit the rubocop gem and then overwrite some of the defaults.最终,我要做的是继承 rubocop gem,然后覆盖一些默认值。 Here's what I have right now:这是我现在拥有的:
---
inherit_gem:
rubocop-github:
- config/default.yml
inherit_from:
- https://raw.githubusercontent.com/rubocop/rubocop/master/config/default.yml
- .rubocop-custom.yml
The problem with this is that rubocop-github
gem (outdated) conflicts with my rubocop
gem (more up-to-date), so it doesn't work.这个问题是rubocop-github
gem(过时的)与我的rubocop
gem(更新的)冲突,所以它不起作用。 It would be great if I could do something like this:如果我能做这样的事情会很棒:
# Common configuration.
---
inherit_gem:
rubocop:
- https://raw.githubusercontent.com/rubocop/rubocop/master/config/default.yml
inherit_from:
- .rubocop-custom.yml
but this doesn't work.但这不起作用。 I get the following error in VS Code:我在 VS 代码中收到以下错误:
can't inherit configuration from the rubocop gem /home/ubuntu/.rvm/gems/ruby-
...
Figured out the solution to this problem, although there is now a new problem.想出了解决这个问题的办法,虽然现在又出现了新问题。 The gem rubocop
actually comes with config/default.yml
already in the gems directory; gem rubocop
实际上已经在 gems 目录中附带了config/default.yml
; however, there's a piece of code that actually doesn't allow you to pre-load the configuration file.但是,有一段代码实际上不允许您预加载配置文件。
This worked for me, at least until the issue with the gem file coming up:这对我有用,至少在 gem 文件出现问题之前:
# Common configuration.
---
inherit_gem:
rubocop:
- config/default.yml
inherit_from:
- https://raw.githubusercontent.com/rubocop/rubocop/master/config/default.yml
- .rubocop-custom.yml
Error that gets produced from this:由此产生的错误:
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.