rubocop-changes 0.6.0 → 0.8.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: ee87c885eb2498625bb6f9fc0a59719cbd1c59d71419fd32e1fc3128aa201ce0
4
- data.tar.gz: 947199d33a4427840836b901f780661b98f32428ac6aaaae8012c5cf449e4a48
3
+ metadata.gz: '09daace2e31cf1451cba68fe23ac1c6ab439f281b23d1634c004fe316b67cd8e'
4
+ data.tar.gz: dc982a2074301f56ad4658c97cd09b9e2f657498476d52c60d2bea242f60b32e
5
5
  SHA512:
6
- metadata.gz: 6eb29fc5b10fcdcbbb9966d5d287459def271a9ac1d593e81d227c7c1e78fb15e1a74018e93c6fd6251d24d4037da6df7b6a5c1b7e862fabaf56a7cfd70368e6
7
- data.tar.gz: e43732b83c2f830f69fa795ac96d6c80bce7c1f48e0e54c9a4e076fc1614056b264268241dd9deee99a1520b99f97219c005cb6a60ec90c09bbb8be1b4423d01
6
+ metadata.gz: cc9ccaf62d221526a6405f8e57a8b4c7b5ede8963a43b5793ab4013914da4eca6535f4c00c55d32038dddde15e7966f5e7c280615ab8900f57fdfb308db19f2c
7
+ data.tar.gz: a1d648e0776098ceb27e23d0f3efb6742d7b71fef4cfb28e628e8e0f9f4cd5d64daf829a8782196306519322cba50afa6c2c2585c896612595674b2f85e6565a
@@ -10,7 +10,7 @@ jobs:
10
10
  strategy:
11
11
  fail-fast: false
12
12
  matrix:
13
- ruby: ["2.5", "2.6", "2.7", "3.0", "3.1", ruby-head]
13
+ ruby: ["2.6", "2.7", "3.0", "3.1", ruby-head]
14
14
 
15
15
  steps:
16
16
  - uses: actions/checkout@v2
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-changes (0.5.0)
4
+ rubocop-changes (0.8.0)
5
5
  git_diff_parser (~> 3.2)
6
- rubocop (~> 1.25)
6
+ rubocop (>= 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -12,12 +12,13 @@ GEM
12
12
  byebug (10.0.2)
13
13
  diff-lcs (1.3)
14
14
  git_diff_parser (3.2.0)
15
- parallel (1.21.0)
16
- parser (3.1.0.0)
15
+ json (2.6.3)
16
+ parallel (1.22.1)
17
+ parser (3.2.0.0)
17
18
  ast (~> 2.4.1)
18
19
  rainbow (3.1.1)
19
20
  rake (13.0.3)
20
- regexp_parser (2.2.0)
21
+ regexp_parser (2.6.2)
21
22
  rexml (3.2.5)
22
23
  rspec (3.9.0)
23
24
  rspec-core (~> 3.9.0)
@@ -32,19 +33,20 @@ GEM
32
33
  diff-lcs (>= 1.2.0, < 2.0)
33
34
  rspec-support (~> 3.9.0)
34
35
  rspec-support (3.9.0)
35
- rubocop (1.25.0)
36
+ rubocop (1.44.0)
37
+ json (~> 2.3)
36
38
  parallel (~> 1.10)
37
- parser (>= 3.1.0.0)
39
+ parser (>= 3.2.0.0)
38
40
  rainbow (>= 2.2.2, < 4.0)
39
41
  regexp_parser (>= 1.8, < 3.0)
40
- rexml
41
- rubocop-ast (>= 1.15.1, < 2.0)
42
+ rexml (>= 3.2.5, < 4.0)
43
+ rubocop-ast (>= 1.24.1, < 2.0)
42
44
  ruby-progressbar (~> 1.7)
43
- unicode-display_width (>= 1.4.0, < 3.0)
44
- rubocop-ast (1.15.1)
45
- parser (>= 3.0.1.1)
45
+ unicode-display_width (>= 2.4.0, < 3.0)
46
+ rubocop-ast (1.24.1)
47
+ parser (>= 3.1.1.0)
46
48
  ruby-progressbar (1.11.0)
47
- unicode-display_width (2.1.0)
49
+ unicode-display_width (2.4.2)
48
50
 
49
51
  PLATFORMS
50
52
  ruby
data/README.md CHANGED
@@ -32,7 +32,9 @@ Or install it yourself as:
32
32
 
33
33
  ## Usage
34
34
 
35
- $ bundle exec rubocop-changes
35
+ $ bundle exec rubocop-changes -b master
36
+
37
+ When you run `rubocop-changes`, you have to specify which is your base branch with `-b` argument. By default is `main`. If you want to avoid to pass this argument everytime you execute this command, you can also set the `RUBOCOP_CHANGES_BASE_BRANCH` environment variable.
36
38
 
37
39
  ## Other gems
38
40
 
@@ -10,6 +10,7 @@ require 'rubocop/changes/shell'
10
10
  module Rubocop
11
11
  module Changes
12
12
  class UnknownFormat < StandardError; end
13
+ class UnknownBaseBranchError < StandardError; end
13
14
  class UnknownForkPointError < StandardError; end
14
15
 
15
16
  class Checker
@@ -22,6 +23,7 @@ module Rubocop
22
23
  end
23
24
 
24
25
  def run
26
+ raise UnknownBaseBranchError if base_branch.empty?
25
27
  raise UnknownForkPointError if fork_point.empty?
26
28
  raise UnknownFormat if formatter_klass.nil?
27
29
 
@@ -32,14 +34,23 @@ module Rubocop
32
34
 
33
35
  private
34
36
 
35
- attr_reader :format, :quiet, :commit, :auto_correct
37
+ attr_reader :format, :quiet, :commit, :auto_correct, :base_branch
38
+
39
+ def path_prefix
40
+ return @path_prefix if defined?(@path_prefix)
41
+ @path_prefix = local_git_root_path && Dir.pwd.gsub(local_git_root_path, '')[1..-1]
42
+ end
43
+
44
+ def local_git_root_path
45
+ @local_git_root_path ||= Shell.run("git rev-parse --show-toplevel")
46
+ end
36
47
 
37
48
  def fork_point
38
49
  @fork_point ||= Shell.run(command)
39
50
  end
40
51
 
41
52
  def command
42
- return "git merge-base HEAD origin/#{@base_branch}" unless commit
53
+ return "git merge-base HEAD origin/#{base_branch}" unless commit
43
54
 
44
55
  "git log -n 1 --pretty=format:\"%h\" #{commit}"
45
56
  end
@@ -57,7 +68,17 @@ module Rubocop
57
68
  end
58
69
 
59
70
  def ruby_changed_files
60
- changed_files.select { |changed_file| changed_file =~ /.rb$/ }
71
+ changed_files.select { |changed_file| changed_file =~ /\.rb$/ }
72
+ end
73
+
74
+ def ruby_changed_files_from_pwd
75
+ ruby_changed_files.map do |path|
76
+ if path_prefix
77
+ path.gsub(/^#{path_prefix}\//, '')
78
+ else
79
+ path
80
+ end
81
+ end
61
82
  end
62
83
 
63
84
  def rubocop
@@ -76,11 +97,11 @@ module Rubocop
76
97
  end
77
98
 
78
99
  def formatter_modifier
79
- "-f j #{ruby_changed_files.join(' ')}"
100
+ "-f j #{ruby_changed_files_from_pwd.join(' ')}"
80
101
  end
81
102
 
82
103
  def auto_correct_modifier
83
- '-a' if @auto_correct
104
+ '-A' if @auto_correct
84
105
  end
85
106
 
86
107
  def rubocop_json
@@ -121,7 +142,9 @@ module Rubocop
121
142
  end
122
143
 
123
144
  def formatter_klass
124
- @formatter_klass ||= formatters[format]
145
+ return formatters[format] unless formatters[format].is_a? String
146
+
147
+ Kernel.const_get("RuboCop::Formatter::#{formatters[format]}")
125
148
  end
126
149
 
127
150
  def formatters
@@ -8,7 +8,13 @@ module Rubocop
8
8
  Options = Struct.new(:format, :quiet, :commit, :auto_correct, :base_branch)
9
9
 
10
10
  def initialize
11
- @args = Options.new(:simple, false, nil, false, 'main') # Defaults
11
+ @args = Options.new(
12
+ :simple,
13
+ false,
14
+ nil,
15
+ false,
16
+ ENV.fetch('RUBOCOP_CHANGES_BASE_BRANCH', 'main')
17
+ ) # Defaults
12
18
  end
13
19
 
14
20
  def parse!
@@ -73,7 +79,8 @@ module Rubocop
73
79
  end
74
80
 
75
81
  def parse_base_branch!(opts)
76
- opts.on('-b', '--base_branch [BRANCH]', 'Base branch to compare') do |v|
82
+ env_message = 'Also, you can set RUBOCOP_CHANGES_BASE_BRANCH environment variable'
83
+ opts.on('-b', '--base-branch [BRANCH]', "Base branch to compare. #{env_message}") do |v|
77
84
  args.base_branch = v
78
85
  end
79
86
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Changes
5
- VERSION = '0.6.0'
5
+ VERSION = '0.8.0'
6
6
  end
7
7
  end
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.require_paths = ['lib']
38
38
 
39
39
  spec.add_runtime_dependency 'git_diff_parser', '~> 3.2'
40
- spec.add_runtime_dependency 'rubocop', '~> 1.25'
40
+ spec.add_runtime_dependency 'rubocop', '>= 1.0'
41
41
 
42
42
  spec.add_development_dependency 'bundler', '~> 2.0'
43
43
  spec.add_development_dependency 'byebug', '~> 10.0'
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.6.0
4
+ version: 0.8.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: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2023-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git_diff_parser
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rubocop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.25'
33
+ version: '1.0'
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: '1.25'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubygems_version: 3.1.2
151
+ rubygems_version: 3.3.5
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Rubocop on changed lines from git fork point