ruboclean 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.gitignore +1 -0
- data/.rubocop.yml +24 -0
- data/Gemfile.lock +19 -21
- data/README.md +70 -13
- data/lib/ruboclean/cli_arguments.rb +45 -15
- data/lib/ruboclean/path_cleanup.rb +9 -3
- data/lib/ruboclean/runner/options/input.rb +44 -0
- data/lib/ruboclean/runner/options/output.rb +49 -0
- data/lib/ruboclean/runner/options.rb +56 -0
- data/lib/ruboclean/runner.rb +20 -37
- data/lib/ruboclean/stream_writer.rb +21 -0
- data/lib/ruboclean/to_yaml_converter.rb +4 -8
- data/lib/ruboclean/version.rb +1 -1
- data/lib/ruboclean.rb +16 -7
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d33545be3fee0dac0b9079635c279efa82b2af8b304880314be985e39302e1
|
4
|
+
data.tar.gz: 955b57ad29b70210d72c2da05b8df40027f10323c0d4f3de09a98d4c72724faf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a906081afe314920743999bc31471cd1c6e2837281409e9babf3bb68149dd7d094eb8a0942f9efa1bd4eec7f0a354a3d5f4530a4169b1ef039c0c4f61dab460
|
7
|
+
data.tar.gz: '097a82f5d6654f12fc5104d0f463e01204dbbe3c143819c93d8567e13f6bc5d0ecb06512775732884cf3f11f63b9dc834ce77c7658689ebf3dfb2308193f9a4b'
|
data/.github/workflows/ci.yml
CHANGED
@@ -15,10 +15,10 @@ jobs:
|
|
15
15
|
fail-fast: false
|
16
16
|
matrix:
|
17
17
|
os: [ubuntu-latest]
|
18
|
-
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', head]
|
18
|
+
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head]
|
19
19
|
runs-on: ${{ matrix.os }}
|
20
20
|
steps:
|
21
|
-
- uses: actions/checkout@
|
21
|
+
- uses: actions/checkout@v4
|
22
22
|
|
23
23
|
- uses: ruby/setup-ruby@v1
|
24
24
|
with:
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -4,6 +4,9 @@ require:
|
|
4
4
|
- rubocop-minitest
|
5
5
|
- rubocop-rake
|
6
6
|
|
7
|
+
Gemspec/AddRuntimeDependency:
|
8
|
+
Enabled: true
|
9
|
+
|
7
10
|
Gemspec/DeprecatedAttributeAssignment:
|
8
11
|
Enabled: true
|
9
12
|
|
@@ -79,6 +82,9 @@ Lint/DuplicateRequire:
|
|
79
82
|
Lint/DuplicateRescueException:
|
80
83
|
Enabled: true
|
81
84
|
|
85
|
+
Lint/DuplicateSetElement:
|
86
|
+
Enabled: true
|
87
|
+
|
82
88
|
Lint/EmptyBlock:
|
83
89
|
Enabled: true
|
84
90
|
|
@@ -187,6 +193,9 @@ Lint/UnreachableLoop:
|
|
187
193
|
Lint/UselessMethodDefinition:
|
188
194
|
Enabled: true
|
189
195
|
|
196
|
+
Lint/UselessNumericOperation:
|
197
|
+
Enabled: true
|
198
|
+
|
190
199
|
Lint/UselessRescue:
|
191
200
|
Enabled: true
|
192
201
|
|
@@ -241,6 +250,9 @@ Minitest/DuplicateTestRun:
|
|
241
250
|
Minitest/EmptyLineBeforeAssertionMethods:
|
242
251
|
Enabled: true
|
243
252
|
|
253
|
+
Minitest/Focus:
|
254
|
+
Enabled: true
|
255
|
+
|
244
256
|
Minitest/LifecycleHooksOrder:
|
245
257
|
Enabled: true
|
246
258
|
|
@@ -419,6 +431,9 @@ Style/MagicCommentFormat:
|
|
419
431
|
Style/MapCompactWithConditionalBlock:
|
420
432
|
Enabled: true
|
421
433
|
|
434
|
+
Style/MapIntoArray:
|
435
|
+
Enabled: true
|
436
|
+
|
422
437
|
Style/MapToHash:
|
423
438
|
Enabled: true
|
424
439
|
|
@@ -497,6 +512,9 @@ Style/RedundantHeredocDelimiterQuotes:
|
|
497
512
|
Style/RedundantInitialize:
|
498
513
|
Enabled: true
|
499
514
|
|
515
|
+
Style/RedundantInterpolationUnfreeze:
|
516
|
+
Enabled: true
|
517
|
+
|
500
518
|
Style/RedundantLineContinuation:
|
501
519
|
Enabled: true
|
502
520
|
|
@@ -527,6 +545,9 @@ Style/ReturnNilInPredicateMethodDefinition:
|
|
527
545
|
Style/SelectByRegexp:
|
528
546
|
Enabled: true
|
529
547
|
|
548
|
+
Style/SendWithLiteralMethodName:
|
549
|
+
Enabled: true
|
550
|
+
|
530
551
|
Style/SingleArgumentDig:
|
531
552
|
Enabled: true
|
532
553
|
|
@@ -549,6 +570,9 @@ Style/StringLiterals:
|
|
549
570
|
Enabled: true
|
550
571
|
EnforcedStyle: double_quotes
|
551
572
|
|
573
|
+
Style/SuperArguments:
|
574
|
+
Enabled: true
|
575
|
+
|
552
576
|
Style/SuperWithArgsParentheses:
|
553
577
|
Enabled: true
|
554
578
|
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruboclean (0.
|
4
|
+
ruboclean (0.7.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
|
-
docile (1.4.
|
11
|
-
json (2.7.
|
10
|
+
docile (1.4.1)
|
11
|
+
json (2.7.2)
|
12
12
|
language_server-protocol (3.17.0.3)
|
13
|
-
minitest (5.
|
14
|
-
parallel (1.
|
15
|
-
parser (3.
|
13
|
+
minitest (5.25.1)
|
14
|
+
parallel (1.26.3)
|
15
|
+
parser (3.3.5.0)
|
16
16
|
ast (~> 2.4.1)
|
17
17
|
racc
|
18
|
-
racc (1.
|
18
|
+
racc (1.8.1)
|
19
19
|
rainbow (3.1.1)
|
20
|
-
rake (13.1
|
21
|
-
regexp_parser (2.
|
22
|
-
|
23
|
-
rubocop (1.59.0)
|
20
|
+
rake (13.2.1)
|
21
|
+
regexp_parser (2.9.2)
|
22
|
+
rubocop (1.67.0)
|
24
23
|
json (~> 2.3)
|
25
24
|
language_server-protocol (>= 3.17.0)
|
26
25
|
parallel (~> 1.10)
|
27
|
-
parser (>= 3.
|
26
|
+
parser (>= 3.3.0.2)
|
28
27
|
rainbow (>= 2.2.2, < 4.0)
|
29
|
-
regexp_parser (>=
|
30
|
-
|
31
|
-
rubocop-ast (>= 1.30.0, < 2.0)
|
28
|
+
regexp_parser (>= 2.4, < 3.0)
|
29
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
32
30
|
ruby-progressbar (~> 1.7)
|
33
31
|
unicode-display_width (>= 2.4.0, < 3.0)
|
34
|
-
rubocop-ast (1.
|
35
|
-
parser (>= 3.
|
36
|
-
rubocop-minitest (0.
|
37
|
-
rubocop (>= 1.
|
38
|
-
rubocop-ast (>= 1.
|
32
|
+
rubocop-ast (1.32.3)
|
33
|
+
parser (>= 3.3.1.0)
|
34
|
+
rubocop-minitest (0.36.0)
|
35
|
+
rubocop (>= 1.61, < 2.0)
|
36
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
39
37
|
rubocop-rake (0.6.0)
|
40
38
|
rubocop (~> 1.0)
|
41
39
|
ruby-progressbar (1.13.0)
|
@@ -44,7 +42,7 @@ GEM
|
|
44
42
|
json (>= 1.8, < 3)
|
45
43
|
simplecov-html (~> 0.10.0)
|
46
44
|
simplecov-html (0.10.2)
|
47
|
-
unicode-display_width (2.
|
45
|
+
unicode-display_width (2.6.0)
|
48
46
|
|
49
47
|
PLATFORMS
|
50
48
|
ruby
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
Finally it orders the configurations **alphabetically** within these groups.
|
14
14
|
|
15
|
-
##
|
15
|
+
## Main example
|
16
16
|
|
17
17
|
### Input `.rubocop.yml`:
|
18
18
|
|
@@ -66,7 +66,7 @@ Rails/ShortI18n:
|
|
66
66
|
Add this line to your application's Gemfile:
|
67
67
|
|
68
68
|
```ruby
|
69
|
-
gem
|
69
|
+
gem "ruboclean", require: false
|
70
70
|
```
|
71
71
|
|
72
72
|
And then execute:
|
@@ -84,20 +84,23 @@ gem install ruboclean
|
|
84
84
|
## Command synopsis
|
85
85
|
|
86
86
|
```shell
|
87
|
-
ruboclean [
|
87
|
+
ruboclean [input] \
|
88
|
+
[--stdin] \
|
89
|
+
[--output=/path/to/file.yml] \
|
90
|
+
[--silent] \
|
91
|
+
[--preserve-comments] \
|
92
|
+
[--preserve-paths] \
|
93
|
+
[--verify]
|
88
94
|
```
|
89
95
|
|
90
96
|
### Parameters
|
91
97
|
|
92
|
-
|
93
|
-
|:----------------------|:--------------------------------------------------------------------------------------------------------------------------------------|
|
94
|
-
| `path` | Can be a directory that contains a `.rubocop.yml`, or a path to a `.rubocop.yml` directly. Defaults to the current working directory. |
|
95
|
-
| `--silent` | Suppress any output displayed on the screen when executing the command. |
|
96
|
-
| `--preserve-comments` | Preserves **preceding** comments for each top-level entry in the configuration. Inline comments are **not** preserved. |
|
97
|
-
| `--preserve-paths` | Skips the path cleanup that are applied against `Include:` and `Exclude:` configuration. |
|
98
|
-
| `--verify` | Executes in dry-run mode. Exits with 1 if changes are needed, otherwise 0. |
|
98
|
+
#### `input`
|
99
99
|
|
100
|
-
|
100
|
+
Can be a directory that contains a `.rubocop.yml`, or a path to a `.rubocop.yml` directly.
|
101
|
+
Defaults to the current working directory.
|
102
|
+
|
103
|
+
##### Examples
|
101
104
|
|
102
105
|
```shell
|
103
106
|
ruboclean # uses `.rubocop.yml` of current working directory
|
@@ -105,6 +108,60 @@ ruboclean /path/to/dir # uses `.rubocop.yml` of /path/to/dir
|
|
105
108
|
ruboclean /path/to/dir/.rubocop.yml
|
106
109
|
```
|
107
110
|
|
111
|
+
#### `--stdin`
|
112
|
+
|
113
|
+
It's possible to read from `STDIN`, for example:
|
114
|
+
|
115
|
+
```shell
|
116
|
+
echo "SomeConfig: True" | ruboclean --stdin
|
117
|
+
```
|
118
|
+
|
119
|
+
Using `STDIN` will automatically set the output to `STDOUT`. You can use the `--output` flag to override this.
|
120
|
+
|
121
|
+
Also, if you use `STDIN`, your current working directory should be the root directory of your project, so that the
|
122
|
+
cleanup of unused paths/references (see `--preserve-paths`) works properly. If your current working directory
|
123
|
+
is something else, you have to explicitly provide the project's root directory using the `input` argument.
|
124
|
+
|
125
|
+
```shell
|
126
|
+
echo "SomeConfig: True" | ruboclean /path/to/the/project/directory --stdin
|
127
|
+
```
|
128
|
+
|
129
|
+
#### `--output=/path/to/file.yml`
|
130
|
+
|
131
|
+
Output path where the result is written to.
|
132
|
+
Can be absolute or relative to the current working directory.
|
133
|
+
`--output=STDOUT` prints it to `STDOUT` and not to a file, and silences all logging (see `--silent`).
|
134
|
+
|
135
|
+
##### Examples
|
136
|
+
|
137
|
+
```shell
|
138
|
+
ruboclean --output=/absolute/path.yml
|
139
|
+
ruboclean --output=relative/path.yml # relative to current working directory
|
140
|
+
ruboclean --output=STDOUT # does not write anything to a file
|
141
|
+
```
|
142
|
+
|
143
|
+
#### `--silent`
|
144
|
+
|
145
|
+
Suppress any log output displayed on the screen when executing the command.
|
146
|
+
Using `--output=STDOUT` also forces this.
|
147
|
+
|
148
|
+
#### `--preserve-comments`
|
149
|
+
|
150
|
+
Preserves **preceding** comments for each top-level entry in the configuration.
|
151
|
+
Inline comments are **not** preserved.
|
152
|
+
|
153
|
+
See main example above for explanation.
|
154
|
+
|
155
|
+
#### `--preserve-paths`
|
156
|
+
|
157
|
+
Skips the path cleanup that are applied against `Include:` and `Exclude:` configurations.
|
158
|
+
|
159
|
+
See main example above for explanation.
|
160
|
+
|
161
|
+
#### `--verify`
|
162
|
+
|
163
|
+
Executes in dry-run mode. Exits with `1` if changes are needed, otherwise `0`.
|
164
|
+
|
108
165
|
## Development
|
109
166
|
|
110
167
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -113,7 +170,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
113
170
|
|
114
171
|
## Contributing
|
115
172
|
|
116
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/lxxxvi/ruboclean. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lxxxvi/ruboclean/blob/
|
173
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lxxxvi/ruboclean. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lxxxvi/ruboclean/blob/main/CODE_OF_CONDUCT.md).
|
117
174
|
|
118
175
|
## License
|
119
176
|
|
@@ -121,4 +178,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
121
178
|
|
122
179
|
## Code of Conduct
|
123
180
|
|
124
|
-
Everyone interacting in the Ruboclean project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lxxxvi/ruboclean/blob/
|
181
|
+
Everyone interacting in the Ruboclean project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lxxxvi/ruboclean/blob/main/CODE_OF_CONDUCT.md).
|
@@ -3,48 +3,78 @@
|
|
3
3
|
module Ruboclean
|
4
4
|
# Reads command line arguments and exposes corresponding reader methods
|
5
5
|
class CliArguments
|
6
|
+
FLAG_DEFAULTS = {
|
7
|
+
"--stdin" => false,
|
8
|
+
"--output" => nil,
|
9
|
+
"--silent" => false,
|
10
|
+
"--preserve-comments" => false,
|
11
|
+
"--preserve-paths" => false,
|
12
|
+
"--verify" => false
|
13
|
+
}.freeze
|
14
|
+
|
6
15
|
def initialize(command_line_arguments = [])
|
7
16
|
@command_line_arguments = Array(command_line_arguments)
|
8
17
|
end
|
9
18
|
|
10
|
-
def
|
11
|
-
@
|
19
|
+
def input
|
20
|
+
@input ||= find_input
|
21
|
+
end
|
22
|
+
|
23
|
+
def stdin?
|
24
|
+
flag_arguments.fetch("--stdin")
|
12
25
|
end
|
13
26
|
|
14
|
-
def
|
15
|
-
|
27
|
+
def output
|
28
|
+
flag_arguments.fetch("--output")
|
16
29
|
end
|
17
30
|
|
18
31
|
def silent?
|
19
|
-
|
32
|
+
flag_arguments.fetch("--silent")
|
20
33
|
end
|
21
34
|
|
22
35
|
def preserve_comments?
|
23
|
-
|
36
|
+
flag_arguments.fetch("--preserve-comments")
|
24
37
|
end
|
25
38
|
|
26
39
|
def preserve_paths?
|
27
|
-
|
40
|
+
flag_arguments.fetch("--preserve-paths")
|
28
41
|
end
|
29
42
|
|
30
43
|
def verify?
|
31
|
-
|
44
|
+
flag_arguments.fetch("--verify")
|
32
45
|
end
|
33
46
|
|
34
47
|
private
|
35
48
|
|
36
49
|
attr_reader :command_line_arguments
|
37
50
|
|
38
|
-
def
|
39
|
-
command_line_arguments.first
|
40
|
-
return Dir.pwd if argument.nil? || argument.start_with?("--")
|
51
|
+
def find_input
|
52
|
+
first_argument = command_line_arguments.first
|
41
53
|
|
42
|
-
|
43
|
-
|
54
|
+
return nil if first_argument.nil? || first_argument.start_with?("--")
|
55
|
+
|
56
|
+
first_argument
|
57
|
+
end
|
58
|
+
|
59
|
+
def flag_arguments
|
60
|
+
@flag_arguments ||= FLAG_DEFAULTS.dup.merge(custom_flag_arguments)
|
44
61
|
end
|
45
62
|
|
46
|
-
def
|
47
|
-
command_line_arguments.
|
63
|
+
def custom_flag_arguments
|
64
|
+
command_line_arguments.each_with_object({}) do |item, hash|
|
65
|
+
next unless item.start_with?("--")
|
66
|
+
|
67
|
+
flag_name, flag_value = item.split("=")
|
68
|
+
|
69
|
+
raise ArgumentError, "invalid argument '#{item}'" unless FLAG_DEFAULTS.include?(flag_name)
|
70
|
+
|
71
|
+
flag_default_value = FLAG_DEFAULTS[flag_name]
|
72
|
+
|
73
|
+
hash[flag_name] = flag_value
|
74
|
+
|
75
|
+
# Subject to change: We may need to find another way to determine if an argument has Boolean characteristics
|
76
|
+
hash[flag_name] = !flag_value if flag_default_value.is_a?(FalseClass)
|
77
|
+
end
|
48
78
|
end
|
49
79
|
end
|
50
80
|
end
|
@@ -8,12 +8,14 @@ module Ruboclean
|
|
8
8
|
# If all entries in `Include` or `Exclude` are removed, the entire property is removed.
|
9
9
|
# If a Cop gets entirely truncated due to removing all `Includes` and/or `Exclude`, the Cop itself will be removed.
|
10
10
|
class PathCleanup
|
11
|
-
def initialize(configuration_hash,
|
11
|
+
def initialize(configuration_hash, options:)
|
12
12
|
@configuration_hash = configuration_hash
|
13
|
-
@
|
13
|
+
@options = options
|
14
14
|
end
|
15
15
|
|
16
16
|
def cleanup
|
17
|
+
return configuration_hash if options.preserve_paths?
|
18
|
+
|
17
19
|
configuration_hash.each_with_object({}) do |(top_level_key, top_level_value), hash|
|
18
20
|
result = process_top_level_value(top_level_value)
|
19
21
|
|
@@ -25,7 +27,11 @@ module Ruboclean
|
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
attr_reader :configuration_hash, :
|
30
|
+
attr_reader :configuration_hash, :options
|
31
|
+
|
32
|
+
def root_directory
|
33
|
+
options.input_path.dirname
|
34
|
+
end
|
29
35
|
|
30
36
|
# top_level_value could be something like this:
|
31
37
|
#
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruboclean
|
4
|
+
class Runner
|
5
|
+
class Options
|
6
|
+
# Determines the input stream
|
7
|
+
class Input
|
8
|
+
def initialize(cli_arguments:)
|
9
|
+
@cli_arguments = cli_arguments
|
10
|
+
end
|
11
|
+
|
12
|
+
def stream
|
13
|
+
@stream ||= determine_input_stream
|
14
|
+
end
|
15
|
+
|
16
|
+
def input_path
|
17
|
+
@input_path ||= find_input_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def stdin?
|
21
|
+
cli_arguments.stdin?
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :cli_arguments
|
27
|
+
|
28
|
+
def determine_input_stream
|
29
|
+
return $stdin if stdin?
|
30
|
+
|
31
|
+
return input_path if input_path.exist?
|
32
|
+
|
33
|
+
raise ArgumentError, "input path does not exist: '#{input_path}'"
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_input_path
|
37
|
+
pathname = cli_arguments.input.nil? ? Pathname.new(Dir.pwd) : Pathname.new(cli_arguments.input)
|
38
|
+
pathname = pathname.join(".rubocop.yml") if pathname.directory?
|
39
|
+
pathname
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruboclean
|
4
|
+
class Runner
|
5
|
+
class Options
|
6
|
+
# Determines the output stream
|
7
|
+
class Output
|
8
|
+
def initialize(cli_arguments:, input:)
|
9
|
+
@cli_arguments = cli_arguments
|
10
|
+
@input = input
|
11
|
+
end
|
12
|
+
|
13
|
+
def stream
|
14
|
+
@stream ||= determine_output_stream
|
15
|
+
end
|
16
|
+
|
17
|
+
def stdout?
|
18
|
+
(cli_arguments.output.nil? && input.stdin?) ||
|
19
|
+
cli_arguments.output == "STDOUT"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :cli_arguments, :input
|
25
|
+
|
26
|
+
def determine_output_stream
|
27
|
+
return $stdout if stdout?
|
28
|
+
|
29
|
+
output_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def output_path
|
33
|
+
@output_path ||= find_output_path
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_output_path
|
37
|
+
return input.stream if cli_arguments.output.nil?
|
38
|
+
|
39
|
+
pathname = Pathname.new(cli_arguments.output)
|
40
|
+
pathname = Pathname.new(Dir.pwd).join(pathname) if pathname.relative?
|
41
|
+
|
42
|
+
return pathname unless pathname.directory?
|
43
|
+
|
44
|
+
raise ArgumentError, "output path (--output=#{pathname}) cannot be a directory"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruboclean
|
4
|
+
class Runner
|
5
|
+
# Consolidates cli_arguments with "smart" defaults
|
6
|
+
class Options
|
7
|
+
def initialize(cli_arguments:)
|
8
|
+
@cli_arguments = cli_arguments
|
9
|
+
end
|
10
|
+
|
11
|
+
def input_stream
|
12
|
+
input.stream
|
13
|
+
end
|
14
|
+
|
15
|
+
def input_path
|
16
|
+
input.input_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def output_stream
|
20
|
+
output.stream
|
21
|
+
end
|
22
|
+
|
23
|
+
def verbose?
|
24
|
+
!silent?
|
25
|
+
end
|
26
|
+
|
27
|
+
def silent?
|
28
|
+
cli_arguments.silent? || output.stdout?
|
29
|
+
end
|
30
|
+
|
31
|
+
def preserve_comments?
|
32
|
+
cli_arguments.preserve_comments?
|
33
|
+
end
|
34
|
+
|
35
|
+
def preserve_paths?
|
36
|
+
cli_arguments.preserve_paths?
|
37
|
+
end
|
38
|
+
|
39
|
+
def verify?
|
40
|
+
cli_arguments.verify?
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :cli_arguments
|
46
|
+
|
47
|
+
def input
|
48
|
+
@input ||= Ruboclean::Runner::Options::Input.new(cli_arguments: cli_arguments)
|
49
|
+
end
|
50
|
+
|
51
|
+
def output
|
52
|
+
@output ||= Ruboclean::Runner::Options::Output.new(cli_arguments: cli_arguments, input: input)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ruboclean/runner.rb
CHANGED
@@ -6,18 +6,19 @@ require "yaml"
|
|
6
6
|
module Ruboclean
|
7
7
|
# Entry point for processing
|
8
8
|
class Runner
|
9
|
-
def initialize(
|
10
|
-
|
9
|
+
def initialize(command_line_arguments = [])
|
10
|
+
cli_arguments = CliArguments.new(command_line_arguments)
|
11
|
+
@options = Runner::Options.new(cli_arguments: cli_arguments)
|
11
12
|
end
|
12
13
|
|
13
14
|
def run!
|
14
|
-
return if
|
15
|
+
return if source_yaml.empty?
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
parse_yaml.then(&method(:order))
|
18
|
+
.then(&method(:cleanup_paths))
|
19
|
+
.then(&method(:convert_to_yaml))
|
20
|
+
.then(&method(:write_stream!))
|
21
|
+
.then(&method(:changed?))
|
21
22
|
end
|
22
23
|
|
23
24
|
def changed?(target_yaml)
|
@@ -25,26 +26,26 @@ module Ruboclean
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def verbose?
|
28
|
-
|
29
|
+
options.verbose?
|
29
30
|
end
|
30
31
|
|
31
32
|
def verify?
|
32
|
-
|
33
|
+
options.verify?
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
-
|
36
|
+
def input_path
|
37
|
+
options.input_path
|
37
38
|
end
|
38
39
|
|
39
40
|
private
|
40
41
|
|
41
|
-
attr_reader :
|
42
|
+
attr_reader :options
|
42
43
|
|
43
44
|
def source_yaml
|
44
|
-
@source_yaml ||=
|
45
|
+
@source_yaml ||= options.input_stream.read
|
45
46
|
end
|
46
47
|
|
47
|
-
def
|
48
|
+
def parse_yaml
|
48
49
|
YAML.safe_load(source_yaml, permitted_classes: [Regexp])
|
49
50
|
end
|
50
51
|
|
@@ -53,33 +54,15 @@ module Ruboclean
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def cleanup_paths(configuration_hash)
|
56
|
-
|
57
|
-
|
58
|
-
PathCleanup.new(configuration_hash, source_file_pathname.dirname).cleanup
|
57
|
+
PathCleanup.new(configuration_hash, options: options).cleanup
|
59
58
|
end
|
60
59
|
|
61
60
|
def convert_to_yaml(configuration_hash)
|
62
|
-
ToYamlConverter.new(configuration_hash,
|
63
|
-
end
|
64
|
-
|
65
|
-
def write_file!(target_yaml)
|
66
|
-
target_yaml.tap do |content|
|
67
|
-
source_file_pathname.write(content) unless verify?
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def source_file_pathname
|
72
|
-
@source_file_pathname ||= find_source_file_pathname
|
61
|
+
ToYamlConverter.new(configuration_hash, source_yaml, options: options).to_yaml
|
73
62
|
end
|
74
63
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
source_path = source_path.join(".rubocop.yml") if source_path.directory?
|
79
|
-
|
80
|
-
return source_path if source_path.exist?
|
81
|
-
|
82
|
-
raise ArgumentError, "path does not exist: '#{source_path}'"
|
64
|
+
def write_stream!(target_yaml)
|
65
|
+
StreamWriter.new(target_yaml, options: options).write!
|
83
66
|
end
|
84
67
|
end
|
85
68
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ruboclean
|
4
|
+
# Orders the items within the groups alphabetically
|
5
|
+
class StreamWriter
|
6
|
+
def initialize(content, options:)
|
7
|
+
@content = content
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def write!
|
12
|
+
options.output_stream.write(content) unless options.verify?
|
13
|
+
|
14
|
+
content
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :content, :options
|
20
|
+
end
|
21
|
+
end
|
@@ -3,27 +3,23 @@
|
|
3
3
|
module Ruboclean
|
4
4
|
# Converts the configuration hash to YAML and applies modifications on it, if requested
|
5
5
|
class ToYamlConverter
|
6
|
-
def initialize(configuration_hash,
|
6
|
+
def initialize(configuration_hash, source_yaml, options:)
|
7
7
|
@configuration_hash = configuration_hash
|
8
|
-
@preserve_comments = preserve_comments
|
9
8
|
@source_yaml = source_yaml
|
9
|
+
@options = options
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_yaml
|
13
13
|
target_yaml = sanitize_yaml(configuration_hash.transform_keys(&:to_s).to_yaml)
|
14
14
|
|
15
|
-
return target_yaml unless preserve_comments?
|
15
|
+
return target_yaml unless options.preserve_comments?
|
16
16
|
|
17
17
|
preserve_preceding_comments(source_yaml, target_yaml)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
attr_reader :configuration_hash, :
|
23
|
-
|
24
|
-
def preserve_comments?
|
25
|
-
preserve_comments
|
26
|
-
end
|
22
|
+
attr_reader :configuration_hash, :source_yaml, :options
|
27
23
|
|
28
24
|
def sanitize_yaml(data)
|
29
25
|
data.gsub(/^([a-zA-Z]+)/, "\n\\1")
|
data/lib/ruboclean/version.rb
CHANGED
data/lib/ruboclean.rb
CHANGED
@@ -6,20 +6,29 @@ require "ruboclean/logger"
|
|
6
6
|
require "ruboclean/grouper"
|
7
7
|
require "ruboclean/path_cleanup"
|
8
8
|
require "ruboclean/runner"
|
9
|
+
require "ruboclean/runner/options"
|
10
|
+
require "ruboclean/runner/options/input"
|
11
|
+
require "ruboclean/runner/options/output"
|
12
|
+
require "ruboclean/stream_writer"
|
9
13
|
require "ruboclean/to_yaml_converter"
|
10
14
|
require "ruboclean/version"
|
11
15
|
|
12
16
|
# Ruboclean entry point
|
13
17
|
module Ruboclean
|
14
|
-
def self.run_from_cli!(args)
|
15
|
-
|
16
|
-
|
18
|
+
def self.run_from_cli!(args) # rubocop:disable Metrics/MethodLength
|
19
|
+
if args.include?("--version")
|
20
|
+
print Ruboclean::VERSION
|
21
|
+
else
|
22
|
+
runner = Runner.new(args)
|
23
|
+
logger = Ruboclean::Logger.new(runner.verbose? ? :verbose : :none)
|
24
|
+
|
25
|
+
logger.verbose "Using input path '#{runner.input_path}' ... "
|
26
|
+
changed = runner.run!
|
27
|
+
logger.verbose post_execution_message(changed, runner.verify?)
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
logger.verbose post_execution_message(changed, runner.verify?)
|
29
|
+
exit !changed if runner.verify?
|
30
|
+
end
|
21
31
|
|
22
|
-
exit !changed if runner.verify?
|
23
32
|
exit 0
|
24
33
|
end
|
25
34
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboclean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lxxxvi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Cleans and orders settings in .rubocop.yml
|
14
14
|
email:
|
@@ -38,6 +38,10 @@ files:
|
|
38
38
|
- lib/ruboclean/orderer.rb
|
39
39
|
- lib/ruboclean/path_cleanup.rb
|
40
40
|
- lib/ruboclean/runner.rb
|
41
|
+
- lib/ruboclean/runner/options.rb
|
42
|
+
- lib/ruboclean/runner/options/input.rb
|
43
|
+
- lib/ruboclean/runner/options/output.rb
|
44
|
+
- lib/ruboclean/stream_writer.rb
|
41
45
|
- lib/ruboclean/to_yaml_converter.rb
|
42
46
|
- lib/ruboclean/version.rb
|
43
47
|
- ruboclean.gemspec
|
@@ -64,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
68
|
- !ruby/object:Gem::Version
|
65
69
|
version: '0'
|
66
70
|
requirements: []
|
67
|
-
rubygems_version: 3.5.
|
71
|
+
rubygems_version: 3.5.23
|
68
72
|
signing_key:
|
69
73
|
specification_version: 4
|
70
74
|
summary: Cleans and orders settings in .rubocop.yml
|