Skip to content

Commit 2d2c8c6

Browse files
authored
Merge pull request #903 from Fryguy/update_rubocop
Upgrade manageiq-style and rubocop
2 parents fd862b5 + 6cc92fd commit 2d2c8c6

4 files changed

Lines changed: 61 additions & 45 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ gem 'awesome_spawn', '~> 1.6'
3838
gem 'default_value_for', '~> 4.0'
3939
gem 'haml_lint', '~> 0.51', :require => false
4040
gem 'irb'
41-
gem 'manageiq-style', '~> 1.5', '>=1.5.6', :require => false
41+
gem 'manageiq-style', '~> 1.6', :require => false
4242
gem 'more_core_extensions', '~> 4.4', :require => 'more_core_extensions/all'
4343
gem 'rugged', :require => false
4444

Gemfile.lock

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ GEM
7676
public_suffix (>= 2.0.2, < 8.0)
7777
ast (2.4.3)
7878
awesome_spawn (1.6.0)
79-
base64 (0.1.2)
79+
base64 (0.3.0)
8080
benchmark (0.5.0)
8181
bigdecimal (4.0.1)
8282
builder (3.3.0)
@@ -149,6 +149,7 @@ GEM
149149
thor (>= 0.14, < 2.0)
150150
json (2.19.2)
151151
language_server-protocol (3.17.0.5)
152+
lint_roller (1.1.0)
152153
listen (3.10.0)
153154
logger
154155
rb-fsevent (~> 0.10, >= 0.10.3)
@@ -162,13 +163,11 @@ GEM
162163
net-imap
163164
net-pop
164165
net-smtp
165-
manageiq-style (1.5.10)
166+
manageiq-style (1.6.0)
166167
more_core_extensions
167168
optimist
168169
rack (>= 2.2.22, < 4)
169-
rexml (>= 3.4.4)
170-
rubocop (= 1.56.3)
171-
rubocop-ast (~> 1.40.0)
170+
rubocop (~> 1.85)
172171
rubocop-performance
173172
rubocop-rails
174173
marcel (1.0.4)
@@ -294,28 +293,30 @@ GEM
294293
rspec-mocks (>= 3.13.0, < 5.0.0)
295294
rspec-support (>= 3.13.0, < 5.0.0)
296295
rspec-support (3.13.7)
297-
rubocop (1.56.3)
298-
base64 (~> 0.1.1)
296+
rubocop (1.86.0)
299297
json (~> 2.3)
300-
language_server-protocol (>= 3.17.0)
298+
language_server-protocol (~> 3.17.0.2)
299+
lint_roller (~> 1.1.0)
301300
parallel (~> 1.10)
302-
parser (>= 3.2.2.3)
301+
parser (>= 3.3.0.2)
303302
rainbow (>= 2.2.2, < 4.0)
304-
regexp_parser (>= 1.8, < 3.0)
305-
rexml (>= 3.2.5, < 4.0)
306-
rubocop-ast (>= 1.28.1, < 2.0)
303+
regexp_parser (>= 2.9.3, < 3.0)
304+
rubocop-ast (>= 1.49.0, < 2.0)
307305
ruby-progressbar (~> 1.7)
308-
unicode-display_width (>= 2.4.0, < 3.0)
309-
rubocop-ast (1.40.0)
310-
parser (>= 3.3.1.0)
311-
rubocop-performance (1.23.1)
312-
rubocop (>= 1.48.1, < 2.0)
313-
rubocop-ast (>= 1.31.1, < 2.0)
314-
rubocop-rails (2.29.1)
306+
unicode-display_width (>= 2.4.0, < 4.0)
307+
rubocop-ast (1.49.1)
308+
parser (>= 3.3.7.2)
309+
prism (~> 1.7)
310+
rubocop-performance (1.26.1)
311+
lint_roller (~> 1.1)
312+
rubocop (>= 1.75.0, < 2.0)
313+
rubocop-ast (>= 1.47.1, < 2.0)
314+
rubocop-rails (2.34.3)
315315
activesupport (>= 4.2.0)
316+
lint_roller (~> 1.1)
316317
rack (>= 1.1)
317-
rubocop (>= 1.52.0, < 2.0)
318-
rubocop-ast (>= 1.31.1, < 2.0)
318+
rubocop (>= 1.75.0, < 2.0)
319+
rubocop-ast (>= 1.44.0, < 2.0)
319320
ruby-progressbar (1.13.0)
320321
rufus-scheduler (3.9.2)
321322
fugit (~> 1.1, >= 1.11.1)
@@ -372,7 +373,9 @@ GEM
372373
turbolinks-source (5.2.0)
373374
tzinfo (2.0.6)
374375
concurrent-ruby (~> 1.0)
375-
unicode-display_width (2.6.0)
376+
unicode-display_width (3.2.0)
377+
unicode-emoji (~> 4.1)
378+
unicode-emoji (4.2.0)
376379
uri (1.1.1)
377380
useragent (0.16.11)
378381
webmock (3.26.2)
@@ -404,7 +407,7 @@ DEPENDENCIES
404407
irb
405408
jquery-rails
406409
listen
407-
manageiq-style (~> 1.5, >= 1.5.6)
410+
manageiq-style (~> 1.6)
408411
minigit (~> 0.0.4)
409412
more_core_extensions (~> 4.4)
410413
net-ssh (~> 7.3.0)

app/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'rubocop'
22
require 'rubocop-rails'
3+
require 'rubocop-performance'
34
require 'haml_lint'
45

56
class CommitMonitorHandlers::CommitRange::RubocopChecker::MessageBuilder
@@ -29,25 +30,23 @@ def comments
2930
"refactor" => :low
3031
).freeze
3132

32-
COP_URIS = RuboCop::Cop::Base.descendants.each_with_object({}) do |cop, h|
33-
plugin, version = nil
33+
COP_URIS = begin
34+
# Load configuration to get plugin DocumentationBaseURL settings
35+
config = RuboCop::ConfigLoader.configuration_from_file('.rubocop.yml')
3436

35-
case cop.department
36-
when :Rails
37-
plugin = "rubocop-rails"
38-
version = RuboCop::Rails::Version.document_version
39-
else
40-
plugin = "rubocop"
41-
version = RuboCop::Version.document_version
42-
end
37+
RuboCop::Cop::Registry.global.cops.each_with_object({}) do |cop, h|
38+
url_string = RuboCop::Cop::Documentation.url_for(cop, config)
39+
next unless url_string # Skip cops without documentation URLs
4340

44-
url = URI(RuboCop::Cop::Documentation.url_for(cop))
45-
url_path_parts = url.path.split("/")
46-
url_path_parts[1] = plugin
47-
url_path_parts.insert(2, version) unless url_path_parts[2] == version
41+
# Insert "latest" version into URL path to avoid redirect that loses fragment
42+
# e.g., /rubocop/cops_layout.html -> /rubocop/latest/cops_layout.html
43+
url = URI(url_string)
44+
url_path_parts = url.path.split("/")
45+
url_path_parts.insert(2, "latest") unless url_path_parts[2] == "latest"
46+
url.path = url_path_parts.join("/")
4847

49-
url.path = url_path_parts.join("/")
50-
h[cop.cop_name] = "[#{cop.cop_name}](#{url})"
48+
h[cop.cop_name] = "[#{cop.cop_name}](#{url})"
49+
end
5150
end.freeze
5251

5352
def tag

spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/message_builder_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
5 files checked, 5 offenses detected
2323
2424
**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb**
25-
- [ ] :exclamation: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L3), Col 5 - [Layout/HashAlignment](https://docs.rubocop.org/rubocop/#{rubocop_version_short}/cops_layout.html#layouthashalignment) - Align the keys and values of a hash literal if they span more than one line.
26-
- [ ] :exclamation: - [Line 4](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L4), Col 5 - [Layout/HashAlignment](https://docs.rubocop.org/rubocop/#{rubocop_version_short}/cops_layout.html#layouthashalignment) - Align the keys and values of a hash literal if they span more than one line.
25+
- [ ] :exclamation: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L3), Col 5 - [Layout/HashAlignment](https://docs.rubocop.org/rubocop/latest/cops_layout.html#layouthashalignment) - Align the keys and values of a hash literal if they span more than one line.
26+
- [ ] :exclamation: - [Line 4](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L4), Col 5 - [Layout/HashAlignment](https://docs.rubocop.org/rubocop/latest/cops_layout.html#layouthashalignment) - Align the keys and values of a hash literal if they span more than one line.
2727
2828
**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/rails.rb**
29-
- [ ] :exclamation: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/rails.rb#L3), Col 5 - [Rails/DynamicFindBy](https://docs.rubocop.org/rubocop-rails/#{rubocop_rails_version_short}/cops_rails.html#railsdynamicfindby) - Use `find_by` instead of dynamic `find_by_name`.
29+
- [ ] :exclamation: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/with_results_with_offenses/rails.rb#L3), Col 5 - [Rails/DynamicFindBy](https://docs.rubocop.org/rubocop-rails/latest/cops_rails.html#railsdynamicfindby) - Use `find_by` instead of dynamic `find_by_name`.
3030
3131
**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb**
32-
- [ ] :bomb: :boom: :fire: :fire_engine: - [Line 6](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb#L6), Col 1 - [Lint/Syntax](https://docs.rubocop.org/rubocop/#{rubocop_version_short}/cops_lint.html#lintsyntax) - unexpected token kEND
32+
- [ ] :bomb: :boom: :fire: :fire_engine: - [Line 6](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb#L6), Col 1 - [Lint/Syntax](https://docs.rubocop.org/rubocop/latest/cops_lint.html#lintsyntax) - unexpected token kEND
3333
(Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
3434
3535
**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb**
36-
- [ ] :warning: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb#L3), Col 5 - [Lint/UselessAssignment](https://docs.rubocop.org/rubocop/#{rubocop_version_short}/cops_lint.html#lintuselessassignment) - Useless assignment to variable - `unused_variable`.
36+
- [ ] :warning: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb#L3), Col 5 - [Lint/UselessAssignment](https://docs.rubocop.org/rubocop/latest/cops_lint.html#lintuselessassignment) - Useless assignment to variable - `unused_variable`.
3737
EOMSG
3838
end
3939

@@ -68,6 +68,20 @@
6868
end
6969
end
7070

71+
describe "::COP_URIS" do
72+
it "generates documentation URLs for builtin cops" do
73+
expect(described_class::COP_URIS['Style/StringLiterals']).to match(/\[Style\/StringLiterals\]\(https:\/\/docs\.rubocop\.org\/rubocop\/latest\/cops_style\.html#stylestringliterals\)/)
74+
end
75+
76+
it "generates documentation URLs for Rails cops" do
77+
expect(described_class::COP_URIS['Rails/DynamicFindBy']).to match(/\[Rails\/DynamicFindBy\]\(https:\/\/docs\.rubocop\.org\/rubocop-rails\/latest\/cops_rails\.html#railsdynamicfindby\)/)
78+
end
79+
80+
it "generates documentation URLs for Performance cops" do
81+
expect(described_class::COP_URIS['Performance/StringInclude']).to match(/\[Performance\/StringInclude\]\(https:\/\/docs\.rubocop\.org\/rubocop-performance\/latest\/cops_performance\.html#performancestringinclude\)/)
82+
end
83+
end
84+
7185
context "with stubbed yamllint" do
7286
before do
7387
described_class.instance_variable_set(:@yamllint_version, nil) # Clear caching

0 commit comments

Comments
 (0)