ruboclean 0.2.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 837aa85e87f68e67b33c4823a8d8e7d121e4f7da094f08d69965343fd5633ab6
4
- data.tar.gz: 10ef204409cceadbea450b54d05b60473b8ad47676a7b958d73b2204722e972d
3
+ metadata.gz: 4d44db013c200c2aa27fb69d03ba72a9160fdff84c32fd337616c741f665fc02
4
+ data.tar.gz: 506a81ba8570624d6a7694b634c5daeca924049ec4a799cc8d3634500908aa5d
5
5
  SHA512:
6
- metadata.gz: a2797e99e1aaac4b460230fb67381377c339047d38cf689a784aa678201f326ebc924628b470c86df2cc24ef917f89a4d686d3a490010f39878dcab6f2acec43
7
- data.tar.gz: f432dae557d42f76bf41aa2fa684a6f0465adfd310f7137670aad9aa8646757cda25f5e80585eba95e70005d22e55255016122b8ee8c8aa280bd647dd2f2e83e
6
+ metadata.gz: 46aefeee7846f41223c011cba0926d1a4554c9c9072ed05b3d346d584f1e71a76ded64daf6648956b6d707d82388696fa4ae2729560f710ad9d1cd522b30f8b1
7
+ data.tar.gz: b4b699189ad6cced7bb0beeed940550217c0d14c140b6d20eb3f25876ecd23415436bdd91f106d9cc33a57c0a52582e58515159854d37a3ac860c1d3be1d46ad
@@ -1,33 +1,29 @@
1
1
  env:
2
- RUBY_VERSION: 2.7
3
2
  CC_TEST_REPORTER_BINARY_URL: https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
4
3
  CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
5
4
 
6
5
  name: Continuous Integration
7
- on: [push, pull_request]
6
+ on:
7
+ push:
8
+ branches:
9
+ - 'main' # Set a branch to deploy
10
+ pull_request:
8
11
 
9
12
  jobs:
10
13
  test:
11
- name: Run bin/test
12
- runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ os: [ubuntu-latest]
18
+ ruby: ['2.7', '3.0', '3.1', '3.2', head]
19
+ runs-on: ${{ matrix.os }}
13
20
  steps:
14
- - uses: actions/checkout@v1
21
+ - uses: actions/checkout@v3
15
22
 
16
23
  - uses: ruby/setup-ruby@v1
17
24
  with:
18
- ruby-version: ${{ env.RUBY_VERSION }}
19
-
20
- # install gems
21
- - name: Cache Ruby gems
22
- uses: actions/cache@v2
23
- with:
24
- path: vendor/bundle
25
- key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
26
-
27
- - name: Bundle install
28
- run: |
29
- bundle config path vendor/bundle
30
- bundle install --jobs 4 --retry 3
25
+ ruby-version: ${{ matrix.ruby }}
26
+ bundler-cache: true
31
27
 
32
28
  # prepare CC test reporter
33
29
  - name: Download CC test reporter binary
data/.rubocop.yml CHANGED
@@ -1,107 +1,376 @@
1
1
  ---
2
2
 
3
+ require:
4
+ - rubocop-minitest
5
+ - rubocop-rake
6
+
7
+ Gemspec/DeprecatedAttributeAssignment:
8
+ Enabled: true
9
+
10
+ Gemspec/DevelopmentDependencies:
11
+ Enabled: true
12
+
13
+ Gemspec/RequireMFA:
14
+ Enabled: true
15
+
3
16
  Layout/BeginEndAlignment:
4
17
  Enabled: true
5
18
 
6
19
  Layout/EmptyLinesAroundAttributeAccessor:
7
20
  Enabled: true
8
21
 
22
+ Layout/LineContinuationLeadingSpace:
23
+ Enabled: true
24
+
25
+ Layout/LineContinuationSpacing:
26
+ Enabled: true
27
+
28
+ Layout/LineEndStringConcatenationIndentation:
29
+ Enabled: true
30
+
9
31
  Layout/SpaceAroundMethodCallOperator:
10
32
  Enabled: true
11
33
 
34
+ Layout/SpaceBeforeBrackets:
35
+ Enabled: true
36
+
37
+ Lint/AmbiguousAssignment:
38
+ Enabled: true
39
+
40
+ Lint/AmbiguousOperatorPrecedence:
41
+ Enabled: true
42
+
43
+ Lint/AmbiguousRange:
44
+ Enabled: true
45
+
12
46
  Lint/BinaryOperatorWithIdenticalOperands:
13
47
  Enabled: true
14
48
 
15
49
  Lint/ConstantDefinitionInBlock:
16
50
  Enabled: true
17
51
 
52
+ Lint/ConstantOverwrittenInRescue:
53
+ Enabled: true
54
+
55
+ Lint/DeprecatedConstants:
56
+ Enabled: true
57
+
18
58
  Lint/DeprecatedOpenSSLConstant:
19
59
  Enabled: true
20
60
 
61
+ Lint/DuplicateBranch:
62
+ Enabled: true
63
+
21
64
  Lint/DuplicateElsifCondition:
22
65
  Enabled: true
23
66
 
67
+ Lint/DuplicateMagicComment:
68
+ Enabled: true
69
+
70
+ Lint/DuplicateMatchPattern:
71
+ Enabled: true
72
+
73
+ Lint/DuplicateRegexpCharacterClassElement:
74
+ Enabled: true
75
+
24
76
  Lint/DuplicateRequire:
25
77
  Enabled: true
26
78
 
27
79
  Lint/DuplicateRescueException:
28
80
  Enabled: true
29
81
 
82
+ Lint/EmptyBlock:
83
+ Enabled: true
84
+
85
+ Lint/EmptyClass:
86
+ Enabled: true
87
+
30
88
  Lint/EmptyConditionalBody:
31
89
  Enabled: true
32
90
 
33
91
  Lint/EmptyFile:
34
92
  Enabled: true
35
93
 
94
+ Lint/EmptyInPattern:
95
+ Enabled: true
96
+
36
97
  Lint/FloatComparison:
37
98
  Enabled: true
38
99
 
39
100
  Lint/IdentityComparison:
40
101
  Enabled: true
41
102
 
103
+ Lint/IncompatibleIoSelectWithFiberScheduler:
104
+ Enabled: true
105
+
106
+ Lint/LambdaWithoutLiteralBlock:
107
+ Enabled: true
108
+
42
109
  Lint/MissingSuper:
43
110
  Enabled: true
44
111
 
45
112
  Lint/MixedRegexpCaptureTypes:
46
113
  Enabled: true
47
114
 
115
+ Lint/NoReturnInBeginEndBlocks:
116
+ Enabled: true
117
+
118
+ Lint/NonAtomicFileOperation:
119
+ Enabled: true
120
+
121
+ Lint/NumberedParameterAssignment:
122
+ Enabled: true
123
+
124
+ Lint/OrAssignmentToConstant:
125
+ Enabled: true
126
+
48
127
  Lint/OutOfRangeRegexpRef:
49
128
  Enabled: true
50
129
 
51
130
  Lint/RaiseException:
52
131
  Enabled: true
53
132
 
133
+ Lint/RedundantDirGlobSort:
134
+ Enabled: true
135
+
136
+ Lint/RefinementImportMethods:
137
+ Enabled: true
138
+
139
+ Lint/RequireRangeParentheses:
140
+ Enabled: true
141
+
142
+ Lint/RequireRelativeSelfPath:
143
+ Enabled: true
144
+
54
145
  Lint/SelfAssignment:
55
146
  Enabled: true
56
147
 
57
148
  Lint/StructNewOverride:
58
149
  Enabled: true
59
150
 
151
+ Lint/SymbolConversion:
152
+ Enabled: true
153
+
154
+ Lint/ToEnumArguments:
155
+ Enabled: true
156
+
60
157
  Lint/TopLevelReturnWithArgument:
61
158
  Enabled: true
62
159
 
63
160
  Lint/TrailingCommaInAttributeDeclaration:
64
161
  Enabled: true
65
162
 
163
+ Lint/TripleQuotes:
164
+ Enabled: true
165
+
166
+ Lint/UnexpectedBlockArity:
167
+ Enabled: true
168
+
169
+ Lint/UnmodifiedReduceAccumulator:
170
+ Enabled: true
171
+
66
172
  Lint/UnreachableLoop:
67
173
  Enabled: true
68
174
 
69
175
  Lint/UselessMethodDefinition:
70
176
  Enabled: true
71
177
 
178
+ Lint/UselessRescue:
179
+ Enabled: true
180
+
181
+ Lint/UselessRuby2Keywords:
182
+ Enabled: true
183
+
72
184
  Lint/UselessTimes:
73
185
  Enabled: true
74
186
 
187
+ Metrics/CollectionLiteralLength:
188
+ Enabled: true
189
+
190
+ Minitest/AssertInDelta:
191
+ Enabled: true
192
+
193
+ Minitest/AssertKindOf:
194
+ Enabled: true
195
+
196
+ Minitest/AssertOutput:
197
+ Enabled: true
198
+
199
+ Minitest/AssertPathExists:
200
+ Enabled: true
201
+
202
+ Minitest/AssertPredicate:
203
+ Enabled: true
204
+
205
+ Minitest/AssertRaisesCompoundBody:
206
+ Enabled: true
207
+
208
+ Minitest/AssertRaisesWithRegexpArgument:
209
+ Enabled: true
210
+
211
+ Minitest/AssertSame:
212
+ Enabled: true
213
+
214
+ Minitest/AssertSilent:
215
+ Enabled: true
216
+
217
+ Minitest/AssertWithExpectedArgument:
218
+ Enabled: true
219
+
220
+ Minitest/AssertionInLifecycleHook:
221
+ Enabled: true
222
+
223
+ Minitest/DuplicateTestRun:
224
+ Enabled: true
225
+
226
+ Minitest/EmptyLineBeforeAssertionMethods:
227
+ Enabled: true
228
+
229
+ Minitest/LifecycleHooksOrder:
230
+ Enabled: true
231
+
232
+ Minitest/LiteralAsActualArgument:
233
+ Enabled: true
234
+
235
+ Minitest/MultipleAssertions:
236
+ Enabled: true
237
+ Max: 5
238
+
239
+ Minitest/NonPublicTestMethod:
240
+ Enabled: true
241
+
242
+ Minitest/RefuteInDelta:
243
+ Enabled: true
244
+
245
+ Minitest/RefuteKindOf:
246
+ Enabled: true
247
+
248
+ Minitest/RefutePathExists:
249
+ Enabled: true
250
+
251
+ Minitest/RefutePredicate:
252
+ Enabled: true
253
+
254
+ Minitest/RefuteSame:
255
+ Enabled: true
256
+
257
+ Minitest/ReturnInTestMethod:
258
+ Enabled: true
259
+
260
+ Minitest/SkipEnsure:
261
+ Enabled: true
262
+
263
+ Minitest/SkipWithoutReason:
264
+ Enabled: true
265
+
266
+ Minitest/TestFileName:
267
+ Enabled: true
268
+
269
+ Minitest/TestMethodName:
270
+ Enabled: true
271
+
272
+ Minitest/UnreachableAssertion:
273
+ Enabled: true
274
+
275
+ Minitest/UnspecifiedException:
276
+ Enabled: true
277
+
278
+ Minitest/UselessAssertion:
279
+ Enabled: true
280
+
281
+ Naming/BlockForwarding:
282
+ Enabled: true
283
+
284
+ Security/CompoundHash:
285
+ Enabled: true
286
+
287
+ Security/IoMethods:
288
+ Enabled: true
289
+
75
290
  Style/AccessorGrouping:
76
291
  Enabled: true
77
292
 
293
+ Style/ArgumentsForwarding:
294
+ Enabled: true
295
+
78
296
  Style/ArrayCoercion:
79
297
  Enabled: true
80
298
 
299
+ Style/ArrayIntersect:
300
+ Enabled: true
301
+
81
302
  Style/BisectedAttrAccessor:
82
303
  Enabled: true
83
304
 
84
305
  Style/CaseLikeIf:
85
306
  Enabled: true
86
307
 
308
+ Style/CollectionCompact:
309
+ Enabled: true
310
+
87
311
  Style/CombinableLoops:
88
312
  Enabled: true
89
313
 
314
+ Style/ComparableClamp:
315
+ Enabled: true
316
+
317
+ Style/ConcatArrayLiterals:
318
+ Enabled: true
319
+
320
+ Style/DataInheritance:
321
+ Enabled: true
322
+
323
+ Style/DirEmpty:
324
+ Enabled: true
325
+
326
+ Style/DocumentDynamicEvalDefinition:
327
+ Enabled: true
328
+
329
+ Style/EmptyHeredoc:
330
+ Enabled: true
331
+
332
+ Style/EndlessMethod:
333
+ Enabled: true
334
+
335
+ Style/EnvHome:
336
+ Enabled: true
337
+
338
+ Style/ExactRegexpMatch:
339
+ Enabled: true
340
+
90
341
  Style/ExplicitBlockArgument:
91
342
  Enabled: true
92
343
 
93
344
  Style/ExponentialNotation:
94
345
  Enabled: true
95
346
 
347
+ Style/FetchEnvVar:
348
+ Enabled: true
349
+
350
+ Style/FileEmpty:
351
+ Enabled: true
352
+
353
+ Style/FileRead:
354
+ Enabled: true
355
+
356
+ Style/FileWrite:
357
+ Enabled: true
358
+
96
359
  Style/GlobalStdStream:
97
360
  Enabled: true
98
361
 
99
362
  Style/HashAsLastArrayItem:
100
363
  Enabled: true
101
364
 
365
+ Style/HashConversion:
366
+ Enabled: true
367
+
102
368
  Style/HashEachMethods:
103
369
  Enabled: true
104
370
 
371
+ Style/HashExcept:
372
+ Enabled: true
373
+
105
374
  Style/HashLikeCase:
106
375
  Enabled: true
107
376
 
@@ -111,30 +380,120 @@ Style/HashTransformKeys:
111
380
  Style/HashTransformValues:
112
381
  Enabled: true
113
382
 
383
+ Style/IfWithBooleanLiteralBranches:
384
+ Enabled: true
385
+
386
+ Style/InPatternThen:
387
+ Enabled: true
388
+
114
389
  Style/KeywordParametersOrder:
115
390
  Enabled: true
116
391
 
392
+ Style/MagicCommentFormat:
393
+ Enabled: true
394
+
395
+ Style/MapCompactWithConditionalBlock:
396
+ Enabled: true
397
+
398
+ Style/MapToHash:
399
+ Enabled: true
400
+
401
+ Style/MapToSet:
402
+ Enabled: true
403
+
404
+ Style/MinMaxComparison:
405
+ Enabled: true
406
+
407
+ Style/MultilineInPatternThen:
408
+ Enabled: true
409
+
410
+ Style/NegatedIfElseCondition:
411
+ Enabled: true
412
+
413
+ Style/NestedFileDirname:
414
+ Enabled: true
415
+
416
+ Style/NilLambda:
417
+ Enabled: true
418
+
419
+ Style/NumberedParameters:
420
+ Enabled: true
421
+
422
+ Style/NumberedParametersLimit:
423
+ Enabled: true
424
+
425
+ Style/ObjectThen:
426
+ Enabled: true
427
+
428
+ Style/OpenStructUse:
429
+ Enabled: true
430
+
431
+ Style/OperatorMethodCall:
432
+ Enabled: true
433
+
117
434
  Style/OptionalBooleanParameter:
118
435
  Enabled: true
119
436
 
437
+ Style/QuotedSymbols:
438
+ Enabled: true
439
+
440
+ Style/RedundantArgument:
441
+ Enabled: true
442
+
443
+ Style/RedundantArrayConstructor:
444
+ Enabled: true
445
+
120
446
  Style/RedundantAssignment:
121
447
  Enabled: true
122
448
 
449
+ Style/RedundantConstantBase:
450
+ Enabled: true
451
+
452
+ Style/RedundantDoubleSplatHashBraces:
453
+ Enabled: true
454
+
455
+ Style/RedundantEach:
456
+ Enabled: true
457
+
123
458
  Style/RedundantFetchBlock:
124
459
  Enabled: true
125
460
 
126
461
  Style/RedundantFileExtensionInRequire:
127
462
  Enabled: true
128
463
 
464
+ Style/RedundantFilterChain:
465
+ Enabled: true
466
+
467
+ Style/RedundantHeredocDelimiterQuotes:
468
+ Enabled: true
469
+
470
+ Style/RedundantInitialize:
471
+ Enabled: true
472
+
473
+ Style/RedundantLineContinuation:
474
+ Enabled: true
475
+
129
476
  Style/RedundantRegexpCharacterClass:
130
477
  Enabled: true
131
478
 
479
+ Style/RedundantRegexpConstructor:
480
+ Enabled: true
481
+
132
482
  Style/RedundantRegexpEscape:
133
483
  Enabled: true
134
484
 
135
485
  Style/RedundantSelfAssignment:
136
486
  Enabled: true
137
487
 
488
+ Style/RedundantSelfAssignmentBranch:
489
+ Enabled: true
490
+
491
+ Style/RedundantStringEscape:
492
+ Enabled: true
493
+
494
+ Style/SelectByRegexp:
495
+ Enabled: true
496
+
138
497
  Style/SingleArgumentDig:
139
498
  Enabled: true
140
499
 
@@ -144,5 +503,18 @@ Style/SlicingWithRange:
144
503
  Style/SoleNestedConditional:
145
504
  Enabled: true
146
505
 
506
+ Style/StringChars:
507
+ Enabled: true
508
+
147
509
  Style/StringConcatenation:
148
510
  Enabled: true
511
+
512
+ Style/StringLiterals:
513
+ Enabled: true
514
+ EnforcedStyle: double_quotes
515
+
516
+ Style/SwapValues:
517
+ Enabled: true
518
+
519
+ Style/YodaExpression:
520
+ Enabled: true
data/Gemfile CHANGED
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
7
  group :development do
8
- gem 'minitest'
9
- gem 'rake'
10
- gem 'rubocop'
11
- gem 'simplecov', '< 0.18'
8
+ gem "minitest"
9
+ gem "rake"
10
+ gem "rubocop"
11
+ gem "rubocop-minitest", require: false
12
+ gem "rubocop-rake", require: false
13
+ gem "simplecov", "< 0.18"
12
14
  end
data/Gemfile.lock CHANGED
@@ -1,40 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruboclean (0.2.1)
4
+ ruboclean (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- docile (1.3.5)
11
- json (2.5.1)
12
- minitest (5.14.4)
13
- parallel (1.20.1)
14
- parser (3.0.1.0)
10
+ docile (1.4.0)
11
+ json (2.6.3)
12
+ minitest (5.18.0)
13
+ parallel (1.23.0)
14
+ parser (3.2.2.3)
15
15
  ast (~> 2.4.1)
16
- rainbow (3.0.0)
17
- rake (13.0.3)
18
- regexp_parser (2.1.1)
16
+ racc
17
+ racc (1.7.0)
18
+ rainbow (3.1.1)
19
+ rake (13.0.6)
20
+ regexp_parser (2.8.0)
19
21
  rexml (3.2.5)
20
- rubocop (1.13.0)
22
+ rubocop (1.52.0)
23
+ json (~> 2.3)
21
24
  parallel (~> 1.10)
22
- parser (>= 3.0.0.0)
25
+ parser (>= 3.2.0.0)
23
26
  rainbow (>= 2.2.2, < 4.0)
24
27
  regexp_parser (>= 1.8, < 3.0)
25
- rexml
26
- rubocop-ast (>= 1.2.0, < 2.0)
28
+ rexml (>= 3.2.5, < 4.0)
29
+ rubocop-ast (>= 1.28.0, < 2.0)
27
30
  ruby-progressbar (~> 1.7)
28
- unicode-display_width (>= 1.4.0, < 3.0)
29
- rubocop-ast (1.4.1)
30
- parser (>= 2.7.1.5)
31
- ruby-progressbar (1.11.0)
31
+ unicode-display_width (>= 2.4.0, < 3.0)
32
+ rubocop-ast (1.29.0)
33
+ parser (>= 3.2.1.0)
34
+ rubocop-minitest (0.31.0)
35
+ rubocop (>= 1.39, < 2.0)
36
+ rubocop-rake (0.6.0)
37
+ rubocop (~> 1.0)
38
+ ruby-progressbar (1.13.0)
32
39
  simplecov (0.17.1)
33
40
  docile (~> 1.1)
34
41
  json (>= 1.8, < 3)
35
42
  simplecov-html (~> 0.10.0)
36
43
  simplecov-html (0.10.2)
37
- unicode-display_width (2.0.0)
44
+ unicode-display_width (2.4.2)
38
45
 
39
46
  PLATFORMS
40
47
  ruby
@@ -44,7 +51,9 @@ DEPENDENCIES
44
51
  rake
45
52
  ruboclean!
46
53
  rubocop
54
+ rubocop-minitest
55
+ rubocop-rake
47
56
  simplecov (< 0.18)
48
57
 
49
58
  BUNDLED WITH
50
- 2.2.3
59
+ 2.4.13
data/README.md CHANGED
@@ -30,8 +30,9 @@ AllCops:
30
30
  Exclude:
31
31
  - bin/**/*
32
32
 
33
+ # Preceding comments will be removed unless the --preserve-comments option is used.
33
34
  require:
34
- - rubocop-rails
35
+ - rubocop-rails # Inline comments will always be removed.
35
36
  ```
36
37
 
37
38
  ### Output `.rubocop.yml`:
@@ -54,10 +55,8 @@ Layout/LineLength:
54
55
 
55
56
  Rails/ShortI18n:
56
57
  Enabled: true
57
-
58
58
  ```
59
59
 
60
-
61
60
  ## Installation
62
61
 
63
62
  Add this line to your application's Gemfile:
@@ -78,27 +77,25 @@ Or install it yourself as:
78
77
  gem install ruboclean
79
78
  ```
80
79
 
81
- ## Usage
80
+ ## Command synopsis
82
81
 
83
82
  ```shell
84
- ruboclean [path]
83
+ ruboclean [path] [--silent] [--preserve-comments]
85
84
  ```
86
85
 
87
- * `path` is optional, it defaults to the current working directory
88
- * `path` can be a directory that contains a `.rubocop.yml`
89
- * `path` can be a path to a `.rubocop.yml` directly
86
+ ### Parameters
90
87
 
91
- ### Examples
88
+ | Parameter | Description |
89
+ |:-|:-|
90
+ | `path` | Can be a directory that contains a `.rubocop.yml`, or a path to a `.rubocop.yml` directly. Defaults to the current working directory. |
91
+ | `--silent` | Suppress any output displayed on the screen when executing the command. |
92
+ | `--preserve-comments` | Preserves **preceding** comments for each top-level entry in the configuration. Inline comments are **not** preserved. |
92
93
 
93
- ```shell
94
- ruboclean # uses `.rubocop.yml` of current working directory
95
- ```
96
-
97
- ```shell
98
- ruboclean /path/to/dir # uses `.rubocop.yml` of /path/to/dir
99
- ```
94
+ ### Examples
100
95
 
101
96
  ```shell
97
+ ruboclean # uses `.rubocop.yml` of current working directory
98
+ ruboclean /path/to/dir # uses `.rubocop.yml` of /path/to/dir
102
99
  ruboclean /path/to/dir/.rubocop.yml
103
100
  ```
104
101
 
@@ -112,7 +109,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
112
109
 
113
110
  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/master/CODE_OF_CONDUCT.md).
114
111
 
115
-
116
112
  ## License
117
113
 
118
114
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rake/testtask'
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
- t.libs << 'test'
8
- t.libs << 'lib'
9
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
10
  end
11
11
 
12
12
  task default: :test
data/bin/console CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
- require 'bundler/setup'
6
- require 'ruboclean'
5
+ require "bundler/setup"
6
+ require "ruboclean"
7
7
 
8
8
  # You can add fixtures and/or initialization code here to make experimenting
9
9
  # with your gem easier. You can also use a different console, if you like.
@@ -12,5 +12,5 @@ require 'ruboclean'
12
12
  # require 'pry'
13
13
  # Pry.start
14
14
 
15
- require 'irb'
15
+ require "irb"
16
16
  IRB.start(__FILE__)
data/bin/ruboclean CHANGED
@@ -2,10 +2,5 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
- require 'ruboclean'
6
-
7
- path = ARGV[0] || Dir.pwd
8
-
9
- print "Using path '#{path}' ... "
10
- Ruboclean.run(path)
11
- puts 'done.'
5
+ require "ruboclean"
6
+ Ruboclean.run_from_cli!(ARGV)
data/bin/test CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
- require 'fileutils'
5
+ require "fileutils"
6
6
 
7
7
  # Runs all tests and linters
8
8
  class BinTest
9
9
  include FileUtils
10
10
 
11
- APP_ROOT = File.expand_path('..', __dir__)
11
+ APP_ROOT = File.expand_path("..", __dir__)
12
12
 
13
13
  def system!(*args)
14
14
  system(*args) || abort("\n== Command #{args} failed ==")
@@ -17,10 +17,10 @@ class BinTest
17
17
  def run
18
18
  chdir APP_ROOT do
19
19
  puts "\n== Run tests =="
20
- system! 'bundle exec rake test'
20
+ system! "bundle exec rake test"
21
21
 
22
22
  puts "\n== Run rubocop =="
23
- system! 'bundle exec rubocop -p'
23
+ system! "bundle exec rubocop --parallel"
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruboclean
4
+ # Reads command line arguments and exposes corresponding reader methods
5
+ class Arguments
6
+ def initialize(command_line_arguments = [])
7
+ @command_line_arguments = Array(command_line_arguments)
8
+ end
9
+
10
+ def path
11
+ @path ||= find_path
12
+ end
13
+
14
+ def verbose?
15
+ !silent?
16
+ end
17
+
18
+ def silent?
19
+ @silent ||= find_argument("--silent")
20
+ end
21
+
22
+ def preserve_comments?
23
+ @preserve_comments ||= find_argument("--preserve-comments")
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :command_line_arguments
29
+
30
+ def find_path
31
+ command_line_arguments.first.then do |argument|
32
+ return Dir.pwd if argument.nil? || argument.start_with?("--")
33
+
34
+ argument
35
+ end
36
+ end
37
+
38
+ def find_argument(name)
39
+ command_line_arguments.any? { |argument| argument == name }
40
+ end
41
+ end
42
+ end
@@ -14,7 +14,7 @@ module Ruboclean
14
14
  @config_hash.each_with_object(empty_groups) do |item, result|
15
15
  key, value = item
16
16
  target_group = find_target_group(key)
17
- result[target_group].merge! Hash[key, value]
17
+ result[target_group].merge!({ key => value })
18
18
  end
19
19
  end
20
20
 
@@ -26,7 +26,7 @@ module Ruboclean
26
26
 
27
27
  def find_target_group(key)
28
28
  return :base if key.start_with?(/[a-z]/)
29
- return :cops if key.include?('/')
29
+ return :cops if key.include?("/")
30
30
 
31
31
  :namespaces
32
32
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruboclean/grouper'
3
+ require "ruboclean/grouper"
4
4
 
5
5
  module Ruboclean
6
6
  # Orders the items within the groups alphabetically
@@ -10,5 +10,9 @@ module Ruboclean
10
10
  def order
11
11
  Ruboclean::Orderer.new(@config_hash).order
12
12
  end
13
+
14
+ def nil?
15
+ @config_hash.nil?
16
+ end
13
17
  end
14
18
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
- require 'yaml'
3
+ require "pathname"
4
+ require "yaml"
5
5
 
6
6
  module Ruboclean
7
7
  # Interface for reading and writing the `.rubocop.yml` file
8
8
  class RubocopConfigurationPath
9
+ PERMITTED_CLASSED = [Regexp].freeze
10
+
9
11
  # Thrown if given path is invalid
10
12
  class InvalidPathError < StandardError
11
13
  def initialize(path)
@@ -17,7 +19,7 @@ module Ruboclean
17
19
  input_path = Pathname.new(path)
18
20
 
19
21
  @rubocop_configuration_path = if input_path.directory?
20
- input_path.join('.rubocop.yml')
22
+ input_path.join(".rubocop.yml")
21
23
  else
22
24
  input_path
23
25
  end
@@ -29,9 +31,10 @@ module Ruboclean
29
31
  Ruboclean::RubocopConfiguration.new(load_yaml)
30
32
  end
31
33
 
32
- def write(rubocop_configuration)
33
- output = sanitize_yaml(rubocop_configuration.to_yaml)
34
- @rubocop_configuration_path.write(output)
34
+ def write(rubocop_configuration, preserve_comments: false)
35
+ output_yaml = sanitize_yaml(rubocop_configuration.to_yaml)
36
+ output_yaml = preserve_preceding_comments(source_yaml, output_yaml) if preserve_comments
37
+ @rubocop_configuration_path.write(output_yaml)
35
38
  end
36
39
 
37
40
  private
@@ -41,7 +44,25 @@ module Ruboclean
41
44
  end
42
45
 
43
46
  def load_yaml
44
- YAML.safe_load(@rubocop_configuration_path.read)
47
+ YAML.safe_load(source_yaml, permitted_classes: PERMITTED_CLASSED)
48
+ end
49
+
50
+ def source_yaml
51
+ @source_yaml ||= @rubocop_configuration_path.read
52
+ end
53
+
54
+ def preserve_preceding_comments(source, target)
55
+ target.dup.tap do |output|
56
+ source.scan(/(((^ *#.*\n|^\s*\n)+)(?![\s#]).+)/) do |groups|
57
+ config_keys_with_preceding_lines = groups.first
58
+ *preceding_lines, config_key = config_keys_with_preceding_lines.split("\n")
59
+
60
+ next if preceding_lines.all?(:empty?)
61
+ next if config_key.gsub(/\s/, "").empty?
62
+
63
+ output.sub!(/^#{config_key}$/, config_keys_with_preceding_lines.strip)
64
+ end
65
+ end
45
66
  end
46
67
  end
47
68
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruboclean
4
+ # Proxy for invoking the cleaning
5
+ class Runner
6
+ def initialize(arguments)
7
+ @arguments = arguments
8
+ end
9
+
10
+ def run!
11
+ rubocop_configuration_path = RubocopConfigurationPath.new(arguments.path)
12
+ rubocop_configuration = rubocop_configuration_path.load
13
+
14
+ return if rubocop_configuration.nil?
15
+
16
+ rubocop_configuration_path.write(rubocop_configuration.order, preserve_comments: arguments.preserve_comments?)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :arguments
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruboclean
4
- VERSION = '0.2.1'
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/ruboclean.rb CHANGED
@@ -1,17 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruboclean/version'
4
- require 'ruboclean/rubocop_configuration'
5
- require 'ruboclean/rubocop_configuration_path'
6
- require 'ruboclean/orderer'
3
+ require "ruboclean/version"
4
+ require "ruboclean/arguments"
5
+ require "ruboclean/rubocop_configuration"
6
+ require "ruboclean/rubocop_configuration_path"
7
+ require "ruboclean/runner"
8
+ require "ruboclean/orderer"
7
9
 
8
10
  # Ruboclean entry point
9
11
  module Ruboclean
10
12
  class Error < StandardError; end
11
13
 
12
- def self.run(path)
13
- rubocop_configuration_path = RubocopConfigurationPath.new(path)
14
- rubocop_configuration = rubocop_configuration_path.load
15
- rubocop_configuration_path.write(rubocop_configuration.order)
14
+ def self.run_from_cli!(command_line_arguments)
15
+ Ruboclean::Arguments.new(command_line_arguments).tap do |arguments|
16
+ print "Using path '#{arguments.path}' ... " if arguments.verbose?
17
+ Runner.new(arguments).run!
18
+ puts "done." if arguments.verbose?
19
+ end
16
20
  end
17
21
  end
data/ruboclean.gemspec CHANGED
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/ruboclean/version'
3
+ require_relative "lib/ruboclean/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'ruboclean'
6
+ spec.name = "ruboclean"
7
7
  spec.version = Ruboclean::VERSION
8
- spec.authors = ['lxxxvi']
9
- spec.email = ['lxxxvi@users.noreply.github.com']
8
+ spec.authors = ["lxxxvi"]
9
+ spec.email = ["lxxxvi@users.noreply.github.com"]
10
10
 
11
- spec.summary = 'Cleans and orders settings in .rubocop.yml'
12
- spec.description = 'Cleans and orders settings in .rubocop.yml'
13
- spec.homepage = 'https://github.com/lxxxvi/ruboclean'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
11
+ spec.summary = "Cleans and orders settings in .rubocop.yml"
12
+ spec.description = "Cleans and orders settings in .rubocop.yml"
13
+ spec.homepage = "https://github.com/lxxxvi/ruboclean"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
16
16
 
17
- spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = 'https://github.com/lxxxvi/ruboclean'
19
- spec.metadata['changelog_uri'] = 'https://github.com/lxxxvi/ruboclean/blob/master/CHANGELOG.md'
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/lxxxvi/ruboclean"
19
+ spec.metadata["changelog_uri"] = "https://github.com/lxxxvi/ruboclean/blob/master/CHANGELOG.md"
20
20
 
21
21
  # Specify which files should be added to the gem when it is released.
22
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
25
  end
26
26
 
27
- spec.executables << 'ruboclean'
28
- spec.require_paths = ['lib']
27
+ spec.executables << "ruboclean"
28
+ spec.require_paths = ["lib"]
29
+ spec.metadata["rubygems_mfa_required"] = "true"
29
30
  end
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.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lxxxvi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-01 00:00:00.000000000 Z
11
+ date: 2023-06-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Cleans and orders settings in .rubocop.yml
14
14
  email:
@@ -32,10 +32,12 @@ files:
32
32
  - bin/setup
33
33
  - bin/test
34
34
  - lib/ruboclean.rb
35
+ - lib/ruboclean/arguments.rb
35
36
  - lib/ruboclean/grouper.rb
36
37
  - lib/ruboclean/orderer.rb
37
38
  - lib/ruboclean/rubocop_configuration.rb
38
39
  - lib/ruboclean/rubocop_configuration_path.rb
40
+ - lib/ruboclean/runner.rb
39
41
  - lib/ruboclean/version.rb
40
42
  - ruboclean.gemspec
41
43
  homepage: https://github.com/lxxxvi/ruboclean
@@ -45,6 +47,7 @@ metadata:
45
47
  homepage_uri: https://github.com/lxxxvi/ruboclean
46
48
  source_code_uri: https://github.com/lxxxvi/ruboclean
47
49
  changelog_uri: https://github.com/lxxxvi/ruboclean/blob/master/CHANGELOG.md
50
+ rubygems_mfa_required: 'true'
48
51
  post_install_message:
49
52
  rdoc_options: []
50
53
  require_paths:
@@ -60,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
63
  - !ruby/object:Gem::Version
61
64
  version: '0'
62
65
  requirements: []
63
- rubygems_version: 3.2.3
66
+ rubygems_version: 3.4.13
64
67
  signing_key:
65
68
  specification_version: 4
66
69
  summary: Cleans and orders settings in .rubocop.yml