Skip to content

Commit

Permalink
add support for RuboCop >= 1.0
Browse files Browse the repository at this point in the history
* change to rubocop dependency version to < 2.0
* fix or ignore rubocop offences
* add rubocop version 1.0.0 and the latest 1.0
  • Loading branch information
eitoball authored Feb 19, 2021
1 parent ae2faf8 commit 6477baf
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
ruby: ['2.4', '2.5', '2.6', '2.7', '3.0']
rubocop: ['0.63.1', '0.84.0', '0.85.0', '0.86.0', '0.87.0', '< 1.0']
rubocop: ['0.63.1', '0.81.0', '0.84.0', '0.85.0', '0.86.0', '0.87.0', '< 1.0', '1.0.0', '< 2.0']
include:
- ruby: '2.3'
rubocop: '0.63.1'
Expand All @@ -24,7 +24,7 @@ jobs:
- name: use specific rubocop version
run: echo "gem 'rubocop', '${{ matrix.rubocop }}'" > Gemfile.local
- name: use specific rubocop-ast version (if required)
if: matrix.rubocop == '0.84.0' || matrix.rubocop == '0.85.0' || matrix.rubocop == '0.85.1'
if: matrix.rubocop == '0.84.0' || matrix.rubocop == '0.85.0'
run: echo "gem 'rubocop-ast', '< 0.7.0'" >> Gemfile.local
- uses: ruby/setup-ruby@v1
with:
Expand Down
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ Layout/MultilineOperationIndentation:

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Metrics/BlockLength:
Exclude:
- pronto-rubocop.gemspec
- spec/**/*_spec.rb
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env rake
# frozen_string_literal: true

require 'bundler'
require 'rspec/core/rake_task'

Expand Down
4 changes: 3 additions & 1 deletion lib/pronto/rubocop.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pronto'
require 'rubocop'
require 'pronto/rubocop/patch_cop'
Expand All @@ -7,7 +9,7 @@ module Pronto
class Rubocop < Runner
def run
ruby_patches
.select { |patch| patch.additions > 0 }
.select { |patch| patch.additions.positive? }
.flat_map { |patch| PatchCop.new(patch, self).messages }
end

Expand Down
13 changes: 7 additions & 6 deletions lib/pronto/rubocop/offense_line.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Pronto
class Rubocop < Runner
class OffenseLine
Expand Down Expand Up @@ -31,7 +33,7 @@ def message_text

def suggestion_text
return unless patch_cop.runner.pronto_rubocop_config['suggestions']
return if corrections_count == 0
return if corrections_count.zero?
return if differing_lines_count != corrections_count

@suggestion_text ||= corrected_lines[offense.line - 1]
Expand Down Expand Up @@ -87,11 +89,10 @@ def corrections_count
def autocorrect_team
@autocorrect_team ||=
::RuboCop::Cop::Team.send(MOBILIZE,
::RuboCop::Cop::Registry.new([cop_class]),
patch_cop.rubocop_config,
auto_correct: true,
stdin: true,
)
::RuboCop::Cop::Registry.new([cop_class]),
patch_cop.rubocop_config,
auto_correct: true,
stdin: true)
end

def cop_class
Expand Down
2 changes: 2 additions & 0 deletions lib/pronto/rubocop/patch_cop.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Pronto
class Rubocop < Runner
class PatchCop
Expand Down
4 changes: 3 additions & 1 deletion lib/pronto/rubocop/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

module Pronto
module RubocopVersion
VERSION = '0.11.0'.freeze
VERSION = '0.11.0'
end
end
7 changes: 4 additions & 3 deletions pronto-rubocop.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

$LOAD_PATH.push File.expand_path('../lib', __FILE__)
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'pronto/rubocop/version'
require 'English'

Expand Down Expand Up @@ -33,7 +33,8 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']

s.add_runtime_dependency('pronto', '~> 0.11.0')
s.add_runtime_dependency('rubocop', '>= 0.63.1', '< 1.0')
s.add_runtime_dependency('rubocop', '>= 0.63.1', '< 2.0')
s.add_development_dependency('appraisal')
s.add_development_dependency('rake', '~> 12.0')
s.add_development_dependency('rspec', '~> 3.4')
s.add_development_dependency('rspec-its', '~> 1.2')
Expand Down
13 changes: 5 additions & 8 deletions spec/pronto/rubocop/offense_line_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe Pronto::Rubocop::OffenseLine do
Expand Down Expand Up @@ -29,7 +31,7 @@
it { expect(message.msg).to eq('Fake message') }

context 'with default severity levels' do
default_level_hash = {
default_level_hash = {
refactor: :warning,
convention: :warning,
warning: :warning,
Expand All @@ -50,13 +52,8 @@
context 'with overridden severity levels to "fatal"' do
let(:config) do
{
'severities' => {
'refactor' => 'fatal',
'convention' => 'fatal',
'warning' => 'fatal',
'error' => 'fatal',
'fatal' => 'fatal',
},
'severities' =>
Hash[::RuboCop::Cop::Severity::NAMES.map { |name| [name, 'fatal'] }]
}
end

Expand Down
5 changes: 4 additions & 1 deletion spec/pronto/rubocop/patch_cop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe Pronto::Rubocop::PatchCop do
Expand All @@ -7,7 +9,8 @@
end
let(:line) { double :line, new_lineno: 42 }
let(:runner) { double :runner }
let(:processed_source) { double :processed_source }
let(:ast) { double :ast, each_node: nil }
let(:processed_source) { double :processed_source, ast: ast }
let(:team) { double :team, inspect_file: [offense] }
let(:offense) { double :offense, disabled?: false, line: 42 }
let(:offense_line) { double :offense_line, message: 'Err' }
Expand Down
2 changes: 2 additions & 0 deletions spec/pronto/rubocop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

module Pronto
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec'
require 'rspec/its'
require 'pronto/rubocop'
Expand Down

0 comments on commit 6477baf

Please sign in to comment.