rubocop_todo_corrector 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff46eb10969e63064eaf439a4879103de5ea54ae8db44c7c185cb939e3d4b2fd
4
- data.tar.gz: d1b4762bf9bdf6c98fb76311c5389b0175f39434c0f0ccfe8dc8ea4dcbecc3c3
3
+ metadata.gz: a16c0718e0411c212efc6aa1a070df5c0784c415b3ae25b47686c35d4a37f196
4
+ data.tar.gz: 38c4affee6edb3e6569a64df3d4b410522de4fee23c7f3849bbf9b7ccb1e67d9
5
5
  SHA512:
6
- metadata.gz: 6290910045e5aa18a0c7e5689949836f687fb4d7fcd765769450d5a4c33d63476b99d9f2687be6bac7720cf13cc777b400e913f2f41d17a3fefc866eb70d6829
7
- data.tar.gz: d739558dfa006d7110f36b9289505911cabbe9c500c00fb990781d04a9856a25db11910c1eae0fc9a8145e1e45955784b8a05f0706af710b106e4a35d5ba409a
6
+ metadata.gz: a31400bdfed79ab2ed935347885b40bae95956dec916b42dfb001b09507443ed3275cb003402bd427f73bd401006783360916c8f2de20e2382d5dbed18f70720
7
+ data.tar.gz: 8db623bd95d0f3c942df88e1ac720c296305c0f8b2b88371993906cc522253d1159a49c2bc8ac0e3c803c09d672804da908a2970b8d707f22d780ea81a291864
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.6.0 - 2022-05-16
6
+
7
+ ### Added
8
+
9
+ - Add `--only-safe` option to `correct` and `pick` command (default: `true`).
10
+
11
+ ## 0.5.0 - 2022-05-16
12
+
13
+ ### Changed
14
+
15
+ - Change required ruby version from 3.0 to 3.1.
16
+
17
+ ## 0.4.0 - 2022-05-16
18
+
19
+ ### Fixed
20
+
21
+ - Fix misspell: `occured` -> `occurred`.
22
+
5
23
  ## 0.3.0 - 2022-05-15
6
24
 
7
25
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop_todo_corrector (0.3.0)
4
+ rubocop_todo_corrector (0.6.0)
5
5
  bundler
6
6
  thor
7
7
  yard
@@ -54,6 +54,7 @@ GEM
54
54
  webrick (~> 1.7.0)
55
55
 
56
56
  PLATFORMS
57
+ x86_64-darwin-21
57
58
  x86_64-linux
58
59
 
59
60
  DEPENDENCIES
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_occured, most_occured, 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,22 +48,28 @@ 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',
49
55
  enum: %w[
50
56
  first
51
57
  last
52
- least_occured
53
- most_occured
58
+ least_occurred
59
+ most_occurred
54
60
  random
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
 
@@ -57,11 +66,11 @@ module RubocopTodoCorrector
57
66
  auto_correctable_cops.first
58
67
  when 'last'
59
68
  auto_correctable_cops.last
60
- when 'least_occured'
69
+ when 'least_occurred'
61
70
  auto_correctable_cops.min_by do |cop|
62
71
  cop[:offenses_count]
63
72
  end
64
- when 'most_occured'
73
+ when 'most_occurred'
65
74
  auto_correctable_cops.max_by do |cop|
66
75
  cop[:offenses_count]
67
76
  end
@@ -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_corectable
34
33
  end
35
34
 
36
35
  # @return [String, nil]
@@ -45,5 +44,15 @@ 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.') ||
50
+ @content.include?('# This cop supports safe auto-correction')
51
+ end
52
+
53
+ def unsafe_auto_corectable
54
+ @content.include?('# Cop supports --auto-correct-all') ||
55
+ @content.include?('# This cop supports unsafe auto-correction')
56
+ end
48
57
  end
49
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopTodoCorrector
4
- VERSION = '0.3.0'
4
+ VERSION = '0.6.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.3.0
4
+ version: 0.6.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-16 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
  - - ">="