Skip to content

Commit

Permalink
Fix a build error
Browse files Browse the repository at this point in the history
Follow up rubocop/rubocop#10987.

```console
% bundle exec rake
(snip)

NoMethodError: undefined method `disabled' for nil:NilClass

      registry.disabled(config).each do |cop|
               ^^^^^^^^^
    /Users/koic/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/rubocop-479e588e16cd/lib/rubocop/comment_config.rb:94:in `inject_disabled_cops_directives'
    /Users/koic/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/rubocop-479e588e16cd/lib/rubocop/comment_config.rb:78:in `analyze'
    /Users/koic/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/rubocop-479e588e16cd/lib/rubocop/comment_config.rb:45:in `cop_disabled_line_ranges'
```

It supports multiple RuboCop core versions for compatibility with
#156.
  • Loading branch information
koic committed Oct 29, 2022
1 parent 11f5529 commit 0234244
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/rubocop/minitest/assert_offense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,33 @@ def parse_source!(source, file = nil)
file = file.path
end

RuboCop::ProcessedSource.new(source, ruby_version, file)
processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file)

# Follow up https://github.com/rubocop/rubocop/pull/10987.
# When support for RuboCop 1.37.1 ends, this condition can be removed.
if processed_source.respond_to?(:config) && processed_source.respond_to?(:registry)
processed_source.config = configuration
processed_source.registry = registry
end

processed_source
end

def configuration
@configuration ||= if defined?(config)
config
else
RuboCop::Config.new({}, "#{Dir.pwd}/.rubocop.yml")
end
end

def registry
@registry ||= begin
cops = configuration.keys.map { |cop| RuboCop::Cop::Registry.global.find_by_cop_name(cop) }
cops << cop_class if defined?(cop_class) && !cops.include?(cop_class)
cops.compact!
RuboCop::Cop::Registry.new(cops)
end
end

def ruby_version
Expand Down

0 comments on commit 0234244

Please sign in to comment.