-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #113] Add basic compatibility check with main gem
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
# ... | ||
module AST | ||
# Responsible for compatibility with main gem | ||
# @api private | ||
module RuboCopCompatibility | ||
INCOMPATIBLE_COPS = { | ||
'0.89.0' => 'Layout/LineLength' | ||
}.freeze | ||
def rubocop_loaded | ||
loaded = Gem::Version.new(RuboCop::Version::STRING) | ||
incompatible = INCOMPATIBLE_COPS.select do |k, _v| | ||
loaded < Gem::Version.new(k) | ||
end.values | ||
return if incompatible.empty? | ||
|
||
warn <<~WARNING | ||
*** WARNING – Incompatible versions of `rubocop` and `rubocop-ast` | ||
You may encounter issues with the following \ | ||
Cop#{'s' if incompatible.size > 1}: #{incompatible.join(', ')} | ||
Please upgrade rubocop to at least v#{INCOMPATIBLE_COPS.keys.last} | ||
WARNING | ||
end | ||
end | ||
|
||
extend RuboCopCompatibility | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::AST::RuboCopCompatibility do # rubocop:disable RSpec/FilePath | ||
subject(:callback) { RuboCop::AST.rubocop_loaded } | ||
|
||
before do | ||
stub_const '::RuboCop::Version::STRING', rubocop_version | ||
end | ||
|
||
context 'when ran from an incompatible version of Rubocop' do | ||
let(:rubocop_version) { '0.42.0' } | ||
|
||
it 'issues a warning' do | ||
expect { callback }.to output(/LineLength/).to_stderr | ||
end | ||
end | ||
|
||
context 'when ran from a compatible version of Rubocop' do | ||
let(:rubocop_version) { '0.89.0' } | ||
|
||
it 'issues a warning' do | ||
expect { callback }.not_to output.to_stderr | ||
end | ||
end | ||
end |