From 1079381b04f98379aba13461bc537df2b6d87328 Mon Sep 17 00:00:00 2001 From: Thierry Deo Date: Tue, 28 Jun 2022 00:00:54 +0200 Subject: [PATCH] Let Rubocop handle config loading --- lib/erb_lint/linters/rubocop.rb | 25 ------------------------- spec/erb_lint/linters/rubocop_spec.rb | 5 ++++- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/lib/erb_lint/linters/rubocop.rb b/lib/erb_lint/linters/rubocop.rb index 446e6677..62bcbe7f 100644 --- a/lib/erb_lint/linters/rubocop.rb +++ b/lib/erb_lint/linters/rubocop.rb @@ -158,36 +158,11 @@ def build_team end def config_from_hash(hash) - inherit_from = hash&.delete("inherit_from") - resolve_inheritance(hash, inherit_from) - tempfile_from(".erblint-rubocop", hash.to_yaml) do |tempfile| ::RuboCop::ConfigLoader.load_file(tempfile.path) end end - def resolve_inheritance(hash, inherit_from) - base_configs(inherit_from) - .reverse_each do |base_config| - base_config.each do |k, v| - hash[k] = hash.key?(k) ? ::RuboCop::ConfigLoader.merge(v, hash[k]) : v if v.is_a?(Hash) - end - end - end - - def base_configs(inherit_from) - regex = URI::DEFAULT_PARSER.make_regexp(["http", "https"]) - configs = Array(inherit_from).compact.map do |base_name| - if base_name =~ /\A#{regex}\z/ - ::RuboCop::ConfigLoader.load_file(::RuboCop::RemoteConfig.new(base_name, Dir.pwd)) - else - config_from_hash(@file_loader.yaml(base_name)) - end - end - - configs.compact - end - def add_offense(rubocop_offense, offense_range, correction, offset, bound_range) context = if rubocop_offense.corrected? { rubocop_correction: correction, offset: offset, bound_range: bound_range } diff --git a/spec/erb_lint/linters/rubocop_spec.rb b/spec/erb_lint/linters/rubocop_spec.rb index 6e81909d..15274638 100644 --- a/spec/erb_lint/linters/rubocop_spec.rb +++ b/spec/erb_lint/linters/rubocop_spec.rb @@ -24,7 +24,10 @@ let(:inherit_from_filename) { "custom_rubocop.yml" } subject { offenses } before do - allow(file_loader).to(receive(:yaml).with(inherit_from_filename).and_return(nested_config)) + allow(::RuboCop::ConfigLoader).to(receive(:load_file).and_call_original) + allow(::RuboCop::ConfigLoader).to( + receive(:load_file).with(a_string_ending_with(inherit_from_filename)).and_return(nested_config), + ) end before { linter.run(processed_source) }