rubocop_todo_corrector 0.7.0 → 0.9.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: f837600adefd9711b9b73eca485464781dcf9ba2bbf14bc2aec2f899c92c8ee5
4
- data.tar.gz: cafef555598fc0f848bc739317fb3f9d507b227520f86f9fa4ffa1cc5d631b17
3
+ metadata.gz: 61752242b12ed25751b22323c3c0d177acefa0d89a23146607c126c3382921e7
4
+ data.tar.gz: be9d3d0f9c9428bdf7e2967a293dffe199539ea8a071545b0cbb4d914e1854c5
5
5
  SHA512:
6
- metadata.gz: 3f0a064fa54502df60aba17ed32103b55f741704336a4fe2040c9478f5925b5bb2116bbf684fb3f2e8d64e9124408302185a1070f50fadc619a864010b2d45d6
7
- data.tar.gz: 42479c0a9828bfed5899f1cfb3e1f5dbb847330f09aeda1a12126f62af3b8634879fca8177e955ba098c73d56702ec4d52cb983348892217fdc5907dc567f6cd
6
+ metadata.gz: 15a1cb26be0f48eca2430c827985be3eb9426684c9123a23d8f1d7f2c379cd56fda991edf58e6e25b58f65fd769919c20cad8ac9292b9c3a7576d272bc0b29e4
7
+ data.tar.gz: 3506ce4ca3b8fc368c79bd90ab6b18eb6cdabb35d6364891fc928917a5f232904cd020885915d0b2245fd720fe116f57ea7746759a9ca30b84051cc2a89e0cb3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
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
+
11
+ ## 0.8.0 - 2022-07-23
12
+
13
+ ### Added
14
+
15
+ - Add `clean` command.
16
+
17
+ ## 0.7.1 - 2022-05-28
18
+
19
+ ### Fixed
20
+
21
+ - Fix YARD unknown tag warning.
22
+
5
23
  ## 0.7.0 - 2022-05-27
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.7.0)
4
+ rubocop_todo_corrector (0.9.0)
5
5
  bundler
6
6
  thor
7
7
  yard
@@ -50,7 +50,7 @@ GEM
50
50
  thor (1.2.1)
51
51
  unicode-display_width (2.1.0)
52
52
  webrick (1.7.0)
53
- yard (0.9.27)
53
+ yard (0.9.28)
54
54
  webrick (~> 1.7.0)
55
55
 
56
56
  PLATFORMS
data/README.md CHANGED
@@ -25,6 +25,7 @@ gem install rubocop_todo_corrector
25
25
  $ rubocop_todo_corrector
26
26
  Commands:
27
27
  rubocop_todo_corrector bundle # Run `bundle install` to install RuboCop related gems.
28
+ rubocop_todo_corrector clean # Remove temporary files.
28
29
  rubocop_todo_corrector correct # Run `rubocop --auto-correct-all`.
29
30
  rubocop_todo_corrector describe --cop-name=COP_NAME # Output Markdown description for specified cop.
30
31
  rubocop_todo_corrector generate # Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
@@ -33,78 +34,13 @@ Commands:
33
34
  rubocop_todo_corrector remove --cop-name=COP_NAME # Remove section with specified cop name from .rubocop_todo.yml.
34
35
  ```
35
36
 
36
- ### bundle
37
+ ### .rubocop_todo_corrector_ignore
37
38
 
38
- ```console
39
- $ rubocop_todo_corrector help bundle
40
- Usage:
41
- rubocop_todo_corrector bundle
42
-
43
- Run `bundle install` to install RuboCop related gems.
44
- ```
45
-
46
- ### correct
47
-
48
- ```console
49
- Usage:
50
- rubocop_todo_corrector correct
51
-
52
- Options:
53
- [--only-safe], [--no-only-safe]
54
- # Default: true
55
-
56
- Run `rubocop --auto-correct(-all)`.
57
- ```
58
-
59
- ### describe
60
-
61
- ```console
62
- $ rubocop_todo_corrector help describe
63
- Usage:
64
- rubocop_todo_corrector describe --cop-name=COP_NAME
65
-
66
- Options:
67
- --cop-name=COP_NAME
68
-
69
- Output Markdown description for specified cop.
70
- ```
71
-
72
- ### generate
73
-
74
- ```console
75
- $ rubocop_todo_corrector help generate
76
- Usage:
77
- rubocop_todo_corrector generate
39
+ By specifying cop names in `.rubocop_todo_corrector_ignore`, you can exclude them from the selection.
78
40
 
79
- Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
80
41
  ```
81
-
82
- ### pick
83
-
84
- ```console
85
- $ rubocop_todo_corrector help pick
86
- Usage:
87
- rubocop_todo_corrector pick
88
-
89
- Options:
90
- [--mode=MODE]
91
- # Default: random
92
- # Possible values: first, last, least_occurred, most_occurred, random
93
- [--only-safe], [--no-only-safe]
94
- # Default: true
95
-
96
- Output an auto-correctable Cop from .rubocop_todo.yml.
42
+ Style/StringConcatenation
43
+ Style/StringLiterals
97
44
  ```
98
45
 
99
- ### remove
100
-
101
- ```console
102
- $ rubocop_todo_corrector help remove
103
- Usage:
104
- rubocop_todo_corrector remove --cop-name=COP_NAME
105
-
106
- Options:
107
- --cop-name=COP_NAME
108
-
109
- Remove section with specified cop name from .rubocop_todo.yml.
110
- ```
46
+ This is useful, for example, when you find a cop that cannot be autocorrected.
@@ -14,6 +14,13 @@ module RubocopTodoCorrector
14
14
  )
15
15
  end
16
16
 
17
+ desc 'clean', 'Remove temporary files.'
18
+ def clean
19
+ Commands::Clean.call(
20
+ temporary_gemfile_path: 'tmp/Gemfile_rubocop_todo_corrector.rb'
21
+ )
22
+ end
23
+
17
24
  desc 'correct', 'Run `rubocop --auto-correct(-all)`.'
18
25
  option(
19
26
  :only_safe,
@@ -68,6 +75,7 @@ module RubocopTodoCorrector
68
75
  )
69
76
  def pick
70
77
  Commands::Pick.call(
78
+ ignore_file_path: '.rubocop_todo_corrector_ignore',
71
79
  mode: options[:mode],
72
80
  only_safe: options[:only_safe],
73
81
  rubocop_todo_path: '.rubocop_todo.yml'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module RubocopTodoCorrector
6
+ module Commands
7
+ class Clean
8
+ class << self
9
+ # @param [String] temporary_gemfile_path
10
+ def call(
11
+ temporary_gemfile_path:
12
+ )
13
+ new(
14
+ temporary_gemfile_path:
15
+ ).call
16
+ end
17
+ end
18
+
19
+ def initialize(
20
+ temporary_gemfile_path:
21
+ )
22
+ @temporary_gemfile_path = temporary_gemfile_path
23
+ end
24
+
25
+ def call
26
+ ::FileUtils.rm_f(
27
+ [
28
+ @temporary_gemfile_path,
29
+ "#{@temporary_gemfile_path}.lock"
30
+ ]
31
+ )
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
 
@@ -3,6 +3,7 @@
3
3
  module RubocopTodoCorrector
4
4
  module Commands
5
5
  autoload :Bundle, 'rubocop_todo_corrector/commands/bundle'
6
+ autoload :Clean, 'rubocop_todo_corrector/commands/clean'
6
7
  autoload :Correct, 'rubocop_todo_corrector/commands/correct'
7
8
  autoload :Describe, 'rubocop_todo_corrector/commands/describe'
8
9
  autoload :Generate, 'rubocop_todo_corrector/commands/generate'
@@ -42,6 +42,7 @@ module RubocopTodoCorrector
42
42
  # @return [YARD::CodeObjects::ClassObject]
43
43
  def yard_class_object
44
44
  @yard_class_object ||= begin
45
+ ::YARD::Tags::Library.define_tag('Cop Safety Information', :safety)
45
46
  ::YARD.parse(@source_path)
46
47
  yardoc = ::YARD::Registry.all(:class).first
47
48
  ::YARD::Registry.clear
@@ -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.7.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.7.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-05-26 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
@@ -75,6 +75,7 @@ files:
75
75
  - lib/rubocop_todo_corrector/cli.rb
76
76
  - lib/rubocop_todo_corrector/commands.rb
77
77
  - lib/rubocop_todo_corrector/commands/bundle.rb
78
+ - lib/rubocop_todo_corrector/commands/clean.rb
78
79
  - lib/rubocop_todo_corrector/commands/correct.rb
79
80
  - lib/rubocop_todo_corrector/commands/describe.rb
80
81
  - lib/rubocop_todo_corrector/commands/generate.rb
@@ -85,6 +86,7 @@ files:
85
86
  - lib/rubocop_todo_corrector/description_renderer.rb
86
87
  - lib/rubocop_todo_corrector/gem_names_detector.rb
87
88
  - lib/rubocop_todo_corrector/gem_version_detector.rb
89
+ - lib/rubocop_todo_corrector/ignore_file.rb
88
90
  - lib/rubocop_todo_corrector/rubocop_todo_parser.rb
89
91
  - lib/rubocop_todo_corrector/rubocop_todo_section_parser.rb
90
92
  - lib/rubocop_todo_corrector/version.rb