Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for RuboCop v1.38.0 and above #5

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/pkg/
/spec/reports/
/tmp/
Gemfile.lock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unacceptable.
Bundler recommends in its official documentation that Gemfile.lock be managed by Git, and in fact the rubocop-rails gem and rubocop-rspec gem have various problems by not managing Gemfile.lock with Git. If you want to make sure that it works with the latest version of RuboCop without any problems, I think it would be better to set up a separate workflow to check it.


# rspec failure tracking
.rspec_status
72 changes: 0 additions & 72 deletions Gemfile.lock

This file was deleted.

20 changes: 18 additions & 2 deletions lib/templatecop/ruby_offense_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,35 @@ def call

private

# @return [RuboCop::Cop::Registry]
def registry
@registry ||= begin
all_cops = if ::RuboCop::Cop::Registry.respond_to?(:all)
::RuboCop::Cop::Registry.all
else
::RuboCop::Cop::Cop.all
end

::RuboCop::Cop::Registry.new(all_cops)
end
end

# @return [RuboCop::ProcessedSource]
def rubocop_processed_source
@rubocop_processed_source ||= ::RuboCop::ProcessedSource.new(
@source,
@rubocop_config.target_ruby_version,
@file_path
)
).tap do |processed_source|
processed_source.config = @rubocop_config if processed_source.respond_to?(:config)
processed_source.registry = registry if processed_source.respond_to?(:registry)
end
end

# @return [RuboCop::Cop::Team]
def rubocop_team
::RuboCop::Cop::Team.new(
::RuboCop::Cop::Registry.new(::RuboCop::Cop::Cop.all),
registry,
@rubocop_config,
auto_correct: @auto_correct,
display_cop_names: true,
Expand Down
18 changes: 16 additions & 2 deletions spec/templatecop/ruby_offense_collector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
context 'with rubocop:todo comment' do
let(:source) do
<<~RUBY
"a" \# rubocop:todo Style/StringLiterals
"a" # rubocop:todo Style/StringLiterals
RUBY
end

Expand All @@ -42,13 +42,27 @@
context 'with rubocop:disable comment' do
let(:source) do
<<~RUBY
"a" \# rubocop:disable Style/StringLiterals
"a" # rubocop:disable Style/StringLiterals
RUBY
end

it 'excludes disabled offenses' do
expect(subject).to be_empty
end
end

context 'with rubocop:disable comment with missing cop enable directive' do
let(:source) do
<<~RUBY
# rubocop:disable Style/StringLiterals
"a"
RUBY
end

it 'excludes disabled offenses' do
expect(subject.size).to eq 1
expect(subject.first.cop_name).to eq 'Lint/MissingCopEnableDirective'
end
end
end
end
2 changes: 1 addition & 1 deletion spec/templatecop/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
end

let(:rubocop_config) do
::RuboCop::ConfigLoader.default_configuration
RuboCop::ConfigLoader.default_configuration
end

let(:ruby_extractor) do
Expand Down