rubomop 0.2.0 → 1.0.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/.ruby-version +1 -1
- data/.standard.yml +1 -1
- data/CHANGELOG.md +11 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +87 -46
- data/README.md +2 -2
- data/exe/rubomop +1 -2
- data/lib/rubomop/cop.rb +70 -19
- data/lib/rubomop/named_mop.rb +12 -0
- data/lib/rubomop/{mop.rb → random_mop.rb} +30 -19
- data/lib/rubomop/runner.rb +58 -15
- data/lib/rubomop/todo_file.rb +9 -1
- data/lib/rubomop/version.rb +1 -1
- data/lib/rubomop.rb +2 -0
- metadata +27 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 216a8fe4da9335c5a7c12ee8e5660003658aab305804acf99bb69c8493b357d1
|
4
|
+
data.tar.gz: 86644a5f0e10bf9d744fa9e7c516b5749cc303ced54991fd6062f25c3ba87e1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3480c30528e1bf9439bb8b8c7c1de4dc7ce5f77e38c234640eacad02fbdd9365cc739b2b205f741635fbff4145ae3a2725db611d83af0365ade53efedbe8d0da
|
7
|
+
data.tar.gz: ff974af44e598fd848c50f5be23f96515c446a5e674344b2b972b026c99bf25899fb88fee67d416b3b45ae0c4ca8927934ae9f43e0372f36b306ae9bfbdbe8d7
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.8
|
data/.standard.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
## [
|
1
|
+
## [1.0.0] - 7/31/2025
|
2
|
+
|
3
|
+
- Allow for a second run type that removes a specific cop from the todo
|
4
|
+
- Allow for running the cleanup on a different directory
|
5
|
+
- Allow for the difference between safe and unsafe autocorrect
|
6
|
+
- Drop support for Ruby 3.1 and lower
|
7
|
+
- Handles the case where Rubocop puts criteria and not exclusions in the to-do
|
8
|
+
|
9
|
+
## [0.3.0] - 2022-08-12
|
10
|
+
|
11
|
+
- More accurately update offense count in todo file after running rubocop
|
2
12
|
|
3
13
|
## [0.2.0] - 2022-07-22
|
4
14
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,74 +1,115 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubomop (0.
|
5
|
-
activesupport (
|
4
|
+
rubomop (1.0.0)
|
5
|
+
activesupport (>= 7.0)
|
6
6
|
date_by_example (~> 0.1)
|
7
|
-
|
7
|
+
literal
|
8
|
+
zeitwerk (~> 2.7.0)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
activesupport (
|
13
|
-
|
13
|
+
activesupport (8.0.2)
|
14
|
+
base64
|
15
|
+
benchmark (>= 0.3)
|
16
|
+
bigdecimal
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
18
|
+
connection_pool (>= 2.2.5)
|
19
|
+
drb
|
14
20
|
i18n (>= 1.6, < 2)
|
21
|
+
logger (>= 1.4.2)
|
15
22
|
minitest (>= 5.1)
|
16
|
-
|
17
|
-
|
23
|
+
securerandom (>= 0.3)
|
24
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
25
|
+
uri (>= 0.13.1)
|
26
|
+
ast (2.4.3)
|
18
27
|
awesome_print (1.9.2)
|
19
|
-
|
28
|
+
base64 (0.3.0)
|
29
|
+
benchmark (0.4.1)
|
30
|
+
bigdecimal (3.2.2)
|
31
|
+
concurrent-ruby (1.3.5)
|
32
|
+
connection_pool (2.5.3)
|
20
33
|
date_by_example (0.1.1)
|
21
|
-
diff-lcs (1.
|
22
|
-
|
34
|
+
diff-lcs (1.6.2)
|
35
|
+
drb (2.2.3)
|
36
|
+
i18n (1.14.7)
|
23
37
|
concurrent-ruby (~> 1.0)
|
24
|
-
|
25
|
-
|
26
|
-
|
38
|
+
json (2.13.2)
|
39
|
+
language_server-protocol (3.17.0.5)
|
40
|
+
lint_roller (1.1.0)
|
41
|
+
literal (1.8.1)
|
42
|
+
zeitwerk
|
43
|
+
logger (1.7.0)
|
44
|
+
minitest (5.25.5)
|
45
|
+
parallel (1.27.0)
|
46
|
+
parser (3.3.9.0)
|
27
47
|
ast (~> 2.4.1)
|
48
|
+
racc
|
49
|
+
prism (1.4.0)
|
50
|
+
racc (1.8.1)
|
28
51
|
rainbow (3.1.1)
|
29
|
-
rake (13.0
|
30
|
-
regexp_parser (2.
|
31
|
-
|
32
|
-
|
33
|
-
rspec-
|
34
|
-
rspec-
|
35
|
-
|
36
|
-
rspec-collection_matchers (1.2.0)
|
52
|
+
rake (13.3.0)
|
53
|
+
regexp_parser (2.10.0)
|
54
|
+
rspec (3.13.1)
|
55
|
+
rspec-core (~> 3.13.0)
|
56
|
+
rspec-expectations (~> 3.13.0)
|
57
|
+
rspec-mocks (~> 3.13.0)
|
58
|
+
rspec-collection_matchers (1.2.1)
|
37
59
|
rspec-expectations (>= 2.99.0.beta1)
|
38
|
-
rspec-core (3.
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-expectations (3.
|
60
|
+
rspec-core (3.13.5)
|
61
|
+
rspec-support (~> 3.13.0)
|
62
|
+
rspec-expectations (3.13.5)
|
41
63
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-mocks (3.
|
64
|
+
rspec-support (~> 3.13.0)
|
65
|
+
rspec-mocks (3.13.5)
|
44
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-support (3.
|
47
|
-
rubocop (1.
|
67
|
+
rspec-support (~> 3.13.0)
|
68
|
+
rspec-support (3.13.4)
|
69
|
+
rubocop (1.75.8)
|
70
|
+
json (~> 2.3)
|
71
|
+
language_server-protocol (~> 3.17.0.2)
|
72
|
+
lint_roller (~> 1.1.0)
|
48
73
|
parallel (~> 1.10)
|
49
|
-
parser (>= 3.
|
74
|
+
parser (>= 3.3.0.2)
|
50
75
|
rainbow (>= 2.2.2, < 4.0)
|
51
|
-
regexp_parser (>=
|
52
|
-
|
53
|
-
rubocop-ast (>= 1.17.0, < 2.0)
|
76
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
77
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
54
78
|
ruby-progressbar (~> 1.7)
|
55
|
-
unicode-display_width (>=
|
56
|
-
rubocop-ast (1.
|
57
|
-
parser (>= 3.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
79
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
80
|
+
rubocop-ast (1.46.0)
|
81
|
+
parser (>= 3.3.7.2)
|
82
|
+
prism (~> 1.4)
|
83
|
+
rubocop-performance (1.25.0)
|
84
|
+
lint_roller (~> 1.1)
|
85
|
+
rubocop (>= 1.75.0, < 2.0)
|
86
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
87
|
+
ruby-progressbar (1.13.0)
|
88
|
+
securerandom (0.4.1)
|
89
|
+
standard (1.50.0)
|
90
|
+
language_server-protocol (~> 3.17.0.2)
|
91
|
+
lint_roller (~> 1.0)
|
92
|
+
rubocop (~> 1.75.5)
|
93
|
+
standard-custom (~> 1.0.0)
|
94
|
+
standard-performance (~> 1.8)
|
95
|
+
standard-custom (1.0.2)
|
96
|
+
lint_roller (~> 1.0)
|
97
|
+
rubocop (~> 1.50)
|
98
|
+
standard-performance (1.8.0)
|
99
|
+
lint_roller (~> 1.1)
|
100
|
+
rubocop-performance (~> 1.25.0)
|
101
|
+
tzinfo (2.0.6)
|
66
102
|
concurrent-ruby (~> 1.0)
|
67
|
-
unicode-display_width (
|
68
|
-
|
103
|
+
unicode-display_width (3.1.4)
|
104
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
105
|
+
unicode-emoji (4.0.4)
|
106
|
+
uri (1.0.3)
|
107
|
+
zeitwerk (2.7.3)
|
69
108
|
|
70
109
|
PLATFORMS
|
71
110
|
arm64-darwin-21
|
111
|
+
arm64-darwin-24
|
112
|
+
arm64-darwin-25
|
72
113
|
x86_64-darwin-21
|
73
114
|
x86_64-linux
|
74
115
|
|
data/README.md
CHANGED
data/exe/rubomop
CHANGED
data/lib/rubomop/cop.rb
CHANGED
@@ -1,38 +1,41 @@
|
|
1
1
|
module Rubomop
|
2
|
-
class Cop
|
3
|
-
|
4
|
-
|
2
|
+
class Cop < Literal::Object
|
3
|
+
prop :raw_lines, _Array(String), reader: :public, default: -> { [] }
|
4
|
+
prop :files, _Array(String), reader: :public, writer: :public, default: -> { [] }
|
5
|
+
prop :comments, _Array(String), reader: :public, writer: :public, default: -> { [] }
|
6
|
+
prop :config_params, _Array(String), reader: :public, writer: :public, default: -> { [] }
|
7
|
+
prop :autocorrect, _Nilable(Symbol), reader: :public, writer: :public, default: :none
|
8
|
+
prop :offense_count, Integer, reader: :public, writer: :public, default: 0
|
9
|
+
prop :name, String, reader: :public, writer: :public, default: -> { "" }
|
10
|
+
prop :active, _Boolean, reader: :public, writer: :public, default: true
|
5
11
|
|
6
12
|
def self.create_and_parse(raw_lines)
|
7
|
-
result = new(raw_lines)
|
13
|
+
result = new(raw_lines:)
|
8
14
|
result.parse
|
9
15
|
result
|
10
16
|
end
|
11
17
|
|
12
|
-
def initialize(raw_lines)
|
13
|
-
@raw_lines = raw_lines
|
14
|
-
@files = []
|
15
|
-
@autocorrect = false
|
16
|
-
@comments = []
|
17
|
-
end
|
18
|
-
|
19
18
|
def parse
|
20
19
|
raw_lines.each { parse_one_line(_1) }
|
21
20
|
end
|
22
21
|
|
23
22
|
OFFENSE_COUNT_REGEX = /\A# Offense count: (\d*)/
|
24
|
-
COP_NAME_REGEX = /\A(.*):/
|
23
|
+
COP_NAME_REGEX = /\A(\S.*):/
|
25
24
|
FILE_NAME_REGEX = /- '(.*)'/
|
26
|
-
|
25
|
+
SAFE_AUTOCORRECT_REGEX = /\A# This cop supports safe autocorrection/
|
26
|
+
UNSAFE_AUTOCORRECT_REGEX = /\A# This cop supports unsafe autocorrection/
|
27
27
|
GENERAL_COMMENT_REGEX = /\A#/
|
28
28
|
EXCLUDE_REGEX = /Exclude:/
|
29
|
+
CONFIG_PARAM_REGEX = /\A\s\s(.*)/
|
29
30
|
|
30
31
|
def parse_one_line(line)
|
31
32
|
case line
|
32
33
|
when OFFENSE_COUNT_REGEX
|
33
34
|
self.offense_count = line.match(OFFENSE_COUNT_REGEX)[1].to_i
|
34
|
-
when
|
35
|
-
self.autocorrect =
|
35
|
+
when SAFE_AUTOCORRECT_REGEX
|
36
|
+
self.autocorrect = :safe
|
37
|
+
when UNSAFE_AUTOCORRECT_REGEX
|
38
|
+
self.autocorrect = :unsafe
|
36
39
|
when GENERAL_COMMENT_REGEX
|
37
40
|
comments << line.chomp
|
38
41
|
when EXCLUDE_REGEX
|
@@ -41,6 +44,8 @@ module Rubomop
|
|
41
44
|
self.name = line.match(COP_NAME_REGEX)[1]
|
42
45
|
when FILE_NAME_REGEX
|
43
46
|
files << line.match(FILE_NAME_REGEX)[1]
|
47
|
+
when CONFIG_PARAM_REGEX
|
48
|
+
config_params << line.match(CONFIG_PARAM_REGEX)[1]
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
@@ -50,16 +55,62 @@ module Rubomop
|
|
50
55
|
|
51
56
|
def output_lines
|
52
57
|
result = ["# Offense count: #{offense_count}"]
|
53
|
-
result << "#
|
58
|
+
result << "# This cop supports safe autocorrection (--autocorrect)." if autocorrect == :safe
|
59
|
+
result << "# This cop supports unsafe autocorrection (--autocorrect-all)." if autocorrect == :unsafe
|
54
60
|
result += comments
|
55
61
|
result << "#{name}:"
|
56
|
-
result
|
57
|
-
|
62
|
+
result += config_params.map { " #{_1}" }
|
63
|
+
unless files.empty?
|
64
|
+
result << " Exclude:"
|
65
|
+
result += files.map { " - '#{_1}'" }
|
66
|
+
end
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
def any_autocorrect?
|
71
|
+
autocorrect != :none
|
72
|
+
end
|
73
|
+
|
74
|
+
def autocorrect_inquiry
|
75
|
+
autocorrect.to_s.inquiry
|
76
|
+
end
|
77
|
+
|
78
|
+
def autocorrect_verbiage
|
79
|
+
case autocorrect
|
80
|
+
when :safe then "safe autocorrect"
|
81
|
+
when :unsafe then "unsafe autocorrect"
|
82
|
+
else
|
83
|
+
"no autocorrect"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def autocorrect_option
|
88
|
+
case autocorrect
|
89
|
+
when :safe then "a"
|
90
|
+
when :unsafe then "A"
|
91
|
+
else
|
92
|
+
""
|
93
|
+
end
|
58
94
|
end
|
59
95
|
|
60
96
|
def delete!(filename)
|
61
97
|
files.delete(filename)
|
62
|
-
|
98
|
+
end
|
99
|
+
|
100
|
+
def subtract!(offense_count)
|
101
|
+
self.offense_count -= offense_count
|
102
|
+
end
|
103
|
+
|
104
|
+
def activate
|
105
|
+
self.active = true
|
106
|
+
end
|
107
|
+
|
108
|
+
def deactivate
|
109
|
+
self.active = false
|
110
|
+
end
|
111
|
+
|
112
|
+
def active?
|
113
|
+
active
|
63
114
|
end
|
64
115
|
end
|
65
116
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Rubomop
|
2
|
+
class NamedMop < Literal::Object
|
3
|
+
prop :todo_file, TodoFile, reader: :public, writer: :public
|
4
|
+
prop :name, String, reader: :public, writer: :public
|
5
|
+
prop :verbose, _Boolean, reader: :public, writer: :public
|
6
|
+
prop :run_rubocop, _Boolean, reader: :public, writer: :public
|
7
|
+
|
8
|
+
def mop!
|
9
|
+
todo_file.cop_for(name).deactivate
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,30 +1,25 @@
|
|
1
1
|
module Rubomop
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@run_rubocop = run_rubocop
|
12
|
-
@only = only
|
13
|
-
@except = except
|
14
|
-
@block = blocklist
|
15
|
-
end
|
2
|
+
class RandomMop < Literal::Object
|
3
|
+
prop :todo_file, TodoFile, reader: :public, writer: :public
|
4
|
+
prop :number, Integer, reader: :public, writer: :public
|
5
|
+
prop :autocorrect_only, _Boolean, reader: :public, writer: :public
|
6
|
+
prop :verbose, _Boolean, reader: :public, writer: :public
|
7
|
+
prop :run_rubocop, _Boolean, reader: :public, writer: :public
|
8
|
+
prop :only, _Array(String), reader: :public, writer: :public
|
9
|
+
prop :except, _Array(String), reader: :public, writer: :public
|
10
|
+
prop :blocklist, _Array(String), reader: :public, writer: :public
|
16
11
|
|
17
12
|
def cops
|
18
13
|
todo_file.cops
|
19
14
|
end
|
20
15
|
|
21
16
|
def accept?(delete_option)
|
22
|
-
return false if autocorrect_only && !delete_option.cop.
|
17
|
+
return false if autocorrect_only && !delete_option.cop.any_autocorrect?
|
23
18
|
unless except.empty?
|
24
19
|
return except.none? { delete_option.cop.name.include?(_1) }
|
25
20
|
end
|
26
|
-
unless
|
27
|
-
return
|
21
|
+
unless blocklist.empty?
|
22
|
+
return blocklist.none? { delete_option.file.include?(_1) }
|
28
23
|
end
|
29
24
|
unless only.empty?
|
30
25
|
return only.any? { delete_option.cop.name.include?(_1) }
|
@@ -63,7 +58,8 @@ module Rubomop
|
|
63
58
|
delete_option.delete!
|
64
59
|
return unless run_rubocop
|
65
60
|
todo_file.save!
|
66
|
-
delete_option.rubocop_runner
|
61
|
+
offense_count = delete_option.rubocop_runner || 0
|
62
|
+
delete_option.subtract!(offense_count)
|
67
63
|
end
|
68
64
|
|
69
65
|
DeleteOption = Struct.new(:cop, :file, :verbose, :run_rubocop) do
|
@@ -76,10 +72,25 @@ module Rubomop
|
|
76
72
|
cop.delete!(file)
|
77
73
|
end
|
78
74
|
|
75
|
+
def subtract!(offense_count)
|
76
|
+
cop.subtract!(offense_count)
|
77
|
+
end
|
78
|
+
|
79
79
|
def rubocop_runner
|
80
80
|
return unless run_rubocop
|
81
81
|
print "\nbundle exec rubocop #{file} -aD\n"
|
82
|
-
|
82
|
+
IO.popen("bundle exec rubocop #{file} -aD") do |io|
|
83
|
+
result_string = io.read
|
84
|
+
puts result_string.split("\n").last
|
85
|
+
puts "\n"
|
86
|
+
parse_io(result_string)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def parse_io(string)
|
91
|
+
match_data = string.match(/(\d*) offense(s?) corrected/)
|
92
|
+
return 0 if match_data.nil?
|
93
|
+
match_data[1].to_i
|
83
94
|
end
|
84
95
|
end
|
85
96
|
end
|
data/lib/rubomop/runner.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Rubomop
|
2
2
|
class Runner
|
3
|
-
attr_accessor :number, :autocorrect_only, :run_rubocop
|
4
|
-
|
5
|
-
attr_accessor :only, :except, :block
|
3
|
+
attr_accessor :number, :autocorrect_only, :run_rubocop, :filename, :todo_file, :verbose, :config,
|
4
|
+
:options_from_command_line, :only, :except, :blocklist, :name, :directory
|
6
5
|
|
7
6
|
NUM_STRING = "Number of cleanups to perform (default: 10)"
|
8
|
-
|
7
|
+
NAME_STRING = "Name of cop to clean up. Choosing a name overrides choosing a number"
|
8
|
+
AUTOCORRECT_STRING = "Only clean auto-correctable cops (default)"
|
9
9
|
NO_AUTOCORRECT_STRING = "Clean all cops (not default)"
|
10
10
|
RUBOCOP_STRING = "Run rubocop -aD after (default)"
|
11
11
|
NO_RUBOCOP_STRING = "Don't run rubocop -aD after (not default)"
|
@@ -14,6 +14,7 @@ module Rubomop
|
|
14
14
|
ONLY_STRING = "String or regex of cops to limit removal do, can have multiple"
|
15
15
|
EXCEPT_STRING = "String or regex of cops to not remove from, can have multiple"
|
16
16
|
BLOCK_STRING = "String or regex of files to not touch, can have multiple"
|
17
|
+
DIRECTORY_STRING = "Directory to work in (default: current directory)"
|
17
18
|
|
18
19
|
def initialize
|
19
20
|
@number = 10
|
@@ -21,12 +22,14 @@ module Rubomop
|
|
21
22
|
@run_rubocop = true
|
22
23
|
@filename = ".rubocop_todo.yml"
|
23
24
|
@config = ".rubomop.yml"
|
24
|
-
@
|
25
|
+
@directory = "."
|
26
|
+
@todo_file = TodoFile.new(filename: full_path(@filename))
|
25
27
|
@verbose = true
|
26
28
|
@options_from_command_line = []
|
27
29
|
@only = []
|
28
30
|
@except = []
|
29
|
-
@
|
31
|
+
@blocklist = []
|
32
|
+
@name = nil
|
30
33
|
end
|
31
34
|
|
32
35
|
def execute(args)
|
@@ -37,13 +40,18 @@ module Rubomop
|
|
37
40
|
def load_options(args)
|
38
41
|
parse(args)
|
39
42
|
load_from_file
|
43
|
+
# Recreate todo_file with the correct directory after options are loaded
|
44
|
+
@todo_file = TodoFile.new(filename: full_path(@filename))
|
40
45
|
end
|
41
46
|
|
42
47
|
def load_from_file
|
43
|
-
|
44
|
-
|
48
|
+
config_path = full_path(config)
|
49
|
+
return unless File.exist?(config_path)
|
50
|
+
|
51
|
+
file_options = YAML.safe_load_file(config_path)
|
45
52
|
file_options.each do |key, value|
|
46
53
|
next if options_from_command_line.include?(key)
|
54
|
+
|
47
55
|
send("#{key.underscore}=", value) if respond_to?("#{key.underscore}=")
|
48
56
|
end
|
49
57
|
rescue Psych::Exception
|
@@ -81,6 +89,10 @@ module Rubomop
|
|
81
89
|
self.config = value
|
82
90
|
@options_from_command_line << "config"
|
83
91
|
end
|
92
|
+
opts.on("-dDIRECTORY", "--directory=DIRECTORY", "--dir=DIRECTORY", DIRECTORY_STRING) do |value|
|
93
|
+
self.directory = value
|
94
|
+
@options_from_command_line << "directory"
|
95
|
+
end
|
84
96
|
opts.on("--only=ONLY", ONLY_STRING) do |value|
|
85
97
|
only << value
|
86
98
|
@options_from_command_line << "only"
|
@@ -90,9 +102,13 @@ module Rubomop
|
|
90
102
|
@options_from_command_line << "except"
|
91
103
|
end
|
92
104
|
opts.on("--block=BLOCK", BLOCK_STRING) do |value|
|
93
|
-
|
105
|
+
blocklist << value
|
94
106
|
@options_from_command_line << "block"
|
95
107
|
end
|
108
|
+
opts.on("--name=NAME", NAME_STRING) do |value|
|
109
|
+
self.name = value
|
110
|
+
@options_from_command_line << "name"
|
111
|
+
end
|
96
112
|
opts.on("-h", "--help", "Prints this help") do
|
97
113
|
puts opts
|
98
114
|
exit
|
@@ -102,20 +118,47 @@ module Rubomop
|
|
102
118
|
end
|
103
119
|
|
104
120
|
def mop
|
105
|
-
|
121
|
+
if name
|
122
|
+
NamedMop.new(
|
123
|
+
todo_file:,
|
124
|
+
name:,
|
125
|
+
verbose:,
|
126
|
+
run_rubocop:
|
127
|
+
)
|
128
|
+
else
|
129
|
+
RandomMop.new(
|
130
|
+
todo_file:,
|
131
|
+
number:,
|
132
|
+
autocorrect_only:,
|
133
|
+
verbose:,
|
134
|
+
run_rubocop:,
|
135
|
+
only:,
|
136
|
+
except:,
|
137
|
+
blocklist:
|
138
|
+
)
|
139
|
+
end
|
106
140
|
end
|
107
141
|
|
108
142
|
def run
|
109
|
-
self.
|
110
|
-
return if
|
143
|
+
self.todo_file = TodoFile.new(filename: full_path(filename))&.parse
|
144
|
+
return if todo_file.nil?
|
145
|
+
|
111
146
|
backup_existing_file
|
112
147
|
mop.mop!
|
113
|
-
|
148
|
+
todo_file&.save!
|
114
149
|
end
|
115
150
|
|
116
151
|
def backup_existing_file
|
117
|
-
|
118
|
-
|
152
|
+
filename_path = full_path(filename)
|
153
|
+
backup_path = "#{filename_path}.bak"
|
154
|
+
FileUtils.rm(backup_path) if File.exist?(backup_path)
|
155
|
+
FileUtils.mv(filename_path, backup_path)
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
def full_path(file_path)
|
161
|
+
File.join(directory, file_path)
|
119
162
|
end
|
120
163
|
end
|
121
164
|
end
|
data/lib/rubomop/todo_file.rb
CHANGED
@@ -14,10 +14,18 @@ module Rubomop
|
|
14
14
|
self
|
15
15
|
end
|
16
16
|
|
17
|
+
def cop_for(name)
|
18
|
+
cops.select { _1.name == name }.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def active_cops
|
22
|
+
cops.select { _1.active? }
|
23
|
+
end
|
24
|
+
|
17
25
|
def output_lines
|
18
26
|
result = header.map(&:chomp)
|
19
27
|
result << ""
|
20
|
-
|
28
|
+
active_cops.each do |cop|
|
21
29
|
result += cop.output_lines
|
22
30
|
result << ""
|
23
31
|
end
|
data/lib/rubomop/version.rb
CHANGED
data/lib/rubomop.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
require "active_support/core_ext/array"
|
4
4
|
require "active_support/core_ext/string/inflections"
|
5
|
+
require "active_support/core_ext/string/inquiry"
|
5
6
|
require "awesome_print"
|
6
7
|
require "fileutils"
|
8
|
+
require "literal"
|
7
9
|
require "optparse"
|
8
10
|
require "yaml"
|
9
11
|
require "zeitwerk"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubomop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noel Rappin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: date_by_example
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,33 +39,33 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: literal
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '0'
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: zeitwerk
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
61
|
+
version: 2.7.0
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
68
|
+
version: 2.7.0
|
55
69
|
description: Rubomop cleans up after your Rubocop
|
56
70
|
email:
|
57
71
|
- noel.rappin@chime.com
|
@@ -73,7 +87,8 @@ files:
|
|
73
87
|
- exe/rubomop
|
74
88
|
- lib/rubomop.rb
|
75
89
|
- lib/rubomop/cop.rb
|
76
|
-
- lib/rubomop/
|
90
|
+
- lib/rubomop/named_mop.rb
|
91
|
+
- lib/rubomop/random_mop.rb
|
77
92
|
- lib/rubomop/runner.rb
|
78
93
|
- lib/rubomop/todo_file.rb
|
79
94
|
- lib/rubomop/version.rb
|
@@ -94,14 +109,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
109
|
requirements:
|
95
110
|
- - ">="
|
96
111
|
- !ruby/object:Gem::Version
|
97
|
-
version: 2.
|
112
|
+
version: 3.2.0
|
98
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
114
|
requirements:
|
100
115
|
- - ">="
|
101
116
|
- !ruby/object:Gem::Version
|
102
117
|
version: '0'
|
103
118
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
119
|
+
rubygems_version: 3.4.19
|
105
120
|
signing_key:
|
106
121
|
specification_version: 4
|
107
122
|
summary: Rubomop cleans up after your Rubocop
|