rubocop_todo_corrector 0.8.0 → 0.11.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: 86fbfcf2dc8bc54f4a72ce5c802c55063ca925e55174bdcc56ca9194fb9bade1
4
- data.tar.gz: 7e95e96cbdffea5a2e8706fc496218a8f00288255a7cd32015a55589922cd642
3
+ metadata.gz: 1a5761497cb2e78d59de2fed8ce2abc7edd84bc318f6d70483ea1f4f9363a4a4
4
+ data.tar.gz: 1f310cfb7f1479f454914e3cbe1e40b065851c4e6978b484f2d617cd69df7d6c
5
5
  SHA512:
6
- metadata.gz: b1baced0e45b00f3419ec85125d023737d1ca33af3ae642f175bcba37b275c517050f283974b63291ab432683a45fbb891f9a961ea17cc4fa86e825d9bf35654
7
- data.tar.gz: 807219d3418b38e8383e40b557ccc93b1e685d6011c669407bab48364eabd3d3bd9f0efa35319b50ee7055e4af798f73b4d4b1ad09a76495bedcb5e9d04c2e84
6
+ metadata.gz: 227d12206f9b090ba98cae89ac3e960c1f6e1d61a8bcffe501c093ccffca1dd68b7121659977bc7835f1270994c3f63914f0e14bcd5cd040b66d699926339620
7
+ data.tar.gz: d88f4a1733519d7e0f5659ae62474bd0c37c2b06d0284b64fdd94d3a210ac99655a666ce3ab8bdb67cce6118c7f57edcaba7f83cb5de13e52a30523c4b9957b7
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.11.0 - 2022-07-29
6
+
7
+ ### Changed
8
+
9
+ - Use `rubocop --regenerate-todo` option on `generate` command.
10
+
11
+ ## 0.10.0 - 2022-07-27
12
+
13
+ ### Added
14
+
15
+ - Add `ignore` command.
16
+
17
+ ## 0.9.0 - 2022-07-27
18
+
19
+ ### Added
20
+
21
+ - Add `.rubocop_todo_corrector_ignore` file support.
22
+
5
23
  ## 0.8.0 - 2022-07-23
6
24
 
7
25
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop_todo_corrector (0.8.0)
4
+ rubocop_todo_corrector (0.11.0)
5
5
  bundler
6
6
  thor
7
7
  yard
data/README.md CHANGED
@@ -26,96 +26,24 @@ $ rubocop_todo_corrector
26
26
  Commands:
27
27
  rubocop_todo_corrector bundle # Run `bundle install` to install RuboCop related gems.
28
28
  rubocop_todo_corrector clean # Remove temporary files.
29
- rubocop_todo_corrector correct # Run `rubocop --auto-correct-all`.
29
+ rubocop_todo_corrector correct # Run `rubocop --auto-correct(-all)`.
30
30
  rubocop_todo_corrector describe --cop-name=COP_NAME # Output Markdown description for specified cop.
31
31
  rubocop_todo_corrector generate # Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
32
32
  rubocop_todo_corrector help [COMMAND] # Describe available commands or one specific command
33
+ rubocop_todo_corrector ignore --cop-name=COP_NAME # Ignore specified cop by appending it to ignore file.
33
34
  rubocop_todo_corrector pick # Output an auto-correctable Cop from .rubocop_todo.yml.
34
35
  rubocop_todo_corrector remove --cop-name=COP_NAME # Remove section with specified cop name from .rubocop_todo.yml.
35
36
  ```
36
37
 
37
- ### bundle
38
+ ### .rubocop_todo_corrector_ignore
38
39
 
39
- ```console
40
- $ rubocop_todo_corrector help bundle
41
- Usage:
42
- rubocop_todo_corrector bundle
43
-
44
- Run `bundle install` to install RuboCop related gems.
45
- ```
46
-
47
- ### Clean
48
-
49
- ```console
50
- $ rubocop_todo_corrector help clean
51
- Usage:
52
- rubocop_todo_corrector clean
53
-
54
- Remove temporary files.
55
- ```
56
-
57
- ### correct
58
-
59
- ```console
60
- Usage:
61
- rubocop_todo_corrector correct
62
-
63
- Options:
64
- [--only-safe], [--no-only-safe]
65
- # Default: true
66
-
67
- Run `rubocop --auto-correct(-all)`.
68
- ```
69
-
70
- ### describe
71
-
72
- ```console
73
- $ rubocop_todo_corrector help describe
74
- Usage:
75
- rubocop_todo_corrector describe --cop-name=COP_NAME
76
-
77
- Options:
78
- --cop-name=COP_NAME
79
-
80
- Output Markdown description for specified cop.
81
- ```
40
+ By specifying cop names in `.rubocop_todo_corrector_ignore`, you can exclude them from the selection.
82
41
 
83
- ### generate
84
-
85
- ```console
86
- $ rubocop_todo_corrector help generate
87
- Usage:
88
- rubocop_todo_corrector generate
89
-
90
- Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
91
42
  ```
43
+ Style/StringConcatenation
92
44
 
93
- ### pick
94
-
95
- ```console
96
- $ rubocop_todo_corrector help pick
97
- Usage:
98
- rubocop_todo_corrector pick
99
-
100
- Options:
101
- [--mode=MODE]
102
- # Default: random
103
- # Possible values: first, last, least_occurred, most_occurred, random
104
- [--only-safe], [--no-only-safe]
105
- # Default: true
106
-
107
- Output an auto-correctable Cop from .rubocop_todo.yml.
45
+ # Comment line is available like this.
46
+ Style/StringLiterals
108
47
  ```
109
48
 
110
- ### remove
111
-
112
- ```console
113
- $ rubocop_todo_corrector help remove
114
- Usage:
115
- rubocop_todo_corrector remove --cop-name=COP_NAME
116
-
117
- Options:
118
- --cop-name=COP_NAME
119
-
120
- Remove section with specified cop name from .rubocop_todo.yml.
121
- ```
49
+ This is useful, for example, when you find a cop that cannot be autocorrected.
@@ -55,6 +55,19 @@ module RubocopTodoCorrector
55
55
  )
56
56
  end
57
57
 
58
+ desc 'ignore', 'Ignore specified cop by appending it to ignore file.'
59
+ option(
60
+ :cop_name,
61
+ type: :string,
62
+ required: true
63
+ )
64
+ def ignore
65
+ Commands::Ignore.call(
66
+ ignore_file_path: '.rubocop_todo_corrector_ignore',
67
+ cop_name: options[:cop_name]
68
+ )
69
+ end
70
+
58
71
  desc 'pick', 'Output an auto-correctable Cop from .rubocop_todo.yml.'
59
72
  option(
60
73
  :mode,
@@ -75,6 +88,7 @@ module RubocopTodoCorrector
75
88
  )
76
89
  def pick
77
90
  Commands::Pick.call(
91
+ ignore_file_path: '.rubocop_todo_corrector_ignore',
78
92
  mode: options[:mode],
79
93
  only_safe: options[:only_safe],
80
94
  rubocop_todo_path: '.rubocop_todo.yml'
@@ -30,33 +30,9 @@ module RubocopTodoCorrector
30
30
  def call
31
31
  ::Kernel.system(
32
32
  { 'BUNDLE_GEMFILE' => @temporary_gemfile_path },
33
- "bundle exec #{rubocop_command}"
33
+ 'bundle exec rubocop --regenerate-todo'
34
34
  )
35
35
  end
36
-
37
- private
38
-
39
- # @return [String]
40
- def rubocop_command
41
- rubocop_command_from_todo || 'rubocop --auto-gen-config'
42
- end
43
-
44
- # @return [String, nil]
45
- def rubocop_command_from_todo
46
- return unless rubocop_todo_pathname.exist?
47
-
48
- RubocopTodoParser.call(content: rubocop_todo_content)[:previous_rubocop_command]
49
- end
50
-
51
- # @return [String]
52
- def rubocop_todo_content
53
- rubocop_todo_pathname.read
54
- end
55
-
56
- # @return [Pathname]
57
- def rubocop_todo_pathname
58
- @rubocop_todo_pathname ||= ::Pathname.new(@rubocop_todo_path)
59
- end
60
36
  end
61
37
  end
62
38
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module RubocopTodoCorrector
6
+ module Commands
7
+ class Ignore
8
+ class << self
9
+ # @param [String] cop_name
10
+ # @param [String] ignore_file_path
11
+ def call(
12
+ cop_name:,
13
+ ignore_file_path:
14
+ )
15
+ new(
16
+ cop_name:,
17
+ ignore_file_path:
18
+ ).call
19
+ end
20
+ end
21
+
22
+ def initialize(
23
+ cop_name:,
24
+ ignore_file_path:
25
+ )
26
+ @cop_name = cop_name
27
+ @ignore_file_path = ignore_file_path
28
+ end
29
+
30
+ def call
31
+ IgnoreFile.new(path: @ignore_file_path).append_cop_name(@cop_name)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pathname'
4
+ require 'set'
4
5
 
5
6
  module RubocopTodoCorrector
6
7
  module Commands
7
8
  class Pick
8
9
  class << self
10
+ # @param [String] ignore_file_path
9
11
  # @param [String] mode
10
12
  # @param [Boolean] only_safe
11
13
  # @param [String] rubocop_todo_path
12
14
  def call(
15
+ ignore_file_path:,
13
16
  mode:,
14
17
  only_safe:,
15
18
  rubocop_todo_path:
16
19
  )
17
20
  new(
21
+ ignore_file_path:,
18
22
  mode:,
19
23
  only_safe:,
20
24
  rubocop_todo_path:
@@ -23,10 +27,12 @@ module RubocopTodoCorrector
23
27
  end
24
28
 
25
29
  def initialize(
30
+ ignore_file_path:,
26
31
  mode:,
27
32
  only_safe:,
28
33
  rubocop_todo_path:
29
34
  )
35
+ @ignore_file_path = ignore_file_path
30
36
  @mode = mode
31
37
  @only_safe = only_safe
32
38
  @rubocop_todo_path = rubocop_todo_path
@@ -59,23 +65,37 @@ module RubocopTodoCorrector
59
65
  raise "#{rubocop_todo_pathname.to_s.inspect} does not exist." unless rubocop_todo_pathname.exist?
60
66
  end
61
67
 
68
+ # @return [Set<String>]
69
+ def ignored_cop_names
70
+ @ignored_cop_names ||= IgnoreFile.new(
71
+ path: @ignore_file_path
72
+ ).ignored_cop_names.to_set
73
+ end
74
+
75
+ # @return [Array<Hash>]
76
+ def pickable_cops
77
+ auto_correctable_cops.reject do |cop|
78
+ ignored_cop_names.include?(cop[:name])
79
+ end
80
+ end
81
+
62
82
  # @return [Hash, nil]
63
83
  def picked_cop
64
84
  case @mode
65
85
  when 'first'
66
- auto_correctable_cops.first
86
+ pickable_cops.first
67
87
  when 'last'
68
- auto_correctable_cops.last
88
+ pickable_cops.last
69
89
  when 'least_occurred'
70
- auto_correctable_cops.min_by do |cop|
90
+ pickable_cops.min_by do |cop|
71
91
  cop[:offenses_count]
72
92
  end
73
93
  when 'most_occurred'
74
- auto_correctable_cops.max_by do |cop|
94
+ pickable_cops.max_by do |cop|
75
95
  cop[:offenses_count]
76
96
  end
77
97
  else
78
- auto_correctable_cops.sample
98
+ pickable_cops.sample
79
99
  end
80
100
  end
81
101
 
@@ -7,6 +7,7 @@ module RubocopTodoCorrector
7
7
  autoload :Correct, 'rubocop_todo_corrector/commands/correct'
8
8
  autoload :Describe, 'rubocop_todo_corrector/commands/describe'
9
9
  autoload :Generate, 'rubocop_todo_corrector/commands/generate'
10
+ autoload :Ignore, 'rubocop_todo_corrector/commands/ignore'
10
11
  autoload :Pick, 'rubocop_todo_corrector/commands/pick'
11
12
  autoload :Remove, 'rubocop_todo_corrector/commands/remove'
12
13
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module RubocopTodoCorrector
6
+ class IgnoreFile
7
+ # @param [String] path
8
+ def initialize(path:)
9
+ @path = path
10
+ end
11
+
12
+ # @param [String] cop_name
13
+ def append_cop_name(cop_name)
14
+ return if include?(cop_name)
15
+
16
+ appendix = "#{cop_name}\n"
17
+ appendix.prepend("\n") if !content.empty? && !content.end_with?("\n")
18
+ pathname.write("#{content}#{appendix}")
19
+ end
20
+
21
+ # @return [Array<String>]
22
+ def ignored_cop_names
23
+ content.split("\n").map do |line|
24
+ line.sub(/#.+/, '').strip
25
+ end.reject(&:empty?)
26
+ end
27
+
28
+ private
29
+
30
+ # @return [String]
31
+ def content
32
+ if pathname.exist?
33
+ pathname.read
34
+ else
35
+ ''
36
+ end
37
+ end
38
+
39
+ # @param [String] cop_name
40
+ # @return [Boolean]
41
+ def include?(cop_name)
42
+ ignored_cop_names.include?(cop_name)
43
+ end
44
+
45
+ # @return [Pathname]
46
+ def pathname
47
+ @pathname ||= ::Pathname.new(@path)
48
+ end
49
+ end
50
+ end
@@ -27,10 +27,7 @@ module RubocopTodoCorrector
27
27
 
28
28
  # @return [Hash]
29
29
  def call
30
- {
31
- cops:,
32
- previous_rubocop_command:
33
- }
30
+ { cops: }
34
31
  end
35
32
 
36
33
  private
@@ -42,13 +39,6 @@ module RubocopTodoCorrector
42
39
  end
43
40
  end
44
41
 
45
- def previous_rubocop_command
46
- @content[
47
- /`(.+)`/,
48
- 1
49
- ]
50
- end
51
-
52
42
  # @return [Array<String>]
53
43
  def cop_sections
54
44
  @content.split("\n\n").grep(COP_NAME_LINE_REGEXP)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopTodoCorrector
4
- VERSION = '0.8.0'
4
+ VERSION = '0.11.0'
5
5
  end
@@ -11,6 +11,7 @@ module RubocopTodoCorrector
11
11
  autoload :DescriptionRenderer, 'rubocop_todo_corrector/description_renderer'
12
12
  autoload :GemNamesDetector, 'rubocop_todo_corrector/gem_names_detector'
13
13
  autoload :GemVersionDetector, 'rubocop_todo_corrector/gem_version_detector'
14
+ autoload :IgnoreFile, 'rubocop_todo_corrector/ignore_file'
14
15
  autoload :RubocopTodoParser, 'rubocop_todo_corrector/rubocop_todo_parser'
15
16
  autoload :RubocopTodoSectionParser, 'rubocop_todo_corrector/rubocop_todo_section_parser'
16
17
  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.8.0
4
+ version: 0.11.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-07-23 00:00:00.000000000 Z
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,6 +79,7 @@ files:
79
79
  - lib/rubocop_todo_corrector/commands/correct.rb
80
80
  - lib/rubocop_todo_corrector/commands/describe.rb
81
81
  - lib/rubocop_todo_corrector/commands/generate.rb
82
+ - lib/rubocop_todo_corrector/commands/ignore.rb
82
83
  - lib/rubocop_todo_corrector/commands/pick.rb
83
84
  - lib/rubocop_todo_corrector/commands/remove.rb
84
85
  - lib/rubocop_todo_corrector/cop_document_parser.rb
@@ -86,6 +87,7 @@ files:
86
87
  - lib/rubocop_todo_corrector/description_renderer.rb
87
88
  - lib/rubocop_todo_corrector/gem_names_detector.rb
88
89
  - lib/rubocop_todo_corrector/gem_version_detector.rb
90
+ - lib/rubocop_todo_corrector/ignore_file.rb
89
91
  - lib/rubocop_todo_corrector/rubocop_todo_parser.rb
90
92
  - lib/rubocop_todo_corrector/rubocop_todo_section_parser.rb
91
93
  - lib/rubocop_todo_corrector/version.rb