Skip to content

Commit abdb94a

Browse files
authored
Merge pull request #829 from nickcampbell18/update-rubocop
Fix documentation rake tasks to support Rubocop 0.75
2 parents 0719dcf + 4982bfc commit abdb94a

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
* Fix documentation rake task to support Rubocop 0.75. ([@nickcampbell18][])
6+
57
## 1.36.0 (2019-09-27)
68

79
* Fix `RSpec/DescribedClass`'s error when `described_class` is used as part of a constant. ([@pirj][])
@@ -452,3 +454,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
452454
[@foton]: https://github.com/foton
453455
[@nc-holodakg]: https://github.com/nc-holodakg
454456
[@onumis]: https://github.com/onumis
457+
[@nickcampbell18]: https://github.com/nickcampbell18

lib/rubocop/cop/rspec/implicit_expect.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def offending_expect(node)
8282
end
8383
end
8484

85-
def is_expected_range(source_map) # rubocop:disable PredicateName
85+
def is_expected_range(source_map) # rubocop:disable Naming/PredicateName
8686
Parser::Source::Range.new(
8787
source_map.expression.source_buffer,
8888
source_map.expression.begin_pos,

spec/project/changelog_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
it 'has a valid URL' do
4040
issues.each do |issue|
4141
number = issue[:number].gsub(/\D/, '')
42-
pattern = %r{^https://github\.com/.+/.+/(?:issues|pull)/#{number}$} # rubocop:disable LineLength
42+
pattern = %r{^https://github\.com/.+/.+/(?:issues|pull)/#{number}$} # rubocop:disable Metrics/LineLength
4343
expect(issue[:url]).to match(pattern)
4444
end
4545
end

spec/rubocop/cop/rspec/cop_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
let(:fake_cop) do
2323
stub_const('RuboCop::RSpec', Module.new)
24-
# rubocop:disable ClassAndModuleChildren, RSpec/LeakyConstantDeclaration
24+
# rubocop:disable Style/ClassAndModuleChildren
25+
# rubocop:disable RSpec/LeakyConstantDeclaration
2526
class RuboCop::RSpec::FakeCop < described_class
2627
def on_send(node)
2728
add_offense(node, message: 'I flag everything')
2829
end
2930
end
30-
# rubocop:enable ClassAndModuleChildren, RSpec/LeakyConstantDeclaration
31+
# rubocop:enable Style/ClassAndModuleChildren
32+
# rubocop:enable RSpec/LeakyConstantDeclaration
3133
RuboCop::RSpec::FakeCop
3234
end
3335

tasks/cops_documentation.rake

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,32 @@ task generate_cops_documentation: :yard_for_generate_documentation do
138138
end
139139
# rubocop:enable Metrics/MethodLength
140140

141+
def cop_urls(config, cop)
142+
rubocop_version = Gem::Version.new(RuboCop::Version::STRING)
143+
144+
# Since Rubocop v0.75.0 and above, MessageAnnotator#new changed from:
145+
# def initialize(config, cop_config, options)
146+
# to:
147+
# def initialize(config, cop_name, cop_config, options)
148+
#
149+
# Since this library has a loose Rubocop dependency, we select the
150+
# right arguments based on the installed version.
151+
#
152+
# TODO: When Rubocop < 0.75 is no longer supported, remove the second half
153+
# of this condition.
154+
155+
if rubocop_version >= Gem::Version.new('0.75.0')
156+
RuboCop::Cop::MessageAnnotator.new(
157+
config, cop.name, config.for_cop(cop), {}
158+
).urls
159+
else
160+
RuboCop::Cop::MessageAnnotator.new(config, config.for_cop(cop), {}).urls
161+
end
162+
end
163+
141164
def references(config, cop)
142-
cop_config = config.for_cop(cop)
143-
urls = RuboCop::Cop::MessageAnnotator.new(config, cop_config, {}).urls
165+
urls = cop_urls(config, cop)
166+
144167
return '' if urls.empty?
145168

146169
content = h3('References')

0 commit comments

Comments
 (0)