pronto-rubocop 0.8.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3f3464874bf36e423208f529eb5325482e8b13f3
4
- data.tar.gz: 183b57a9994cf7a70fb51c68ec9983f1fd01f22b
2
+ SHA256:
3
+ metadata.gz: '0588bd2b9b7d1c7a702dba2d9a5cdfc74e4d5df1eaa893557aa13445ab82c9d7'
4
+ data.tar.gz: 6bd89ce4bcec0647adc3c62abe770c8f43aff21d77b96a6c9679f6e35ffc84c2
5
5
  SHA512:
6
- metadata.gz: bf51ee17658b490a7fd98bcd8a556cb4bc9a917d8c3db14bfce218ad7944ac76eba1dfdbe9eded26c9af69e1d3f2525424d3b83046d46ba62ece28227f5ed53f
7
- data.tar.gz: f842558e562ce4dbe4812e74c854aca016a89c244b325f1e4ae817f8d3c6796b912d0d73daadef02b61a535f2c8eb22e5d4445669483ba16bf32fa9ecfabb3c7
6
+ metadata.gz: 2177a1cdf31387028a4dac6aed07b0df8379c33e84d80ac3b1329187beb99ad6b3bb490d1c70b4c098345b5cfac538463beff2767fe0bb28c094e78cbdcd14f1
7
+ data.tar.gz: 48856034490369353ed28755decda13d3e0f225468c8600a2706257ec2a119b88516de1757e7b5a5969ebd76e00e16fd908ca2b0e642901c1f51389a6ce483fc
@@ -0,0 +1,3 @@
1
+ # Order is important. The last matching pattern takes the most precedence.
2
+ # Default owners for everything in the repo.
3
+ * @prontolabs/core
@@ -0,0 +1,22 @@
1
+ name: Checks
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ ruby:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0']
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true
21
+ - name: rake spec
22
+ run: bundle exec rake spec
data/README.md CHANGED
@@ -1,13 +1,40 @@
1
- # Pronto runner for Rubocop
1
+ # Pronto runner for RuboCop
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/mmozuras/pronto-rubocop.png)](https://codeclimate.com/github/mmozuras/pronto-rubocop)
4
- [![Build Status](https://travis-ci.org/mmozuras/pronto-rubocop.png)](https://travis-ci.org/mmozuras/pronto-rubocop)
3
+ [![Code Climate](https://codeclimate.com/github/prontolabs/pronto-rubocop.png)](https://codeclimate.com/github/prontolabs/pronto-rubocop)
4
+ [![Build Status](https://travis-ci.org/prontolabs/pronto-rubocop.svg?branch=master)](https://travis-ci.org/prontolabs/pronto-rubocop)
5
5
  [![Gem Version](https://badge.fury.io/rb/pronto-rubocop.png)](http://badge.fury.io/rb/pronto-rubocop)
6
- [![Dependency Status](https://gemnasium.com/mmozuras/pronto-rubocop.png)](https://gemnasium.com/mmozuras/pronto-rubocop)
7
6
 
8
- Pronto runner for [Rubocop](https://github.com/bbatsov/rubocop), ruby code analyzer. [What is Pronto?](https://github.com/mmozuras/pronto)
7
+ Pronto runner for [RuboCop](https://github.com/bbatsov/rubocop), ruby code
8
+ analyzer. [What is Pronto?](https://github.com/prontolabs/pronto)
9
9
 
10
10
  ## Configuration
11
11
 
12
- Configuring Rubocop via .rubocop.yml will work just fine with pronto-rubocop.
13
- You can also specify a custom `.rubocop.yml` location with the environment variable `RUBOCOP_CONFIG`
12
+ Configuring RuboCop via `.rubocop.yml` will work just fine with
13
+ `pronto-rubocop`.
14
+
15
+ You can also specify a custom `.rubocop.yml` location with the environment
16
+ variable `RUBOCOP_CONFIG`.
17
+
18
+ You can also provide additional configuration via `.pronto.yml`:
19
+
20
+ ```yml
21
+ rubocop:
22
+ # Map of RuboCop severity level to Pronto severity level
23
+ severities:
24
+ refactor: info
25
+ warning: error
26
+
27
+ # Enable suggestions
28
+ suggestions: true
29
+ ```
30
+
31
+ ## Suggestions
32
+
33
+ When suggestions are enabled, the messages will include a line suggesting
34
+ what to change, using [GitHub's](https://twitter.com/wa7son/status/1052326282900443137)
35
+ syntax on Pull Request reviews, that can be approved in one click right from
36
+ the Pull Request.
37
+
38
+ For example:
39
+
40
+ ![GitHub screenshot with suggestion](https://user-images.githubusercontent.com/132/50402757-1bd75b80-0799-11e9-809f-8b8a23ed33f6.png)
@@ -1,71 +1,18 @@
1
1
  require 'pronto'
2
2
  require 'rubocop'
3
+ require 'pronto/rubocop/patch_cop'
4
+ require 'pronto/rubocop/offense_line'
3
5
 
4
6
  module Pronto
5
7
  class Rubocop < Runner
6
- def initialize(_, _ = nil)
7
- super
8
-
9
- @config_store = ::RuboCop::ConfigStore.new
10
- @config_store.options_config = ENV['RUBOCOP_CONFIG'] if ENV['RUBOCOP_CONFIG']
11
- @inspector = ::RuboCop::Runner.new({}, @config_store)
12
- end
13
-
14
8
  def run
15
- return [] unless @patches
16
-
17
- @patches.select { |patch| valid_patch?(patch) }
18
- .map { |patch| inspect(patch) }
19
- .flatten.compact
20
- end
21
-
22
- def valid_patch?(patch)
23
- return false if patch.additions < 1
24
-
25
- config_store = config_store_for(patch)
26
- path = patch.new_file_full_path
27
-
28
- return false if config_store.file_to_exclude?(path.to_s)
29
- return true if config_store.file_to_include?(path.to_s)
30
-
31
- ruby_file?(path)
32
- end
33
-
34
- def inspect(patch)
35
- processed_source = processed_source_for(patch)
36
- offences = @inspector.send(:inspect_file, processed_source).first
37
-
38
- offences.sort.reject(&:disabled?).map do |offence|
39
- patch.added_lines
40
- .select { |line| line.new_lineno == offence.line }
41
- .map { |line| new_message(offence, line) }
42
- end
43
- end
44
-
45
- def new_message(offence, line)
46
- path = line.patch.delta.new_file[:path]
47
- level = level(offence.severity.name)
48
-
49
- Message.new(path, line, level, offence.message, nil, self.class)
50
- end
51
-
52
- def config_store_for(patch)
53
- path = patch.new_file_full_path.to_s
54
- @config_store.for(path)
55
- end
56
-
57
- def processed_source_for(patch)
58
- path = patch.new_file_full_path.to_s
59
- ::RuboCop::ProcessedSource.from_file(path, RUBY_VERSION[0..2].to_f)
9
+ ruby_patches
10
+ .select { |patch| patch.additions > 0 }
11
+ .flat_map { |patch| PatchCop.new(patch, self).messages }
60
12
  end
61
13
 
62
- def level(severity)
63
- case severity
64
- when :refactor, :convention
65
- :info
66
- when :warning, :error, :fatal
67
- severity
68
- end
14
+ def pronto_rubocop_config
15
+ @pronto_rubocop_config ||= Pronto::ConfigFile.new.to_h['rubocop'] || {}
69
16
  end
70
17
  end
71
18
  end
@@ -0,0 +1,128 @@
1
+ module Pronto
2
+ class Rubocop < Runner
3
+ class OffenseLine
4
+ def initialize(patch_cop, offense, line)
5
+ @patch_cop = patch_cop
6
+ @offense = offense
7
+ @line = line
8
+ end
9
+
10
+ def message
11
+ Message.new(path, line, level, message_text, nil, Pronto::Rubocop)
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :patch_cop, :offense, :line
17
+
18
+ def path
19
+ line.patch.delta.new_file[:path]
20
+ end
21
+
22
+ def processed_source
23
+ patch_cop.processed_source
24
+ end
25
+
26
+ def message_text
27
+ return offense.message unless suggestion_text
28
+
29
+ "#{offense.message}\n\n```suggestion\n#{suggestion_text}```"
30
+ end
31
+
32
+ def suggestion_text
33
+ return unless patch_cop.runner.pronto_rubocop_config['suggestions']
34
+ return if corrections_count == 0
35
+ return if differing_lines_count != corrections_count
36
+
37
+ @suggestion_text ||= corrected_lines[offense.line - 1]
38
+ end
39
+
40
+ def corrected_lines
41
+ @corrected_lines ||= corrector.rewrite.lines
42
+ end
43
+
44
+ def differing_lines_count
45
+ original_lines.each_with_index.count do |line, index|
46
+ line != corrected_lines[index]
47
+ end
48
+ end
49
+
50
+ def original_lines
51
+ processed_source.lines.join("\n").lines
52
+ end
53
+
54
+ if ::RuboCop::Cop::Team.respond_to?(:mobilize)
55
+ MOBILIZE = :mobilize
56
+
57
+ def report
58
+ @report ||= autocorrect_team.investigate(processed_source).cop_reports.first
59
+ end
60
+
61
+ def corrector
62
+ report.corrector
63
+ end
64
+
65
+ def corrections_count
66
+ report.offenses.size
67
+ end
68
+ else
69
+ # rubocop < v0.85.0
70
+ MOBILIZE = :new
71
+
72
+ def corrector
73
+ @corrector ||= begin
74
+ autocorrect_team.inspect_file(processed_source)
75
+ corrector = RuboCop::Cop::Corrector.new(processed_source.buffer)
76
+ corrector.corrections.concat(autocorrect_team.cops.first.corrections)
77
+ corrector
78
+ end
79
+ end
80
+
81
+ def corrections_count
82
+ @corrections_count ||= corrector.corrections.count
83
+ end
84
+ end
85
+
86
+ def autocorrect_team
87
+ @autocorrect_team ||=
88
+ ::RuboCop::Cop::Team.send(MOBILIZE,
89
+ ::RuboCop::Cop::Registry.new([cop_class]),
90
+ patch_cop.rubocop_config,
91
+ auto_correct: true,
92
+ stdin: true,
93
+ )
94
+ end
95
+
96
+ def cop_class
97
+ patch_cop.registry.find_by_cop_name(offense.cop_name)
98
+ end
99
+
100
+ def level
101
+ severities.fetch(offense.severity.name)
102
+ end
103
+
104
+ def severities
105
+ @severities ||= DEFAULT_SEVERITIES.merge(config_severities)
106
+ end
107
+
108
+ def config_severities
109
+ patch_cop
110
+ .runner
111
+ .pronto_rubocop_config
112
+ .fetch('severities', {})
113
+ .map { |k, v| [k.to_sym, v.to_sym] }
114
+ .to_h
115
+ end
116
+
117
+ DEFAULT_SEVERITIES = {
118
+ refactor: :warning,
119
+ convention: :warning,
120
+ warning: :warning,
121
+ error: :error,
122
+ fatal: :fatal
123
+ }.freeze
124
+
125
+ private_constant :DEFAULT_SEVERITIES
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,73 @@
1
+ module Pronto
2
+ class Rubocop < Runner
3
+ class PatchCop
4
+ attr_reader :runner
5
+
6
+ def initialize(patch, runner)
7
+ @patch = patch
8
+ @runner = runner
9
+ end
10
+
11
+ def messages
12
+ return [] unless valid?
13
+
14
+ offenses.flat_map do |offense|
15
+ patch
16
+ .added_lines
17
+ .select { |line| line.new_lineno == offense.line }
18
+ .map { |line| OffenseLine.new(self, offense, line).message }
19
+ end
20
+ end
21
+
22
+ def processed_source
23
+ @processed_source ||= ::RuboCop::ProcessedSource.from_file(
24
+ path,
25
+ rubocop_config.target_ruby_version
26
+ )
27
+ end
28
+
29
+ def registry
30
+ @registry ||= ::RuboCop::Cop::Registry.new(RuboCop::Cop::Cop.all)
31
+ end
32
+
33
+ def rubocop_config
34
+ @rubocop_config ||= begin
35
+ store = ::RuboCop::ConfigStore.new
36
+ store.for(path)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :patch
43
+
44
+ def valid?
45
+ return false if rubocop_config.file_to_exclude?(path)
46
+ return true if rubocop_config.file_to_include?(path)
47
+
48
+ true
49
+ end
50
+
51
+ def path
52
+ @path ||= patch.new_file_full_path.to_s
53
+ end
54
+
55
+ def offenses
56
+ team
57
+ .inspect_file(processed_source)
58
+ .sort
59
+ .reject(&:disabled?)
60
+ end
61
+
62
+ def team
63
+ @team ||=
64
+ if ::RuboCop::Cop::Team.respond_to?(:mobilize)
65
+ # rubocop v0.85.0 and later
66
+ ::RuboCop::Cop::Team.mobilize(registry, rubocop_config)
67
+ else
68
+ ::RuboCop::Cop::Team.new(registry, rubocop_config)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,5 +1,5 @@
1
1
  module Pronto
2
2
  module RubocopVersion
3
- VERSION = '0.8.0'.freeze
3
+ VERSION = '0.11.0'.freeze
4
4
  end
5
5
  end
@@ -10,11 +10,11 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.author = 'Mindaugas Mozūras'
12
12
  s.email = 'mindaugas.mozuras@gmail.com'
13
- s.homepage = 'http://github.org/mmozuras/pronto-rubocop'
13
+ s.homepage = 'http://github.com/mmozuras/pronto-rubocop'
14
14
  s.summary = 'Pronto runner for Rubocop, ruby code analyzer'
15
15
 
16
16
  s.licenses = ['MIT']
17
- s.required_ruby_version = '>= 2.0.0'
17
+ s.required_ruby_version = '>= 2.3.0'
18
18
  s.rubygems_version = '1.8.23'
19
19
 
20
20
  s.files = `git ls-files`.split($RS).reject do |file|
@@ -32,9 +32,9 @@ Gem::Specification.new do |s|
32
32
  s.extra_rdoc_files = ['LICENSE', 'README.md']
33
33
  s.require_paths = ['lib']
34
34
 
35
- s.add_runtime_dependency('rubocop', '~> 0.38', '>= 0.35.0')
36
- s.add_runtime_dependency('pronto', '~> 0.8.0')
37
- s.add_development_dependency('rake', '~> 11.0')
35
+ s.add_runtime_dependency('pronto', '~> 0.11.0')
36
+ s.add_runtime_dependency('rubocop', '>= 0.49.1', '< 1.0')
37
+ s.add_development_dependency('rake', '~> 12.0')
38
38
  s.add_development_dependency('rspec', '~> 3.4')
39
39
  s.add_development_dependency('rspec-its', '~> 1.2')
40
40
  end
metadata CHANGED
@@ -1,63 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindaugas Mozūras
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-12 00:00:00.000000000 Z
11
+ date: 2021-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubocop
14
+ name: pronto
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.38'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.35.0
19
+ version: 0.11.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.38'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.35.0
26
+ version: 0.11.0
33
27
  - !ruby/object:Gem::Dependency
34
- name: pronto
28
+ name: rubocop
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - "~>"
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.49.1
34
+ - - "<"
38
35
  - !ruby/object:Gem::Version
39
- version: 0.8.0
36
+ version: '1.0'
40
37
  type: :runtime
41
38
  prerelease: false
42
39
  version_requirements: !ruby/object:Gem::Requirement
43
40
  requirements:
44
- - - "~>"
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.49.1
44
+ - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.8.0
46
+ version: '1.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '11.0'
53
+ version: '12.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '11.0'
60
+ version: '12.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -94,12 +94,16 @@ extra_rdoc_files:
94
94
  - LICENSE
95
95
  - README.md
96
96
  files:
97
+ - ".github/CODEOWNERS"
98
+ - ".github/workflows/checks.yml"
97
99
  - LICENSE
98
100
  - README.md
99
101
  - lib/pronto/rubocop.rb
102
+ - lib/pronto/rubocop/offense_line.rb
103
+ - lib/pronto/rubocop/patch_cop.rb
100
104
  - lib/pronto/rubocop/version.rb
101
105
  - pronto-rubocop.gemspec
102
- homepage: http://github.org/mmozuras/pronto-rubocop
106
+ homepage: http://github.com/mmozuras/pronto-rubocop
103
107
  licenses:
104
108
  - MIT
105
109
  metadata: {}
@@ -111,15 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
115
  requirements:
112
116
  - - ">="
113
117
  - !ruby/object:Gem::Version
114
- version: 2.0.0
118
+ version: 2.3.0
115
119
  required_rubygems_version: !ruby/object:Gem::Requirement
116
120
  requirements:
117
121
  - - ">="
118
122
  - !ruby/object:Gem::Version
119
123
  version: '0'
120
124
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.6.10
125
+ rubygems_version: 3.0.3
123
126
  signing_key:
124
127
  specification_version: 4
125
128
  summary: Pronto runner for Rubocop, ruby code analyzer