Skip to content

Commit 38863a6

Browse files
author
Nick Campbell
committed
Fix documentation rake tasks to support Rubocop 0.75
Rubocop 0.75 changed the initializer for RuboCop::Cop::MessageAnnotator in a breaking way, however rubocop-rspec does not pin to a strict version. This commit selects the right interface depending on the loaded version of Rubocop.
1 parent 0719dcf commit 38863a6

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
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

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)