rubocop_todo_corrector 0.9.0 → 0.11.1

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: 61752242b12ed25751b22323c3c0d177acefa0d89a23146607c126c3382921e7
4
- data.tar.gz: be9d3d0f9c9428bdf7e2967a293dffe199539ea8a071545b0cbb4d914e1854c5
3
+ metadata.gz: 1725e72b773d02b2b00407840e3cc9c6f1369efa22fc81f335dda6b3959080cd
4
+ data.tar.gz: 01c22d85c57ea1d2cdfdd692cef1c92764025cacdda049b65d146731a6ed723a
5
5
  SHA512:
6
- metadata.gz: 15a1cb26be0f48eca2430c827985be3eb9426684c9123a23d8f1d7f2c379cd56fda991edf58e6e25b58f65fd769919c20cad8ac9292b9c3a7576d272bc0b29e4
7
- data.tar.gz: 3506ce4ca3b8fc368c79bd90ab6b18eb6cdabb35d6364891fc928917a5f232904cd020885915d0b2245fd720fe116f57ea7746759a9ca30b84051cc2a89e0cb3
6
+ metadata.gz: fd2ceb4d8b406bb5e2e03feeb155b46ba8013ca8080d5667379c002b9b56c36473d9d62292b3aedb262ed2ecfb447608903ff704a01ae53a8d2de62a8f785858
7
+ data.tar.gz: e81181f9fb7919e5066d265ef7250127d99fbf06ef7fc0a0c5c5eb3f5c7c58f25bd7dcb513c4d10742cf63651d6b12d15475744593b66eb0efd457251da7b814
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.11.1 - 2022-08-03
6
+
7
+ ### Fixed
8
+
9
+ - Fix `describe` command on more than three nested cop class.
10
+
11
+ ## 0.11.0 - 2022-07-29
12
+
13
+ ### Changed
14
+
15
+ - Use `rubocop --regenerate-todo` option on `generate` command.
16
+
17
+ ## 0.10.0 - 2022-07-27
18
+
19
+ ### Added
20
+
21
+ - Add `ignore` command.
22
+
5
23
  ## 0.9.0 - 2022-07-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.9.0)
4
+ rubocop_todo_corrector (0.11.1)
5
5
  bundler
6
6
  thor
7
7
  yard
data/README.md CHANGED
@@ -3,7 +3,9 @@
3
3
  [![test](https://github.com/r7kamura/rubocop_todo_corrector/actions/workflows/test.yml/badge.svg)](https://github.com/r7kamura/rubocop_todo_corrector/actions/workflows/test.yml)
4
4
  [![Gem Version](https://badge.fury.io/rb/rubocop_todo_corrector.svg)](https://rubygems.org/gems/rubocop_todo_corrector)
5
5
 
6
- Auto-correct offenses defined in .rubocop_todo.yml.
6
+ Auto-correct offenses defined in `.rubocop_todo.yml`.
7
+
8
+ This is an internal implementation of [rubocop-todo-corrector](https://github.com/r7kamura/rubocop-todo-corrector) action. See its README for more information about this action.
7
9
 
8
10
  ## Installation
9
11
 
@@ -26,10 +28,11 @@ $ rubocop_todo_corrector
26
28
  Commands:
27
29
  rubocop_todo_corrector bundle # Run `bundle install` to install RuboCop related gems.
28
30
  rubocop_todo_corrector clean # Remove temporary files.
29
- rubocop_todo_corrector correct # Run `rubocop --auto-correct-all`.
31
+ rubocop_todo_corrector correct # Run `rubocop --auto-correct(-all)`.
30
32
  rubocop_todo_corrector describe --cop-name=COP_NAME # Output Markdown description for specified cop.
31
33
  rubocop_todo_corrector generate # Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
32
34
  rubocop_todo_corrector help [COMMAND] # Describe available commands or one specific command
35
+ rubocop_todo_corrector ignore --cop-name=COP_NAME # Ignore specified cop by appending it to ignore file.
33
36
  rubocop_todo_corrector pick # Output an auto-correctable Cop from .rubocop_todo.yml.
34
37
  rubocop_todo_corrector remove --cop-name=COP_NAME # Remove section with specified cop name from .rubocop_todo.yml.
35
38
  ```
@@ -40,6 +43,8 @@ By specifying cop names in `.rubocop_todo_corrector_ignore`, you can exclude the
40
43
 
41
44
  ```
42
45
  Style/StringConcatenation
46
+
47
+ # Comment line is available like this.
43
48
  Style/StringLiterals
44
49
  ```
45
50
 
@@ -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,
@@ -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
@@ -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
@@ -45,7 +45,7 @@ module RubocopTodoCorrector
45
45
 
46
46
  # @return [String]
47
47
  def cop_class_name
48
- "RuboCop::Cop::#{@cop_name.sub('/', '::')}"
48
+ "RuboCop::Cop::#{@cop_name.gsub('/', '::')}"
49
49
  end
50
50
  end
51
51
  end
@@ -9,6 +9,15 @@ module RubocopTodoCorrector
9
9
  @path = path
10
10
  end
11
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
+
12
21
  # @return [Array<String>]
13
22
  def ignored_cop_names
14
23
  content.split("\n").map do |line|
@@ -27,6 +36,12 @@ module RubocopTodoCorrector
27
36
  end
28
37
  end
29
38
 
39
+ # @param [String] cop_name
40
+ # @return [Boolean]
41
+ def include?(cop_name)
42
+ ignored_cop_names.include?(cop_name)
43
+ end
44
+
30
45
  # @return [Pathname]
31
46
  def pathname
32
47
  @pathname ||= ::Pathname.new(@path)
@@ -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.9.0'
4
+ VERSION = '0.11.1'
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.9.0
4
+ version: 0.11.1
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-26 00:00:00.000000000 Z
11
+ date: 2022-08-03 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