Skip to content

Commit

Permalink
Merge pull request #261 from pennylane-hq/main
Browse files Browse the repository at this point in the history
Let Rubocop handle config loading
  • Loading branch information
rafaelfranca authored Jun 29, 2022
2 parents e392851 + 1079381 commit f4c7558
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
25 changes: 0 additions & 25 deletions lib/erb_lint/linters/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 4 additions & 1 deletion spec/erb_lint/linters/rubocop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit f4c7558

Please sign in to comment.