rubocop_todo_corrector 0.7.1 → 0.10.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: 78ebb6430a735647bdf5174b57e594385e52238e041622590771e0fe433b725f
4
- data.tar.gz: d8bba18c545e8cae9ef03d271d432df33277e2c7ba92d578139d9425dd10cdc4
3
+ metadata.gz: e0b057086a834c7f6ec21014fae505b444094e01bc4556e47e91c81f387e3239
4
+ data.tar.gz: 8a56da11f2c70a840097588e539512e06edede97ba9fe185fd8df05096fa734f
5
5
  SHA512:
6
- metadata.gz: 3eee8ffc0e2f7df0837613b06e65231b0c7013b69dae419ec7842f92354c350a7608a8ec0f9c8ba1a757b4308c90f5f7bcbe073ab49196e91c9295e11b0bcfb8
7
- data.tar.gz: 47e6a365002f3c8e3e551f1020647e95e2dad184c3a561685ce56667cb773c9334d0bab2d72c23f650cb849a1c3c7d831ce3fbd499ca0558373e11ebfed772aa
6
+ metadata.gz: f54c8912b371c74034d95f1e46f18c07c9bc5c3544ea07ffdbd37650ac0980cfdf296485a798af14006ceaae2376c669bf53ea9dc64607402d63c91f6754a3c8
7
+ data.tar.gz: a2ffcc354d8508eb8164b1e45c4e2cd4927758f9963b900e74517a3edf523c00adb4a5235a005016ed486dddbef30be66eea7e8f129ab6496998e6775ac1e38c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.10.0 - 2022-07-27
6
+
7
+ ### Added
8
+
9
+ - Add `ignore` command.
10
+
11
+ ## 0.9.0 - 2022-07-27
12
+
13
+ ### Added
14
+
15
+ - Add `.rubocop_todo_corrector_ignore` file support.
16
+
17
+ ## 0.8.0 - 2022-07-23
18
+
19
+ ### Added
20
+
21
+ - Add `clean` command.
22
+
5
23
  ## 0.7.1 - 2022-05-28
6
24
 
7
25
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop_todo_corrector (0.7.1)
4
+ rubocop_todo_corrector (0.10.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,86 +25,25 @@ 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 correct # Run `rubocop --auto-correct-all`.
28
+ rubocop_todo_corrector clean # Remove temporary files.
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.
31
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.
32
34
  rubocop_todo_corrector pick # Output an auto-correctable Cop from .rubocop_todo.yml.
33
35
  rubocop_todo_corrector remove --cop-name=COP_NAME # Remove section with specified cop name from .rubocop_todo.yml.
34
36
  ```
35
37
 
36
- ### bundle
38
+ ### .rubocop_todo_corrector_ignore
37
39
 
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
40
+ By specifying cop names in `.rubocop_todo_corrector_ignore`, you can exclude them from the selection.
55
41
 
56
- Run `rubocop --auto-correct(-all)`.
57
42
  ```
43
+ Style/StringConcatenation
58
44
 
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.
45
+ # Comment line is available like this.
46
+ Style/StringLiterals
70
47
  ```
71
48
 
72
- ### generate
73
-
74
- ```console
75
- $ rubocop_todo_corrector help generate
76
- Usage:
77
- rubocop_todo_corrector generate
78
-
79
- Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
80
- ```
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.
97
- ```
98
-
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
- ```
49
+ 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,
@@ -48,6 +55,19 @@ module RubocopTodoCorrector
48
55
  )
49
56
  end
50
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
+
51
71
  desc 'pick', 'Output an auto-correctable Cop from .rubocop_todo.yml.'
52
72
  option(
53
73
  :mode,
@@ -68,6 +88,7 @@ module RubocopTodoCorrector
68
88
  )
69
89
  def pick
70
90
  Commands::Pick.call(
91
+ ignore_file_path: '.rubocop_todo_corrector_ignore',
71
92
  mode: options[:mode],
72
93
  only_safe: options[:only_safe],
73
94
  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
@@ -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
 
@@ -3,9 +3,11 @@
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'
10
+ autoload :Ignore, 'rubocop_todo_corrector/commands/ignore'
9
11
  autoload :Pick, 'rubocop_todo_corrector/commands/pick'
10
12
  autoload :Remove, 'rubocop_todo_corrector/commands/remove'
11
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopTodoCorrector
4
- VERSION = '0.7.1'
4
+ VERSION = '0.10.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.1
4
+ version: 0.10.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-27 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,9 +75,11 @@ 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
82
+ - lib/rubocop_todo_corrector/commands/ignore.rb
81
83
  - lib/rubocop_todo_corrector/commands/pick.rb
82
84
  - lib/rubocop_todo_corrector/commands/remove.rb
83
85
  - lib/rubocop_todo_corrector/cop_document_parser.rb
@@ -85,6 +87,7 @@ files:
85
87
  - lib/rubocop_todo_corrector/description_renderer.rb
86
88
  - lib/rubocop_todo_corrector/gem_names_detector.rb
87
89
  - lib/rubocop_todo_corrector/gem_version_detector.rb
90
+ - lib/rubocop_todo_corrector/ignore_file.rb
88
91
  - lib/rubocop_todo_corrector/rubocop_todo_parser.rb
89
92
  - lib/rubocop_todo_corrector/rubocop_todo_section_parser.rb
90
93
  - lib/rubocop_todo_corrector/version.rb