ruboclean 0.5.0 → 0.6.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: be162ee85b381ec3596945c154e6a9596a3c1a38ca54932bc172e71bb750f006
4
- data.tar.gz: ab675e274e9d0774bd654f73e4afc14d6bfbd6d54547685e7794830c2d4b99c5
3
+ metadata.gz: eed645db36081518d593efb17c64f3c1566a978548a699d10aecf64893ad0f48
4
+ data.tar.gz: 62c988143427e15fa10e551cedb5965be6a81dd7afbba5ec40ef303ce6e6183c
5
5
  SHA512:
6
- metadata.gz: 3177f58dec5a6ea6318b9ba33dbe31e813060d43cff545c5d354d8998efb326b02d2d7b65c3b5850c1fdbfa8d8fe9e27020430e59df16f7c442fe81812e29e28
7
- data.tar.gz: edc1388ea384c16dac65f59127f887267c560f6b3b4e65cef970304b3932b430d2974a747839cbf4da1665f380021297a4de0915ccf7fb412763785b19954668
6
+ metadata.gz: 31f137822127611a4aa5b54df8e7d9222d96937438367ab73a3bdf588e1a854b36a2ba8ce617125ff955948046214ad63037b4ae8a4b5f571f979793c252b2c0
7
+ data.tar.gz: c939cd53f18fae460f56d76b6ed1c463b229795ac4518ef246ef12b4dd11135067c329276b5d1a9418aebdcf690c8088a4944ff5b338b314be01246dd0acd26e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruboclean (0.5.0)
4
+ ruboclean (0.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -84,7 +84,7 @@ gem install ruboclean
84
84
  ## Command synopsis
85
85
 
86
86
  ```shell
87
- ruboclean [path] [--silent] [--preserve-comments] [--preserve-paths]
87
+ ruboclean [path] [--silent] [--preserve-comments] [--preserve-paths] [--verify]
88
88
  ```
89
89
 
90
90
  ### Parameters
@@ -95,6 +95,7 @@ ruboclean [path] [--silent] [--preserve-comments] [--preserve-paths]
95
95
  | `--silent` | Suppress any output displayed on the screen when executing the command. |
96
96
  | `--preserve-comments` | Preserves **preceding** comments for each top-level entry in the configuration. Inline comments are **not** preserved. |
97
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
99
 
99
100
  ### Examples
100
101
 
@@ -27,6 +27,10 @@ module Ruboclean
27
27
  @preserve_paths ||= find_argument("--preserve-paths")
28
28
  end
29
29
 
30
+ def verify?
31
+ @verify ||= find_argument("--verify")
32
+ end
33
+
30
34
  private
31
35
 
32
36
  attr_reader :command_line_arguments
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruboclean
4
+ # Logger for clean management of log levels
5
+ class Logger
6
+ def initialize(log_level = :verbose)
7
+ raise ArgumentError, "Invalid log level" unless %i[verbose none].include?(log_level)
8
+
9
+ @log_level = log_level
10
+ end
11
+
12
+ def verbose(message)
13
+ case @log_level
14
+ when :verbose
15
+ print message
16
+ end
17
+ end
18
+ end
19
+ end
@@ -17,12 +17,21 @@ module Ruboclean
17
17
  .then(&method(:cleanup_paths))
18
18
  .then(&method(:convert_to_yaml))
19
19
  .then(&method(:write_file!))
20
+ .then(&method(:changed?))
21
+ end
22
+
23
+ def changed?(target_yaml)
24
+ target_yaml != source_yaml
20
25
  end
21
26
 
22
27
  def verbose?
23
28
  cli_arguments.verbose?
24
29
  end
25
30
 
31
+ def verify?
32
+ cli_arguments.verify?
33
+ end
34
+
26
35
  def path
27
36
  cli_arguments.path
28
37
  end
@@ -54,7 +63,9 @@ module Ruboclean
54
63
  end
55
64
 
56
65
  def write_file!(target_yaml)
57
- source_file_pathname.write(target_yaml)
66
+ target_yaml.tap do |content|
67
+ source_file_pathname.write(content) unless verify?
68
+ end
58
69
  end
59
70
 
60
71
  def source_file_pathname
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruboclean
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/ruboclean.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "ruboclean/cli_arguments"
4
4
  require "ruboclean/orderer"
5
+ require "ruboclean/logger"
5
6
  require "ruboclean/grouper"
6
7
  require "ruboclean/path_cleanup"
7
8
  require "ruboclean/runner"
@@ -12,8 +13,25 @@ require "ruboclean/version"
12
13
  module Ruboclean
13
14
  def self.run_from_cli!(args)
14
15
  runner = Runner.new(args)
15
- print "Using path '#{runner.path}' ... " if runner.verbose?
16
- runner.run!
17
- puts "done." if runner.verbose?
16
+ logger = Ruboclean::Logger.new(runner.verbose? ? :verbose : :none)
17
+
18
+ logger.verbose "Using path '#{runner.path}' ... "
19
+ changed = runner.run!
20
+ logger.verbose post_execution_message(changed, runner.verify?)
21
+
22
+ exit !changed if runner.verify?
23
+ exit 0
24
+ end
25
+
26
+ def self.post_execution_message(changed, verify)
27
+ if changed
28
+ if verify
29
+ "needs clean.\n"
30
+ else
31
+ "done.\n"
32
+ end
33
+ else
34
+ "already clean.\n"
35
+ end
18
36
  end
19
37
  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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lxxxvi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-11 00:00:00.000000000 Z
11
+ date: 2024-03-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Cleans and orders settings in .rubocop.yml
14
14
  email:
@@ -34,6 +34,7 @@ files:
34
34
  - lib/ruboclean.rb
35
35
  - lib/ruboclean/cli_arguments.rb
36
36
  - lib/ruboclean/grouper.rb
37
+ - lib/ruboclean/logger.rb
37
38
  - lib/ruboclean/orderer.rb
38
39
  - lib/ruboclean/path_cleanup.rb
39
40
  - lib/ruboclean/runner.rb