rubocop_todo_corrector 0.5.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: 0f41cc52c87afb8d1971ed4dbf006acd3471c42183e3c9947e588870a6bff7f3
4
- data.tar.gz: dba2c971d07471a2b2da8b76eaf6ae1b8a27cde13698a116a97c7edfab2cdeb6
3
+ metadata.gz: a16c0718e0411c212efc6aa1a070df5c0784c415b3ae25b47686c35d4a37f196
4
+ data.tar.gz: 38c4affee6edb3e6569a64df3d4b410522de4fee23c7f3849bbf9b7ccb1e67d9
5
5
  SHA512:
6
- metadata.gz: 455f57a51dbd813148f3fde5d6c00f813e0edc47e2d5644b53efbe2bd3dda354fc4b6c52e952ca33b214309dc97ffe33a47f20fb5137759b224dcb4743fd11f5
7
- data.tar.gz: 5d47b50b46c2fb7d79488ba0ef66bef0050483bb9c82ae346159ae69ba6b6e7145e2520658e41a914996e9d6bb6a17e4f125b1ce758c385326305cb8d6f8f2df
6
+ metadata.gz: a31400bdfed79ab2ed935347885b40bae95956dec916b42dfb001b09507443ed3275cb003402bd427f73bd401006783360916c8f2de20e2382d5dbed18f70720
7
+ data.tar.gz: 8db623bd95d0f3c942df88e1ac720c296305c0f8b2b88371993906cc522253d1159a49c2bc8ac0e3c803c09d672804da908a2970b8d707f22d780ea81a291864
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
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
+
5
11
  ## 0.5.0 - 2022-05-16
6
12
 
7
13
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop_todo_corrector (0.5.0)
4
+ rubocop_todo_corrector (0.6.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
  ```
@@ -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
@@ -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(
14
+ only_safe:,
12
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
@@ -7,13 +7,16 @@ 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
18
  mode:,
19
+ only_safe:,
17
20
  rubocop_todo_path:
18
21
  ).call
19
22
  end
@@ -21,9 +24,11 @@ module RubocopTodoCorrector
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
 
@@ -18,19 +18,18 @@ module RubocopTodoCorrector
18
18
  # @return [Hash]
19
19
  def call
20
20
  {
21
- auto_correctable: auto_correctable?,
21
+ auto_correctable:,
22
22
  name:,
23
- offenses_count:
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.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
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.5.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