rubocop_todo_corrector 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +10 -5
- data/lib/rubocop_todo_corrector/cli.rb +14 -2
- data/lib/rubocop_todo_corrector/commands/correct.rb +17 -1
- data/lib/rubocop_todo_corrector/commands/pick.rb +10 -1
- data/lib/rubocop_todo_corrector/rubocop_todo_section_parser.rb +15 -6
- data/lib/rubocop_todo_corrector/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a16c0718e0411c212efc6aa1a070df5c0784c415b3ae25b47686c35d4a37f196
|
4
|
+
data.tar.gz: 38c4affee6edb3e6569a64df3d4b410522de4fee23c7f3849bbf9b7ccb1e67d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a31400bdfed79ab2ed935347885b40bae95956dec916b42dfb001b09507443ed3275cb003402bd427f73bd401006783360916c8f2de20e2382d5dbed18f70720
|
7
|
+
data.tar.gz: 8db623bd95d0f3c942df88e1ac720c296305c0f8b2b88371993906cc522253d1159a49c2bc8ac0e3c803c09d672804da908a2970b8d707f22d780ea81a291864
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -29,7 +29,7 @@ Commands:
|
|
29
29
|
rubocop_todo_corrector describe --cop-name=COP_NAME # Output Markdown description for specified cop.
|
30
30
|
rubocop_todo_corrector generate # Run `rubocop --auto-gen-config` to generate .rubocop_todo.yml.
|
31
31
|
rubocop_todo_corrector help [COMMAND] # Describe available commands or one specific command
|
32
|
-
rubocop_todo_corrector pick #
|
32
|
+
rubocop_todo_corrector pick # Output an auto-correctable Cop from .rubocop_todo.yml.
|
33
33
|
rubocop_todo_corrector remove --cop-name=COP_NAME # Remove section with specified cop name from .rubocop_todo.yml.
|
34
34
|
```
|
35
35
|
|
@@ -46,11 +46,14 @@ Run `bundle install` to install RuboCop related gems.
|
|
46
46
|
### correct
|
47
47
|
|
48
48
|
```console
|
49
|
-
$ rubocop_todo_corrector help correct
|
50
49
|
Usage:
|
51
50
|
rubocop_todo_corrector correct
|
52
51
|
|
53
|
-
|
52
|
+
Options:
|
53
|
+
[--only-safe], [--no-only-safe]
|
54
|
+
# Default: true
|
55
|
+
|
56
|
+
Run `rubocop --auto-correct(-all)`.
|
54
57
|
```
|
55
58
|
|
56
59
|
### describe
|
@@ -85,8 +88,10 @@ Usage:
|
|
85
88
|
|
86
89
|
Options:
|
87
90
|
[--mode=MODE]
|
88
|
-
|
89
|
-
|
91
|
+
# Default: random
|
92
|
+
# Possible values: first, last, least_occurred, most_occurred, random
|
93
|
+
[--only-safe], [--no-only-safe]
|
94
|
+
# Default: true
|
90
95
|
|
91
96
|
Output an auto-correctable Cop from .rubocop_todo.yml.
|
92
97
|
```
|
@@ -14,9 +14,15 @@ module RubocopTodoCorrector
|
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
|
-
desc 'correct', 'Run `rubocop --auto-correct-all`.'
|
17
|
+
desc 'correct', 'Run `rubocop --auto-correct(-all)`.'
|
18
|
+
option(
|
19
|
+
:only_safe,
|
20
|
+
default: true,
|
21
|
+
type: :boolean
|
22
|
+
)
|
18
23
|
def correct
|
19
24
|
Commands::Correct.call(
|
25
|
+
only_safe: options[:only_safe],
|
20
26
|
temporary_gemfile_path: 'tmp/Gemfile_rubocop_todo_corrector.rb'
|
21
27
|
)
|
22
28
|
end
|
@@ -42,7 +48,7 @@ module RubocopTodoCorrector
|
|
42
48
|
)
|
43
49
|
end
|
44
50
|
|
45
|
-
desc 'pick', '
|
51
|
+
desc 'pick', 'Output an auto-correctable Cop from .rubocop_todo.yml.'
|
46
52
|
option(
|
47
53
|
:mode,
|
48
54
|
default: 'random',
|
@@ -55,9 +61,15 @@ module RubocopTodoCorrector
|
|
55
61
|
],
|
56
62
|
type: :string
|
57
63
|
)
|
64
|
+
option(
|
65
|
+
:only_safe,
|
66
|
+
default: true,
|
67
|
+
type: :boolean
|
68
|
+
)
|
58
69
|
def pick
|
59
70
|
Commands::Pick.call(
|
60
71
|
mode: options[:mode],
|
72
|
+
only_safe: options[:only_safe],
|
61
73
|
rubocop_todo_path: '.rubocop_todo.yml'
|
62
74
|
)
|
63
75
|
end
|
@@ -4,28 +4,44 @@ module RubocopTodoCorrector
|
|
4
4
|
module Commands
|
5
5
|
class Correct
|
6
6
|
class << self
|
7
|
+
# @param [Boolean] only_safe
|
7
8
|
# @param [String] temporary_gemfile_path
|
8
9
|
def call(
|
10
|
+
only_safe:,
|
9
11
|
temporary_gemfile_path:
|
10
12
|
)
|
11
13
|
new(
|
14
|
+
only_safe:,
|
12
15
|
temporary_gemfile_path:
|
13
16
|
).call
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
17
20
|
def initialize(
|
21
|
+
only_safe:,
|
18
22
|
temporary_gemfile_path:
|
19
23
|
)
|
24
|
+
@only_safe = only_safe
|
20
25
|
@temporary_gemfile_path = temporary_gemfile_path
|
21
26
|
end
|
22
27
|
|
23
28
|
def call
|
24
29
|
::Kernel.system(
|
25
30
|
{ 'BUNDLE_GEMFILE' => @temporary_gemfile_path },
|
26
|
-
|
31
|
+
"bundle exec rubocop #{rubocop_options}"
|
27
32
|
)
|
28
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# @return [String]
|
38
|
+
def rubocop_options
|
39
|
+
if @only_safe
|
40
|
+
'--auto-correct'
|
41
|
+
else
|
42
|
+
'--auto-correct-all'
|
43
|
+
end
|
44
|
+
end
|
29
45
|
end
|
30
46
|
end
|
31
47
|
end
|
@@ -7,13 +7,16 @@ module RubocopTodoCorrector
|
|
7
7
|
class Pick
|
8
8
|
class << self
|
9
9
|
# @param [String] mode
|
10
|
+
# @param [Boolean] only_safe
|
10
11
|
# @param [String] rubocop_todo_path
|
11
12
|
def call(
|
12
13
|
mode:,
|
14
|
+
only_safe:,
|
13
15
|
rubocop_todo_path:
|
14
16
|
)
|
15
17
|
new(
|
16
18
|
mode:,
|
19
|
+
only_safe:,
|
17
20
|
rubocop_todo_path:
|
18
21
|
).call
|
19
22
|
end
|
@@ -21,9 +24,11 @@ module RubocopTodoCorrector
|
|
21
24
|
|
22
25
|
def initialize(
|
23
26
|
mode:,
|
27
|
+
only_safe:,
|
24
28
|
rubocop_todo_path:
|
25
29
|
)
|
26
30
|
@mode = mode
|
31
|
+
@only_safe = only_safe
|
27
32
|
@rubocop_todo_path = rubocop_todo_path
|
28
33
|
end
|
29
34
|
|
@@ -42,7 +47,11 @@ module RubocopTodoCorrector
|
|
42
47
|
# @return [Array<Hash>]
|
43
48
|
def auto_correctable_cops
|
44
49
|
rubocop_todo[:cops].select do |cop|
|
45
|
-
|
50
|
+
if @only_safe
|
51
|
+
cop[:safe_auto_correctable]
|
52
|
+
else
|
53
|
+
cop[:auto_correctable]
|
54
|
+
end
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
@@ -18,19 +18,18 @@ module RubocopTodoCorrector
|
|
18
18
|
# @return [Hash]
|
19
19
|
def call
|
20
20
|
{
|
21
|
-
auto_correctable
|
21
|
+
auto_correctable:,
|
22
22
|
name:,
|
23
|
-
offenses_count
|
23
|
+
offenses_count:,
|
24
|
+
safe_auto_correctable:
|
24
25
|
}
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
30
|
# @return [Boolean]
|
30
|
-
def auto_correctable
|
31
|
-
|
32
|
-
@content.include?('# This cop supports safe auto-correction') ||
|
33
|
-
@content.include?('# This cop supports unsafe auto-correction')
|
31
|
+
def auto_correctable
|
32
|
+
safe_auto_correctable || unsafe_auto_corectable
|
34
33
|
end
|
35
34
|
|
36
35
|
# @return [String, nil]
|
@@ -45,5 +44,15 @@ module RubocopTodoCorrector
|
|
45
44
|
'offenses_count'
|
46
45
|
]&.to_i
|
47
46
|
end
|
47
|
+
|
48
|
+
def safe_auto_correctable
|
49
|
+
@content.include?('# Cop supports --auto-correct.') ||
|
50
|
+
@content.include?('# This cop supports safe auto-correction')
|
51
|
+
end
|
52
|
+
|
53
|
+
def unsafe_auto_corectable
|
54
|
+
@content.include?('# Cop supports --auto-correct-all') ||
|
55
|
+
@content.include?('# This cop supports unsafe auto-correction')
|
56
|
+
end
|
48
57
|
end
|
49
58
|
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|