rubocop_todo_corrector 0.17.0 → 0.18.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 +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/rubocop_todo_corrector/cli.rb +20 -0
- data/lib/rubocop_todo_corrector/commands/apply.rb +124 -0
- data/lib/rubocop_todo_corrector/commands/remove.rb +0 -4
- data/lib/rubocop_todo_corrector/commands.rb +1 -0
- data/lib/rubocop_todo_corrector/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efb93393a3a909e2af0629cf384bfb3c9c5a123ddef3e055c95a8622e8df367d
|
4
|
+
data.tar.gz: 88bd969fe3b575e37f5f0903d3ba35b89eacbf363fa1f49e1ceec023279cd194
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a9ad177249f6d392edfa4b05c8e7c28cf577eb33a0eaa31a08f8033c872dbc30efc146e0a0aaf0aa6c4c1bdede0ce853dd95c13409dc0e4fe0e51ee472a95af
|
7
|
+
data.tar.gz: 57177d4e1131d7cd97fd128aa17d4b156399a30f9d8f7ac763a022220fe8ee0809f1af16825888d60e77f8ab0826fc1e0a48cb1661ea07369e54dc3ae3176893
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,6 +25,7 @@ gem install rubocop_todo_corrector
|
|
25
25
|
```console
|
26
26
|
$ rubocop_todo_corrector
|
27
27
|
Commands:
|
28
|
+
rubocop_todo_corrector apply # Remove target cop section from .rubocop_todo.yml and correct excluded files.
|
28
29
|
rubocop_todo_corrector bundle # Run `bundle install` to install RuboCop related gems.
|
29
30
|
rubocop_todo_corrector clean # Remove temporary files.
|
30
31
|
rubocop_todo_corrector correct # Run `rubocop --auto-correct(-all)`.
|
@@ -5,6 +5,26 @@ require 'thor'
|
|
5
5
|
module RubocopTodoCorrector
|
6
6
|
# Provide CLI sub-commands.
|
7
7
|
class Cli < ::Thor
|
8
|
+
desc 'apply', 'Remove target cop section from .rubocop_todo.yml and correct excluded files.'
|
9
|
+
option(
|
10
|
+
:cop_name,
|
11
|
+
type: :string,
|
12
|
+
required: true
|
13
|
+
)
|
14
|
+
option(
|
15
|
+
:only_safe,
|
16
|
+
default: true,
|
17
|
+
type: :boolean
|
18
|
+
)
|
19
|
+
def apply
|
20
|
+
Commands::Apply.call(
|
21
|
+
cop_name: options[:cop_name],
|
22
|
+
only_safe: options[:only_safe],
|
23
|
+
rubocop_todo_path: '.rubocop_todo.yml',
|
24
|
+
temporary_gemfile_path: 'tmp/Gemfile_rubocop_todo_corrector.rb'
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
8
28
|
desc 'bundle', 'Run `bundle install` to install RuboCop related gems.'
|
9
29
|
def bundle
|
10
30
|
Commands::Bundle.call(
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module RubocopTodoCorrector
|
7
|
+
module Commands
|
8
|
+
class Apply
|
9
|
+
class << self
|
10
|
+
# @param [String] cop_name
|
11
|
+
# @param [Boolean] only_safe
|
12
|
+
# @param [String] rubocop_todo_path
|
13
|
+
# @param [String] temporary_gemfile_path
|
14
|
+
# @return [void]
|
15
|
+
def call(
|
16
|
+
cop_name:,
|
17
|
+
only_safe:,
|
18
|
+
rubocop_todo_path:,
|
19
|
+
temporary_gemfile_path:
|
20
|
+
)
|
21
|
+
new(
|
22
|
+
cop_name:,
|
23
|
+
only_safe:,
|
24
|
+
rubocop_todo_path:,
|
25
|
+
temporary_gemfile_path:
|
26
|
+
).call
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [String] cop_name
|
31
|
+
# @param [Boolean] only_safe
|
32
|
+
# @param [String] rubocop_todo_path
|
33
|
+
# @param [String] temporary_gemfile_path
|
34
|
+
def initialize(
|
35
|
+
cop_name:,
|
36
|
+
only_safe:,
|
37
|
+
rubocop_todo_path:,
|
38
|
+
temporary_gemfile_path:
|
39
|
+
)
|
40
|
+
@cop_name = cop_name
|
41
|
+
@only_safe = only_safe
|
42
|
+
@rubocop_todo_path = rubocop_todo_path
|
43
|
+
@temporary_gemfile_path = temporary_gemfile_path
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [void]
|
47
|
+
def call
|
48
|
+
check_rubocop_todo_existence
|
49
|
+
update_rubocop_todo
|
50
|
+
autocorrect_excluded_files
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# @return [void]
|
56
|
+
def autocorrect_excluded_files
|
57
|
+
::Kernel.system(
|
58
|
+
{ 'BUNDLE_GEMFILE' => @temporary_gemfile_path },
|
59
|
+
[
|
60
|
+
'bundle exec rubocop --force-exclusion', autocorrect_option, *excluded_file_paths
|
61
|
+
].join(' ')
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [String]
|
66
|
+
def autocorrect_arguments
|
67
|
+
::Shellwords.shelljoin(excluded_file_paths)
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [String]
|
71
|
+
def autocorrect_option
|
72
|
+
if @only_safe
|
73
|
+
'--auto-correct'
|
74
|
+
else
|
75
|
+
'--auto-correct-all'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [void]
|
80
|
+
def check_rubocop_todo_existence
|
81
|
+
raise "#{rubocop_todo_pathname.to_s.inspect} does not exist." unless rubocop_todo_pathname.exist?
|
82
|
+
end
|
83
|
+
|
84
|
+
# @return [Array<String>]
|
85
|
+
def excluded_file_paths
|
86
|
+
cop_section = rubocop_todo_sections.grep(/^#{@cop_name}:/).first
|
87
|
+
raise unless cop_section
|
88
|
+
|
89
|
+
paths = ::YAML.safe_load(cop_section).dig(@cop_name, 'Exclude')
|
90
|
+
raise unless paths
|
91
|
+
|
92
|
+
paths
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [String]
|
96
|
+
def rubocop_todo_content
|
97
|
+
rubocop_todo_pathname.read
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [Array<String>]
|
101
|
+
def rubocop_todo_sections
|
102
|
+
@rubocop_todo_sections ||= rubocop_todo_content.split("\n\n")
|
103
|
+
end
|
104
|
+
|
105
|
+
# @return [String]
|
106
|
+
def rubocop_todo_content_without_cop
|
107
|
+
rubocop_todo_sections.grep_v(/^#{@cop_name}:$/).join("\n\n")
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return [Pathname]
|
111
|
+
def rubocop_todo_pathname
|
112
|
+
@rubocop_todo_pathname ||= ::Pathname.new(@rubocop_todo_path)
|
113
|
+
end
|
114
|
+
|
115
|
+
# @return [void]
|
116
|
+
def update_rubocop_todo
|
117
|
+
::File.write(
|
118
|
+
@rubocop_todo_path,
|
119
|
+
rubocop_todo_content_without_cop
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -44,10 +44,6 @@ module RubocopTodoCorrector
|
|
44
44
|
rubocop_todo_content.split("\n\n").grep_v(/^#{@cop_name}:$/).join("\n\n")
|
45
45
|
end
|
46
46
|
|
47
|
-
def rubocop_todo
|
48
|
-
RubocopTodoParser.call(content: rubocop_todo_content)
|
49
|
-
end
|
50
|
-
|
51
47
|
# @return [String]
|
52
48
|
def rubocop_todo_content
|
53
49
|
rubocop_todo_pathname.read
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module RubocopTodoCorrector
|
4
4
|
module Commands
|
5
|
+
autoload :Apply, 'rubocop_todo_corrector/commands/apply'
|
5
6
|
autoload :Bundle, 'rubocop_todo_corrector/commands/bundle'
|
6
7
|
autoload :Clean, 'rubocop_todo_corrector/commands/clean'
|
7
8
|
autoload :Correct, 'rubocop_todo_corrector/commands/correct'
|
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.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- r7kamura@gmail.com
|
72
72
|
executables:
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/rubocop_todo_corrector/bundle_installer.rb
|
88
88
|
- lib/rubocop_todo_corrector/cli.rb
|
89
89
|
- lib/rubocop_todo_corrector/commands.rb
|
90
|
+
- lib/rubocop_todo_corrector/commands/apply.rb
|
90
91
|
- lib/rubocop_todo_corrector/commands/bundle.rb
|
91
92
|
- lib/rubocop_todo_corrector/commands/clean.rb
|
92
93
|
- lib/rubocop_todo_corrector/commands/correct.rb
|
@@ -115,7 +116,7 @@ metadata:
|
|
115
116
|
source_code_uri: https://github.com/r7kamura/rubocop_todo_corrector
|
116
117
|
changelog_uri: https://github.com/r7kamura/rubocop_todo_corrector/releases
|
117
118
|
rubygems_mfa_required: 'true'
|
118
|
-
post_install_message:
|
119
|
+
post_install_message:
|
119
120
|
rdoc_options: []
|
120
121
|
require_paths:
|
121
122
|
- lib
|
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
version: '0'
|
132
133
|
requirements: []
|
133
134
|
rubygems_version: 3.3.27
|
134
|
-
signing_key:
|
135
|
+
signing_key:
|
135
136
|
specification_version: 4
|
136
137
|
summary: Autocorrect offenses defined in .rubocop_todo.yml.
|
137
138
|
test_files: []
|