rubocop-changes 0.1.2 → 0.4.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
2
  SHA256:
3
- metadata.gz: 37daad64414834e07edb588962bdf3916e67fc450a2e3746ab5e45272f5fb72e
4
- data.tar.gz: 5737ea89aa55ce98e89019537e4f54774729b1a19292f40fa2755591721f2763
3
+ metadata.gz: 4a94905b21e4303a0e32552697c0766e15aa6caedba8a96a047f5ecc5f5393fd
4
+ data.tar.gz: 98efe986e967c29ef194427f0cab777b9d611d230b1add48f44716e475d2164e
5
5
  SHA512:
6
- metadata.gz: 96a3aa06fd3bcc04f9556b73a88adc391c1ef4509070aa5386b73442a7b5c1092a02cb904f3f1d34cd679cb90e77d42632181c567ddcd2d38f33e451ad28694a
7
- data.tar.gz: f9511dabaa54358cfb3760ca31dbdb4f351d6e1c86d4a0cc3ad5385569a10a2ebda81c801b7d8536ebb67ee80e5e654a12a1be477b94df5280141872d275f702
6
+ metadata.gz: 34ae25af5ff70f8428c54dca710d8b0e423b8f599ab4b854e73d080ccc4db008dd9a85f34feeaefa98d6c2faabb4bcef0c8ab3a30bfa371b42c1592f65779972
7
+ data.tar.gz: 392d5448f21ebe2bdf11e8b3b09bcb6d54212906bbebca4da3850efddd78e6ec3f3653b421754c9696747c76be63aeb4b75c86aa8aa60dd3bf8375c9898e6d2e
data/.rubocop.yml CHANGED
@@ -1,2 +1,20 @@
1
+ Lint/RaiseException:
2
+ Enabled: false
3
+
4
+ Lint/StructNewOverride:
5
+ Enabled: false
6
+
7
+ Style/HashEachMethods:
8
+ Enabled: false
9
+
10
+ Style/HashTransformKeys:
11
+ Enabled: false
12
+
13
+ Style/HashTransformValues:
14
+ Enabled: false
15
+
1
16
  Style/Documentation:
2
17
  Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Max: 120
data/Gemfile.lock CHANGED
@@ -1,23 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-changes (0.1.2)
4
+ rubocop-changes (0.4.0)
5
5
  git_diff_parser (~> 3.2)
6
- rubocop (~> 0.59)
6
+ rubocop (~> 0.80)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.0)
11
+ ast (2.4.2)
12
12
  byebug (10.0.2)
13
13
  diff-lcs (1.3)
14
14
  git_diff_parser (3.2.0)
15
15
  jaro_winkler (1.5.4)
16
16
  parallel (1.19.1)
17
- parser (2.6.5.0)
18
- ast (~> 2.4.0)
17
+ parser (3.0.0.0)
18
+ ast (~> 2.4.1)
19
19
  rainbow (3.0.0)
20
- rake (10.5.0)
20
+ rake (13.0.3)
21
+ rexml (3.2.5)
21
22
  rspec (3.9.0)
22
23
  rspec-core (~> 3.9.0)
23
24
  rspec-expectations (~> 3.9.0)
@@ -31,15 +32,16 @@ GEM
31
32
  diff-lcs (>= 1.2.0, < 2.0)
32
33
  rspec-support (~> 3.9.0)
33
34
  rspec-support (3.9.0)
34
- rubocop (0.76.0)
35
+ rubocop (0.81.0)
35
36
  jaro_winkler (~> 1.5.1)
36
37
  parallel (~> 1.10)
37
- parser (>= 2.6)
38
+ parser (>= 2.7.0.1)
38
39
  rainbow (>= 2.2.2, < 4.0)
40
+ rexml
39
41
  ruby-progressbar (~> 1.7)
40
- unicode-display_width (>= 1.4.0, < 1.7)
42
+ unicode-display_width (>= 1.4.0, < 2.0)
41
43
  ruby-progressbar (1.10.1)
42
- unicode-display_width (1.6.0)
44
+ unicode-display_width (1.7.0)
43
45
 
44
46
  PLATFORMS
45
47
  ruby
@@ -47,9 +49,9 @@ PLATFORMS
47
49
  DEPENDENCIES
48
50
  bundler (~> 2.0)
49
51
  byebug (~> 10.0)
50
- rake (~> 10.0)
52
+ rake (~> 13.0)
51
53
  rspec (~> 3.0)
52
54
  rubocop-changes!
53
55
 
54
56
  BUNDLED WITH
55
- 2.0.2
57
+ 2.1.4
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rubocop::Changes
2
2
 
3
- [![Gem Version](http://img.shields.io/gem/v/rubocop-changes.svg?style=flat)](http://badge.fury.io/rb/rubocop-changes)
4
- [![Build Status](http://img.shields.io/travis/fcsonline/rubocop-changes/master.svg?style=flat)](https://travis-ci.org/fcsonline/rubocop-changes)
3
+ [![Gem Version](https://img.shields.io/gem/v/rubocop-changes)](https://rubygems.org/gems/rubocop-changes)
4
+ [![Build Status](https://img.shields.io/travis/com/fcsonline/rubocop-changes/master)](https://travis-ci.com/fcsonline/rubocop-changes)
5
5
 
6
6
  `rubocop-changes` runs rubocop and shows only the offenses you introduced since
7
7
  the fork point of your git branch. Will not complain about existing offenses in
@@ -34,21 +34,25 @@ Or install it yourself as:
34
34
 
35
35
  $ bundle exec rubocop-changes
36
36
 
37
- ## Alternatives
37
+ ## Other gems
38
38
 
39
- There are similar projects out there, but all of them show all Rubocop offenses for all changes files:
39
+ There are similar projects out there, like
40
+ [rubocop-git](https://github.com/m4i/rubocop-git),
41
+ [diffcop](https://github.com/yohira0616/diffcop),
42
+ [nexocop](https://github.com/SimpleNexus/nexocop), but not all of them offer
43
+ differences at line level. Only
44
+ [rubocop-git](https://github.com/m4i/rubocop-git) offer this nice feature but
45
+ you have to craft the commit id to get the proper fork point of your pull
46
+ request.
40
47
 
41
- - https://github.com/m4i/rubocop-git
42
- - https://github.com/packsaddle/rubocop-select
43
- - https://github.com/mcgain/rubocop-diff
44
- - https://github.com/yohira0616/diffcop
45
- - https://github.com/SimpleNexus/nexocop
48
+ rubocop-changes does this diff out of the box without specify any commit id. If
49
+ you want to get the offense comparing from one specific commit, you can pass
50
+ the argument `commit` to the command.
46
51
 
47
52
  ## Ideas
48
53
 
49
54
  Those are some ideas to improve `rubocop-changes`:
50
55
 
51
- - [ ] Let users specify which formatter to use for the output
52
56
  - [ ] Let users specify the rubocop config file
53
57
 
54
58
  ## Development
data/exe/rubocop-changes CHANGED
@@ -1,9 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'rubocop'
5
+
4
6
  require 'rubocop/changes/checker'
7
+ require 'rubocop/changes/options'
8
+
9
+ args = Rubocop::Changes::Options.new.parse!
5
10
 
6
- checker = Rubocop::Changes::Checker.new
7
- offenses = checker.run
11
+ offenses = Rubocop::Changes::Checker.new(
12
+ format: args.format,
13
+ quiet: args.quiet,
14
+ commit: args.commit,
15
+ auto_correct: args.auto_correct
16
+ ).run
8
17
 
9
18
  exit offenses.count.positive? ? 1 : 0
@@ -9,28 +9,38 @@ require 'rubocop/changes/shell'
9
9
 
10
10
  module Rubocop
11
11
  module Changes
12
+ class UnknownFormat < StandardError; end
12
13
  class UnknownForkPointError < StandardError; end
13
14
 
14
15
  class Checker
16
+ def initialize(format:, quiet:, commit:, auto_correct:)
17
+ @format = format
18
+ @quiet = quiet
19
+ @commit = commit
20
+ @auto_correct = auto_correct
21
+ end
22
+
15
23
  def run
16
24
  raise UnknownForkPointError if fork_point.empty?
25
+ raise UnknownFormat if formatter_klass.nil?
17
26
 
18
- # TODO: Let users choose the formatter
19
- formatter = RuboCop::Formatter::SimpleTextFormatter.new($stdout)
20
-
21
- formatter.started('')
22
-
23
- print_offenses(formatter)
24
-
25
- formatter.finished(ruby_changed_files)
27
+ print_offenses! unless quiet
26
28
 
27
29
  checks.map(&:offenses).flatten
28
30
  end
29
31
 
30
32
  private
31
33
 
34
+ attr_reader :format, :quiet, :commit, :auto_correct
35
+
32
36
  def fork_point
33
- @fork_point ||= Shell.run('git merge-base HEAD origin/master')
37
+ @fork_point ||= Shell.run(command)
38
+ end
39
+
40
+ def command
41
+ return 'git merge-base HEAD origin/master' unless commit
42
+
43
+ "git log -n 1 --pretty=format:\"%h\" #{commit}"
34
44
  end
35
45
 
36
46
  def diff
@@ -50,7 +60,26 @@ module Rubocop
50
60
  end
51
61
 
52
62
  def rubocop
53
- Shell.run("bundle exec rubocop -f j #{ruby_changed_files.join(' ')}")
63
+ shell_command = [
64
+ 'rubocop',
65
+ exclussion_modifier,
66
+ formatter_modifier,
67
+ auto_correct_modifier
68
+ ].compact.join(' ')
69
+
70
+ Shell.run(shell_command)
71
+ end
72
+
73
+ def exclussion_modifier
74
+ '--force-exclusion'
75
+ end
76
+
77
+ def formatter_modifier
78
+ "-f j #{ruby_changed_files.join(' ')}"
79
+ end
80
+
81
+ def auto_correct_modifier
82
+ '-a' if @auto_correct
54
83
  end
55
84
 
56
85
  def rubocop_json
@@ -76,13 +105,35 @@ module Rubocop
76
105
  checks.map { |check| check.offended_lines.size }.inject(0, :+)
77
106
  end
78
107
 
79
- def print_offenses(formatter)
108
+ def print_offenses!
109
+ formatter.started(checks)
110
+
80
111
  checks.each do |check|
81
- print_offenses_for_check(formatter, check)
112
+ print_offenses_for_check(check)
82
113
  end
114
+
115
+ formatter.finished(ruby_changed_files)
116
+ end
117
+
118
+ def formatter
119
+ @formatter ||= formatter_klass.new($stdout)
120
+ end
121
+
122
+ def formatter_klass
123
+ @formatter_klass ||= formatters[format]
124
+ end
125
+
126
+ def formatters
127
+ rubocop_formatters.map do |key, value|
128
+ [key.gsub(/[\[\]]/, '').to_sym, value]
129
+ end.to_h
130
+ end
131
+
132
+ def rubocop_formatters
133
+ RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS
83
134
  end
84
135
 
85
- def print_offenses_for_check(formatter, check)
136
+ def print_offenses_for_check(check)
86
137
  offenses = check.offenses.map do |offense|
87
138
  RuboCop::Cop::Offense.new(
88
139
  offense.severity,
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module Rubocop
6
+ module Changes
7
+ class Options
8
+ Options = Struct.new(:format, :quiet, :commit, :auto_correct)
9
+
10
+ def initialize
11
+ @args = Options.new(:simple, false, nil, false) # Defaults
12
+ end
13
+
14
+ def parse!
15
+ OptionParser.new do |opts|
16
+ opts.banner = 'Usage: rubocop-changes [options]'
17
+
18
+ parse_formatter!(opts)
19
+ parse_commit!(opts)
20
+ parse_quiet!(opts)
21
+ parse_auto_correct!(opts)
22
+ parse_help!(opts)
23
+ parse_version!(opts)
24
+ end.parse!
25
+
26
+ args
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :args
32
+
33
+ def formatter_values
34
+ formatters = RuboCop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS
35
+
36
+ formatters.keys.map do |key|
37
+ key.gsub(/[\[\]]/, '').to_sym
38
+ end
39
+ end
40
+
41
+ def parse_formatter!(opts)
42
+ opts.on(
43
+ '-f',
44
+ '--formatter [FORMATER]',
45
+ formatter_values,
46
+ "Select format type (#{formatter_values.join(', ')})"
47
+ ) do |t|
48
+ args.format = t
49
+ end
50
+ end
51
+
52
+ def parse_commit!(opts)
53
+ opts.on(
54
+ '-c',
55
+ '--commit [COMMIT_ID]',
56
+ 'Compare from some specific point on git history'
57
+ ) do |c|
58
+ args.commit = c
59
+ end
60
+ end
61
+
62
+ def parse_quiet!(opts)
63
+ opts.on('-q', '--quiet', 'Be quiet') do |v|
64
+ args.quiet = v
65
+ end
66
+ end
67
+
68
+ def parse_auto_correct!(opts)
69
+ opts.on('-a', '--auto-correct', 'Auto correct errors') do |v|
70
+ args.auto_correct = v
71
+ end
72
+ end
73
+
74
+ def parse_help!(opts)
75
+ opts.on('-h', '--help', 'Prints this help') do
76
+ puts opts
77
+ exit
78
+ end
79
+ end
80
+
81
+ def parse_version!(opts)
82
+ opts.on('--version', 'Display version') do
83
+ puts Rubocop::Changes::VERSION
84
+ exit 0
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Changes
5
- VERSION = '0.1.2'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -10,10 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Ferran Basora']
11
11
  spec.email = ['fcsonline@gmail.com']
12
12
 
13
- spec.summary = "Rubocop on changed lines from forked point"
13
+ spec.summary = 'Rubocop on changed lines from git fork point'
14
14
  spec.description = <<-DESCRIPTION
15
15
  rubocop-changes will run rubocop on changed lines from forked point in your main branch.
16
- It will not complain about existing offenses in master branch.
16
+ It will not complain about existing offenses in master branch on your git prioject.
17
17
  This gem is perfect as a Continuous Integration tool
18
18
  DESCRIPTION
19
19
 
@@ -26,8 +26,9 @@ Gem::Specification.new do |spec|
26
26
  }
27
27
 
28
28
  # Specify which files should be added to the gem when it is released.
29
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
30
+ # into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
32
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
33
  end
33
34
  spec.bindir = 'exe'
@@ -36,10 +37,10 @@ Gem::Specification.new do |spec|
36
37
  spec.require_paths = ['lib']
37
38
 
38
39
  spec.add_runtime_dependency 'git_diff_parser', '~> 3.2'
39
- spec.add_runtime_dependency 'rubocop', '~> 0.59'
40
+ spec.add_runtime_dependency 'rubocop', '~> 0.80'
40
41
 
41
42
  spec.add_development_dependency 'bundler', '~> 2.0'
42
43
  spec.add_development_dependency 'byebug', '~> 10.0'
43
- spec.add_development_dependency 'rake', '~> 10.0'
44
+ spec.add_development_dependency 'rake', '~> 13.0'
44
45
  spec.add_development_dependency 'rspec', '~> 3.0'
45
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferran Basora
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-29 00:00:00.000000000 Z
11
+ date: 2021-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git_diff_parser
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.59'
33
+ version: '0.80'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.59'
40
+ version: '0.80'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +96,7 @@ dependencies:
96
96
  version: '3.0'
97
97
  description: |2
98
98
  rubocop-changes will run rubocop on changed lines from forked point in your main branch.
99
- It will not complain about existing offenses in master branch.
99
+ It will not complain about existing offenses in master branch on your git prioject.
100
100
  This gem is perfect as a Continuous Integration tool
101
101
  email:
102
102
  - fcsonline@gmail.com
@@ -123,6 +123,7 @@ files:
123
123
  - lib/rubocop/changes.rb
124
124
  - lib/rubocop/changes/check.rb
125
125
  - lib/rubocop/changes/checker.rb
126
+ - lib/rubocop/changes/options.rb
126
127
  - lib/rubocop/changes/shell.rb
127
128
  - lib/rubocop/changes/version.rb
128
129
  - rubocop-changes.gemspec
@@ -147,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  - !ruby/object:Gem::Version
148
149
  version: '0'
149
150
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.6
151
+ rubygems_version: 3.0.1
152
152
  signing_key:
153
153
  specification_version: 4
154
- summary: Rubocop on changed lines from forked point
154
+ summary: Rubocop on changed lines from git fork point
155
155
  test_files: []