rubocop_todo_corrector 0.8.0 → 0.9.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: 86fbfcf2dc8bc54f4a72ce5c802c55063ca925e55174bdcc56ca9194fb9bade1
4
- data.tar.gz: 7e95e96cbdffea5a2e8706fc496218a8f00288255a7cd32015a55589922cd642
3
+ metadata.gz: 61752242b12ed25751b22323c3c0d177acefa0d89a23146607c126c3382921e7
4
+ data.tar.gz: be9d3d0f9c9428bdf7e2967a293dffe199539ea8a071545b0cbb4d914e1854c5
5
5
  SHA512:
6
- metadata.gz: b1baced0e45b00f3419ec85125d023737d1ca33af3ae642f175bcba37b275c517050f283974b63291ab432683a45fbb891f9a961ea17cc4fa86e825d9bf35654
7
- data.tar.gz: 807219d3418b38e8383e40b557ccc93b1e685d6011c669407bab48364eabd3d3bd9f0efa35319b50ee7055e4af798f73b4d4b1ad09a76495bedcb5e9d04c2e84
6
+ metadata.gz: 15a1cb26be0f48eca2430c827985be3eb9426684c9123a23d8f1d7f2c379cd56fda991edf58e6e25b58f65fd769919c20cad8ac9292b9c3a7576d272bc0b29e4
7
+ data.tar.gz: 3506ce4ca3b8fc368c79bd90ab6b18eb6cdabb35d6364891fc928917a5f232904cd020885915d0b2245fd720fe116f57ea7746759a9ca30b84051cc2a89e0cb3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.9.0 - 2022-07-27
6
+
7
+ ### Added
8
+
9
+ - Add `.rubocop_todo_corrector_ignore` file support.
10
+
5
11
  ## 0.8.0 - 2022-07-23
6
12
 
7
13
  ### 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.9.0)
5
5
  bundler
6
6
  thor
7
7
  yard
data/README.md CHANGED
@@ -34,88 +34,13 @@ Commands:
34
34
  rubocop_todo_corrector remove --cop-name=COP_NAME # Remove section with specified cop name from .rubocop_todo.yml.
35
35
  ```
36
36
 
37
- ### bundle
37
+ ### .rubocop_todo_corrector_ignore
38
38
 
39
- ```console
40
- $ rubocop_todo_corrector help bundle
41
- Usage:
42
- rubocop_todo_corrector bundle
39
+ By specifying cop names in `.rubocop_todo_corrector_ignore`, you can exclude them from the selection.
43
40
 
44
- Run `bundle install` to install RuboCop related gems.
45
41
  ```
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.
42
+ Style/StringConcatenation
43
+ Style/StringLiterals
81
44
  ```
82
45
 
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
- ```
92
-
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.
108
- ```
109
-
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
- ```
46
+ This is useful, for example, when you find a cop that cannot be autocorrected.
@@ -75,6 +75,7 @@ module RubocopTodoCorrector
75
75
  )
76
76
  def pick
77
77
  Commands::Pick.call(
78
+ ignore_file_path: '.rubocop_todo_corrector_ignore',
78
79
  mode: options[:mode],
79
80
  only_safe: options[:only_safe],
80
81
  rubocop_todo_path: '.rubocop_todo.yml'
@@ -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
 
@@ -0,0 +1,35 @@
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
+ # @return [Array<String>]
13
+ def ignored_cop_names
14
+ content.split("\n").map do |line|
15
+ line.sub(/#.+/, '').strip
16
+ end.reject(&:empty?)
17
+ end
18
+
19
+ private
20
+
21
+ # @return [String]
22
+ def content
23
+ if pathname.exist?
24
+ pathname.read
25
+ else
26
+ ''
27
+ end
28
+ end
29
+
30
+ # @return [Pathname]
31
+ def pathname
32
+ @pathname ||= ::Pathname.new(@path)
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopTodoCorrector
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.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.9.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-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - lib/rubocop_todo_corrector/description_renderer.rb
87
87
  - lib/rubocop_todo_corrector/gem_names_detector.rb
88
88
  - lib/rubocop_todo_corrector/gem_version_detector.rb
89
+ - lib/rubocop_todo_corrector/ignore_file.rb
89
90
  - lib/rubocop_todo_corrector/rubocop_todo_parser.rb
90
91
  - lib/rubocop_todo_corrector/rubocop_todo_section_parser.rb
91
92
  - lib/rubocop_todo_corrector/version.rb