rubocop_todo_corrector 0.4.0 → 0.7.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: c85c8d566f2b49425a572f879680331084e81e9d3ef8de784f01d76a02405ea2
4
- data.tar.gz: b42c06c055c914dd5ec4c26147c9de35f77361b08b621d3dd415d9bbbe498408
3
+ metadata.gz: f837600adefd9711b9b73eca485464781dcf9ba2bbf14bc2aec2f899c92c8ee5
4
+ data.tar.gz: cafef555598fc0f848bc739317fb3f9d507b227520f86f9fa4ffa1cc5d631b17
5
5
  SHA512:
6
- metadata.gz: 30fe5e842703e0f9416d15fa5a11a36c8caf66481266381fcad1fcf422bb6b21632276119e3c442710e45a9728ca8c87c035883adb19d59a8a1c966f15d7f989
7
- data.tar.gz: c8bbb8075412c6f784e39f73455371fabd593e2c3ca9409eb68abd683f54b4170aa46e94375c6f3c6db2cd5a4a72808cc7b8c6acd999e3131f7ba8efb36b155b
6
+ metadata.gz: 3f0a064fa54502df60aba17ed32103b55f741704336a4fe2040c9478f5925b5bb2116bbf684fb3f2e8d64e9124408302185a1070f50fadc619a864010b2d45d6
7
+ data.tar.gz: 42479c0a9828bfed5899f1cfb3e1f5dbb847330f09aeda1a12126f62af3b8634879fca8177e955ba098c73d56702ec4d52cb983348892217fdc5907dc567f6cd
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ require:
4
4
 
5
5
  AllCops:
6
6
  NewCops: enable
7
- TargetRubyVersion: 3.0
7
+ TargetRubyVersion: 3.1
8
8
 
9
9
  Metrics:
10
10
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.7.0 - 2022-05-27
6
+
7
+ ### Added
8
+
9
+ - Support rubocop 1.30 .rubocop_todo.yml format.
10
+
11
+ ## 0.6.0 - 2022-05-16
12
+
13
+ ### Added
14
+
15
+ - Add `--only-safe` option to `correct` and `pick` command (default: `true`).
16
+
17
+ ## 0.5.0 - 2022-05-16
18
+
19
+ ### Changed
20
+
21
+ - Change required ruby version from 3.0 to 3.1.
22
+
5
23
  ## 0.4.0 - 2022-05-16
6
24
 
7
25
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop_todo_corrector (0.4.0)
4
+ rubocop_todo_corrector (0.7.0)
5
5
  bundler
6
6
  thor
7
7
  yard
data/README.md CHANGED
@@ -29,7 +29,7 @@ Commands:
29
29
  rubocop_todo_corrector describe --cop-name=COP_NAME # Output Markdown description for specified cop.
30
30
  rubocop_todo_corrector generate # Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
31
31
  rubocop_todo_corrector help [COMMAND] # Describe available commands or one specific command
32
- rubocop_todo_corrector pick # Pick an auto-correctable Cop from .rubocop_todo.yml.
32
+ rubocop_todo_corrector pick # Output an auto-correctable Cop from .rubocop_todo.yml.
33
33
  rubocop_todo_corrector remove --cop-name=COP_NAME # Remove section with specified cop name from .rubocop_todo.yml.
34
34
  ```
35
35
 
@@ -46,11 +46,14 @@ Run `bundle install` to install RuboCop related gems.
46
46
  ### correct
47
47
 
48
48
  ```console
49
- $ rubocop_todo_corrector help correct
50
49
  Usage:
51
50
  rubocop_todo_corrector correct
52
51
 
53
- Run `rubocop --auto-correct-all`.
52
+ Options:
53
+ [--only-safe], [--no-only-safe]
54
+ # Default: true
55
+
56
+ Run `rubocop --auto-correct(-all)`.
54
57
  ```
55
58
 
56
59
  ### describe
@@ -85,8 +88,10 @@ Usage:
85
88
 
86
89
  Options:
87
90
  [--mode=MODE]
88
- # Default: random
89
- # Possible values: first, last, least_occurred, most_occurred, random
91
+ # Default: random
92
+ # Possible values: first, last, least_occurred, most_occurred, random
93
+ [--only-safe], [--no-only-safe]
94
+ # Default: true
90
95
 
91
96
  Output an auto-correctable Cop from .rubocop_todo.yml.
92
97
  ```
@@ -12,8 +12,8 @@ module RubocopTodoCorrector
12
12
  temporary_gemfile_path:
13
13
  )
14
14
  new(
15
- gem_specifications: gem_specifications,
16
- temporary_gemfile_path: temporary_gemfile_path
15
+ gem_specifications:,
16
+ temporary_gemfile_path:
17
17
  ).call
18
18
  end
19
19
  end
@@ -14,9 +14,15 @@ module RubocopTodoCorrector
14
14
  )
15
15
  end
16
16
 
17
- desc 'correct', 'Run `rubocop --auto-correct-all`.'
17
+ desc 'correct', 'Run `rubocop --auto-correct(-all)`.'
18
+ option(
19
+ :only_safe,
20
+ default: true,
21
+ type: :boolean
22
+ )
18
23
  def correct
19
24
  Commands::Correct.call(
25
+ only_safe: options[:only_safe],
20
26
  temporary_gemfile_path: 'tmp/Gemfile_rubocop_todo_corrector.rb'
21
27
  )
22
28
  end
@@ -42,7 +48,7 @@ module RubocopTodoCorrector
42
48
  )
43
49
  end
44
50
 
45
- desc 'pick', 'Pick an auto-correctable Cop from .rubocop_todo.yml.'
51
+ desc 'pick', 'Output an auto-correctable Cop from .rubocop_todo.yml.'
46
52
  option(
47
53
  :mode,
48
54
  default: 'random',
@@ -55,9 +61,15 @@ module RubocopTodoCorrector
55
61
  ],
56
62
  type: :string
57
63
  )
64
+ option(
65
+ :only_safe,
66
+ default: true,
67
+ type: :boolean
68
+ )
58
69
  def pick
59
70
  Commands::Pick.call(
60
71
  mode: options[:mode],
72
+ only_safe: options[:only_safe],
61
73
  rubocop_todo_path: '.rubocop_todo.yml'
62
74
  )
63
75
  end
@@ -13,9 +13,9 @@ module RubocopTodoCorrector
13
13
  temporary_gemfile_path:
14
14
  )
15
15
  new(
16
- rubocop_configuration_path: rubocop_configuration_path,
17
- gemfile_lock_path: gemfile_lock_path,
18
- temporary_gemfile_path: temporary_gemfile_path
16
+ rubocop_configuration_path:,
17
+ gemfile_lock_path:,
18
+ temporary_gemfile_path:
19
19
  ).call
20
20
  end
21
21
  end
@@ -32,7 +32,7 @@ module RubocopTodoCorrector
32
32
 
33
33
  def call
34
34
  BundleInstaller.call(
35
- gem_specifications: gem_specifications,
35
+ gem_specifications:,
36
36
  temporary_gemfile_path: @temporary_gemfile_path
37
37
  )
38
38
  end
@@ -51,9 +51,9 @@ module RubocopTodoCorrector
51
51
  def gem_specifications
52
52
  gem_names.map do |gem_name|
53
53
  {
54
- gem_name: gem_name,
54
+ gem_name:,
55
55
  gem_version: GemVersionDetector.call(
56
- gem_name: gem_name,
56
+ gem_name:,
57
57
  gemfile_lock_path: @gemfile_lock_path
58
58
  )
59
59
  }
@@ -4,28 +4,44 @@ module RubocopTodoCorrector
4
4
  module Commands
5
5
  class Correct
6
6
  class << self
7
+ # @param [Boolean] only_safe
7
8
  # @param [String] temporary_gemfile_path
8
9
  def call(
10
+ only_safe:,
9
11
  temporary_gemfile_path:
10
12
  )
11
13
  new(
12
- temporary_gemfile_path: temporary_gemfile_path
14
+ only_safe:,
15
+ temporary_gemfile_path:
13
16
  ).call
14
17
  end
15
18
  end
16
19
 
17
20
  def initialize(
21
+ only_safe:,
18
22
  temporary_gemfile_path:
19
23
  )
24
+ @only_safe = only_safe
20
25
  @temporary_gemfile_path = temporary_gemfile_path
21
26
  end
22
27
 
23
28
  def call
24
29
  ::Kernel.system(
25
30
  { 'BUNDLE_GEMFILE' => @temporary_gemfile_path },
26
- 'bundle exec rubocop --auto-correct-all'
31
+ "bundle exec rubocop #{rubocop_options}"
27
32
  )
28
33
  end
34
+
35
+ private
36
+
37
+ # @return [String]
38
+ def rubocop_options
39
+ if @only_safe
40
+ '--auto-correct'
41
+ else
42
+ '--auto-correct-all'
43
+ end
44
+ end
29
45
  end
30
46
  end
31
47
  end
@@ -11,8 +11,8 @@ module RubocopTodoCorrector
11
11
  temporary_gemfile_path:
12
12
  )
13
13
  new(
14
- cop_name: cop_name,
15
- temporary_gemfile_path: temporary_gemfile_path
14
+ cop_name:,
15
+ temporary_gemfile_path:
16
16
  ).call
17
17
  end
18
18
  end
@@ -36,9 +36,9 @@ module RubocopTodoCorrector
36
36
  return unless cop_document
37
37
 
38
38
  description = DescriptionRenderer.call(
39
- cop_document: cop_document,
39
+ cop_document:,
40
40
  cop_name: @cop_name,
41
- cop_source_path: cop_source_path
41
+ cop_source_path:
42
42
  )
43
43
  ::Kernel.puts(description)
44
44
  end
@@ -13,8 +13,8 @@ module RubocopTodoCorrector
13
13
  temporary_gemfile_path:
14
14
  )
15
15
  new(
16
- rubocop_todo_path: rubocop_todo_path,
17
- temporary_gemfile_path: temporary_gemfile_path
16
+ rubocop_todo_path:,
17
+ temporary_gemfile_path:
18
18
  ).call
19
19
  end
20
20
  end
@@ -7,23 +7,28 @@ module RubocopTodoCorrector
7
7
  class Pick
8
8
  class << self
9
9
  # @param [String] mode
10
+ # @param [Boolean] only_safe
10
11
  # @param [String] rubocop_todo_path
11
12
  def call(
12
13
  mode:,
14
+ only_safe:,
13
15
  rubocop_todo_path:
14
16
  )
15
17
  new(
16
- mode: mode,
17
- rubocop_todo_path: rubocop_todo_path
18
+ mode:,
19
+ only_safe:,
20
+ rubocop_todo_path:
18
21
  ).call
19
22
  end
20
23
  end
21
24
 
22
25
  def initialize(
23
26
  mode:,
27
+ only_safe:,
24
28
  rubocop_todo_path:
25
29
  )
26
30
  @mode = mode
31
+ @only_safe = only_safe
27
32
  @rubocop_todo_path = rubocop_todo_path
28
33
  end
29
34
 
@@ -42,7 +47,11 @@ module RubocopTodoCorrector
42
47
  # @return [Array<Hash>]
43
48
  def auto_correctable_cops
44
49
  rubocop_todo[:cops].select do |cop|
45
- cop[:auto_correctable]
50
+ if @only_safe
51
+ cop[:safe_auto_correctable]
52
+ else
53
+ cop[:auto_correctable]
54
+ end
46
55
  end
47
56
  end
48
57
 
@@ -13,8 +13,8 @@ module RubocopTodoCorrector
13
13
  rubocop_todo_path:
14
14
  )
15
15
  new(
16
- cop_name: cop_name,
17
- rubocop_todo_path: rubocop_todo_path
16
+ cop_name:,
17
+ rubocop_todo_path:
18
18
  ).call
19
19
  end
20
20
  end
@@ -11,7 +11,7 @@ module RubocopTodoCorrector
11
11
  source_path:
12
12
  )
13
13
  new(
14
- source_path: source_path
14
+ source_path:
15
15
  ).call
16
16
  end
17
17
  end
@@ -13,8 +13,8 @@ module RubocopTodoCorrector
13
13
  temporary_gemfile_path:
14
14
  )
15
15
  new(
16
- cop_name: cop_name,
17
- temporary_gemfile_path: temporary_gemfile_path
16
+ cop_name:,
17
+ temporary_gemfile_path:
18
18
  ).call
19
19
  end
20
20
  end
@@ -17,9 +17,9 @@ module RubocopTodoCorrector
17
17
  cop_source_path:
18
18
  )
19
19
  new(
20
- cop_document: cop_document,
21
- cop_name: cop_name,
22
- cop_source_path: cop_source_path
20
+ cop_document:,
21
+ cop_name:,
22
+ cop_source_path:
23
23
  ).call
24
24
  end
25
25
  end
@@ -8,7 +8,7 @@ module RubocopTodoCorrector
8
8
  # @param [String] rubocop_configuration_path
9
9
  # @return [Array<String>]
10
10
  def call(rubocop_configuration_path:)
11
- new(rubocop_configuration_path: rubocop_configuration_path).call
11
+ new(rubocop_configuration_path:).call
12
12
  end
13
13
  end
14
14
 
@@ -10,8 +10,8 @@ module RubocopTodoCorrector
10
10
  # @return [String, nil]
11
11
  def call(gemfile_lock_path:, gem_name:)
12
12
  new(
13
- gemfile_lock_path: gemfile_lock_path,
14
- gem_name: gem_name
13
+ gemfile_lock_path:,
14
+ gem_name:
15
15
  ).call
16
16
  end
17
17
  end
@@ -16,7 +16,7 @@ module RubocopTodoCorrector
16
16
  # @param [String] content
17
17
  def call(content:)
18
18
  new(
19
- content: content
19
+ content:
20
20
  ).call
21
21
  end
22
22
  end
@@ -28,8 +28,8 @@ module RubocopTodoCorrector
28
28
  # @return [Hash]
29
29
  def call
30
30
  {
31
- cops: cops,
32
- previous_rubocop_command: previous_rubocop_command
31
+ cops:,
32
+ previous_rubocop_command:
33
33
  }
34
34
  end
35
35
 
@@ -6,7 +6,7 @@ module RubocopTodoCorrector
6
6
  # @param [String] content
7
7
  def call(content:)
8
8
  new(
9
- content: content
9
+ content:
10
10
  ).call
11
11
  end
12
12
  end
@@ -18,19 +18,18 @@ module RubocopTodoCorrector
18
18
  # @return [Hash]
19
19
  def call
20
20
  {
21
- auto_correctable: auto_correctable?,
22
- name: name,
23
- offenses_count: offenses_count
21
+ auto_correctable:,
22
+ name:,
23
+ offenses_count:,
24
+ safe_auto_correctable:
24
25
  }
25
26
  end
26
27
 
27
28
  private
28
29
 
29
30
  # @return [Boolean]
30
- def auto_correctable?
31
- @content.include?('# Cop supports --auto-correct') ||
32
- @content.include?('# This cop supports safe auto-correction') ||
33
- @content.include?('# This cop supports unsafe auto-correction')
31
+ def auto_correctable
32
+ safe_auto_correctable || unsafe_auto_correctable
34
33
  end
35
34
 
36
35
  # @return [String, nil]
@@ -45,5 +44,17 @@ module RubocopTodoCorrector
45
44
  'offenses_count'
46
45
  ]&.to_i
47
46
  end
47
+
48
+ def safe_auto_correctable
49
+ @content.include?('# Cop supports --auto-correct.') || # Before rubocop 1.26
50
+ @content.include?('# This cop supports safe auto-correction') || # Before rubocop 1.30
51
+ @content.include?('# This cop supports safe autocorrection')
52
+ end
53
+
54
+ def unsafe_auto_correctable
55
+ @content.include?('# Cop supports --auto-correct-all') ||
56
+ @content.include?('# This cop supports unsafe auto-correction') ||
57
+ @content.include?('# This cop supports unsafe autocorrection')
58
+ end
48
59
  end
49
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopTodoCorrector
4
- VERSION = '0.4.0'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = 'Auto-correct offenses defined in .rubocop_todo.yml.'
12
12
  spec.homepage = 'https://github.com/r7kamura/rubocop_todo_corrector'
13
13
  spec.license = 'MIT'
14
- spec.required_ruby_version = '>= 3.0'
14
+ spec.required_ruby_version = '>= 3.1'
15
15
 
16
16
  spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = spec.homepage
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop_todo_corrector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-15 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '3.0'
109
+ version: '3.1'
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="