ruboclean 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8356a24c5eef21d90f98b6a9d70e05c39eecca00bdad3cc44cf487f7f13d4d3f
4
- data.tar.gz: 547493df65b231feec2b0e110beaca285a4c708726a60f25ce42da25c04297de
3
+ metadata.gz: 4d44db013c200c2aa27fb69d03ba72a9160fdff84c32fd337616c741f665fc02
4
+ data.tar.gz: 506a81ba8570624d6a7694b634c5daeca924049ec4a799cc8d3634500908aa5d
5
5
  SHA512:
6
- metadata.gz: 2a322034ef76aef728838a67c0400b6a869614765367347582b99a6a0e9d76ceb1c04ac7f93217d35702eb18b9c111958b059ee39716a8f5d2535f00a6e05e0b
7
- data.tar.gz: 2b9895e2eba1124a33fd0808f2622a22e848cfe87ebede24cda7f17dfc7490e233db040342de84343d69f1dd57d430b8feaf5e9aa87d8961c8c3662624d3e583
6
+ metadata.gz: 46aefeee7846f41223c011cba0926d1a4554c9c9072ed05b3d346d584f1e71a76ded64daf6648956b6d707d82388696fa4ae2729560f710ad9d1cd522b30f8b1
7
+ data.tar.gz: b4b699189ad6cced7bb0beeed940550217c0d14c140b6d20eb3f25876ecd23415436bdd91f106d9cc33a57c0a52582e58515159854d37a3ac860c1d3be1d46ad
@@ -15,7 +15,7 @@ jobs:
15
15
  fail-fast: false
16
16
  matrix:
17
17
  os: [ubuntu-latest]
18
- ruby: ['2.7', '3.0', '3.1', head]
18
+ ruby: ['2.7', '3.0', '3.1', '3.2', head]
19
19
  runs-on: ${{ matrix.os }}
20
20
  steps:
21
21
  - uses: actions/checkout@v3
data/.rubocop.yml CHANGED
@@ -4,11 +4,10 @@ require:
4
4
  - rubocop-minitest
5
5
  - rubocop-rake
6
6
 
7
- Style/StringLiterals:
7
+ Gemspec/DeprecatedAttributeAssignment:
8
8
  Enabled: true
9
- EnforcedStyle: double_quotes
10
9
 
11
- Gemspec/DeprecatedAttributeAssignment:
10
+ Gemspec/DevelopmentDependencies:
12
11
  Enabled: true
13
12
 
14
13
  Gemspec/RequireMFA:
@@ -68,6 +67,9 @@ Lint/DuplicateElsifCondition:
68
67
  Lint/DuplicateMagicComment:
69
68
  Enabled: true
70
69
 
70
+ Lint/DuplicateMatchPattern:
71
+ Enabled: true
72
+
71
73
  Lint/DuplicateRegexpCharacterClassElement:
72
74
  Enabled: true
73
75
 
@@ -173,12 +175,18 @@ Lint/UnreachableLoop:
173
175
  Lint/UselessMethodDefinition:
174
176
  Enabled: true
175
177
 
178
+ Lint/UselessRescue:
179
+ Enabled: true
180
+
176
181
  Lint/UselessRuby2Keywords:
177
182
  Enabled: true
178
183
 
179
184
  Lint/UselessTimes:
180
185
  Enabled: true
181
186
 
187
+ Metrics/CollectionLiteralLength:
188
+ Enabled: true
189
+
182
190
  Minitest/AssertInDelta:
183
191
  Enabled: true
184
192
 
@@ -200,6 +208,9 @@ Minitest/AssertRaisesCompoundBody:
200
208
  Minitest/AssertRaisesWithRegexpArgument:
201
209
  Enabled: true
202
210
 
211
+ Minitest/AssertSame:
212
+ Enabled: true
213
+
203
214
  Minitest/AssertSilent:
204
215
  Enabled: true
205
216
 
@@ -215,6 +226,9 @@ Minitest/DuplicateTestRun:
215
226
  Minitest/EmptyLineBeforeAssertionMethods:
216
227
  Enabled: true
217
228
 
229
+ Minitest/LifecycleHooksOrder:
230
+ Enabled: true
231
+
218
232
  Minitest/LiteralAsActualArgument:
219
233
  Enabled: true
220
234
 
@@ -222,6 +236,9 @@ Minitest/MultipleAssertions:
222
236
  Enabled: true
223
237
  Max: 5
224
238
 
239
+ Minitest/NonPublicTestMethod:
240
+ Enabled: true
241
+
225
242
  Minitest/RefuteInDelta:
226
243
  Enabled: true
227
244
 
@@ -234,12 +251,21 @@ Minitest/RefutePathExists:
234
251
  Minitest/RefutePredicate:
235
252
  Enabled: true
236
253
 
254
+ Minitest/RefuteSame:
255
+ Enabled: true
256
+
257
+ Minitest/ReturnInTestMethod:
258
+ Enabled: true
259
+
237
260
  Minitest/SkipEnsure:
238
261
  Enabled: true
239
262
 
240
263
  Minitest/SkipWithoutReason:
241
264
  Enabled: true
242
265
 
266
+ Minitest/TestFileName:
267
+ Enabled: true
268
+
243
269
  Minitest/TestMethodName:
244
270
  Enabled: true
245
271
 
@@ -249,6 +275,9 @@ Minitest/UnreachableAssertion:
249
275
  Minitest/UnspecifiedException:
250
276
  Enabled: true
251
277
 
278
+ Minitest/UselessAssertion:
279
+ Enabled: true
280
+
252
281
  Naming/BlockForwarding:
253
282
  Enabled: true
254
283
 
@@ -282,9 +311,18 @@ Style/CollectionCompact:
282
311
  Style/CombinableLoops:
283
312
  Enabled: true
284
313
 
314
+ Style/ComparableClamp:
315
+ Enabled: true
316
+
285
317
  Style/ConcatArrayLiterals:
286
318
  Enabled: true
287
319
 
320
+ Style/DataInheritance:
321
+ Enabled: true
322
+
323
+ Style/DirEmpty:
324
+ Enabled: true
325
+
288
326
  Style/DocumentDynamicEvalDefinition:
289
327
  Enabled: true
290
328
 
@@ -297,6 +335,9 @@ Style/EndlessMethod:
297
335
  Style/EnvHome:
298
336
  Enabled: true
299
337
 
338
+ Style/ExactRegexpMatch:
339
+ Enabled: true
340
+
300
341
  Style/ExplicitBlockArgument:
301
342
  Enabled: true
302
343
 
@@ -306,6 +347,9 @@ Style/ExponentialNotation:
306
347
  Style/FetchEnvVar:
307
348
  Enabled: true
308
349
 
350
+ Style/FileEmpty:
351
+ Enabled: true
352
+
309
353
  Style/FileRead:
310
354
  Enabled: true
311
355
 
@@ -396,6 +440,9 @@ Style/QuotedSymbols:
396
440
  Style/RedundantArgument:
397
441
  Enabled: true
398
442
 
443
+ Style/RedundantArrayConstructor:
444
+ Enabled: true
445
+
399
446
  Style/RedundantAssignment:
400
447
  Enabled: true
401
448
 
@@ -414,12 +461,24 @@ Style/RedundantFetchBlock:
414
461
  Style/RedundantFileExtensionInRequire:
415
462
  Enabled: true
416
463
 
464
+ Style/RedundantFilterChain:
465
+ Enabled: true
466
+
467
+ Style/RedundantHeredocDelimiterQuotes:
468
+ Enabled: true
469
+
417
470
  Style/RedundantInitialize:
418
471
  Enabled: true
419
472
 
473
+ Style/RedundantLineContinuation:
474
+ Enabled: true
475
+
420
476
  Style/RedundantRegexpCharacterClass:
421
477
  Enabled: true
422
478
 
479
+ Style/RedundantRegexpConstructor:
480
+ Enabled: true
481
+
423
482
  Style/RedundantRegexpEscape:
424
483
  Enabled: true
425
484
 
@@ -450,6 +509,10 @@ Style/StringChars:
450
509
  Style/StringConcatenation:
451
510
  Enabled: true
452
511
 
512
+ Style/StringLiterals:
513
+ Enabled: true
514
+ EnforcedStyle: double_quotes
515
+
453
516
  Style/SwapValues:
454
517
  Enabled: true
455
518
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruboclean (0.3.0)
4
+ ruboclean (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,37 +9,39 @@ GEM
9
9
  ast (2.4.2)
10
10
  docile (1.4.0)
11
11
  json (2.6.3)
12
- minitest (5.17.0)
13
- parallel (1.22.1)
14
- parser (3.2.0.0)
12
+ minitest (5.18.0)
13
+ parallel (1.23.0)
14
+ parser (3.2.2.3)
15
15
  ast (~> 2.4.1)
16
+ racc
17
+ racc (1.7.0)
16
18
  rainbow (3.1.1)
17
19
  rake (13.0.6)
18
- regexp_parser (2.6.1)
20
+ regexp_parser (2.8.0)
19
21
  rexml (3.2.5)
20
- rubocop (1.42.0)
22
+ rubocop (1.52.0)
21
23
  json (~> 2.3)
22
24
  parallel (~> 1.10)
23
- parser (>= 3.1.2.1)
25
+ parser (>= 3.2.0.0)
24
26
  rainbow (>= 2.2.2, < 4.0)
25
27
  regexp_parser (>= 1.8, < 3.0)
26
28
  rexml (>= 3.2.5, < 4.0)
27
- rubocop-ast (>= 1.24.1, < 2.0)
29
+ rubocop-ast (>= 1.28.0, < 2.0)
28
30
  ruby-progressbar (~> 1.7)
29
- unicode-display_width (>= 1.4.0, < 3.0)
30
- rubocop-ast (1.24.1)
31
- parser (>= 3.1.1.0)
32
- rubocop-minitest (0.25.1)
33
- rubocop (>= 0.90, < 2.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)
34
36
  rubocop-rake (0.6.0)
35
37
  rubocop (~> 1.0)
36
- ruby-progressbar (1.11.0)
38
+ ruby-progressbar (1.13.0)
37
39
  simplecov (0.17.1)
38
40
  docile (~> 1.1)
39
41
  json (>= 1.8, < 3)
40
42
  simplecov-html (~> 0.10.0)
41
43
  simplecov-html (0.10.2)
42
- unicode-display_width (2.4.1)
44
+ unicode-display_width (2.4.2)
43
45
 
44
46
  PLATFORMS
45
47
  ruby
@@ -54,4 +56,4 @@ DEPENDENCIES
54
56
  simplecov (< 0.18)
55
57
 
56
58
  BUNDLED WITH
57
- 2.4.2
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/bin/ruboclean CHANGED
@@ -3,9 +3,4 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  require "ruboclean"
6
-
7
- path = ARGV[0] || Dir.pwd
8
-
9
- print "Using path '#{path}' ... "
10
- Ruboclean.run(path)
11
- puts "done."
6
+ Ruboclean.run_from_cli!(ARGV)
data/bin/test CHANGED
@@ -20,7 +20,7 @@ class BinTest
20
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
@@ -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
@@ -31,9 +31,10 @@ module Ruboclean
31
31
  Ruboclean::RubocopConfiguration.new(load_yaml)
32
32
  end
33
33
 
34
- def write(rubocop_configuration)
35
- output = sanitize_yaml(rubocop_configuration.to_yaml)
36
- @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)
37
38
  end
38
39
 
39
40
  private
@@ -43,7 +44,25 @@ module Ruboclean
43
44
  end
44
45
 
45
46
  def load_yaml
46
- YAML.safe_load(@rubocop_configuration_path.read, permitted_classes: PERMITTED_CLASSED)
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
47
66
  end
48
67
  end
49
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.3.0"
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
3
  require "ruboclean/version"
4
+ require "ruboclean/arguments"
4
5
  require "ruboclean/rubocop_configuration"
5
6
  require "ruboclean/rubocop_configuration_path"
7
+ require "ruboclean/runner"
6
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
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.3.0
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: 2023-01-04 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
@@ -61,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
63
  - !ruby/object:Gem::Version
62
64
  version: '0'
63
65
  requirements: []
64
- rubygems_version: 3.4.1
66
+ rubygems_version: 3.4.13
65
67
  signing_key:
66
68
  specification_version: 4
67
69
  summary: Cleans and orders settings in .rubocop.yml