cleanio 0.1.2 → 0.1.3
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/.rubocop.yml +3 -0
- data/README.md +8 -5
- data/exe/cleanio +12 -8
- data/lib/cleanio/version.rb +1 -1
- data/lib/cleanio.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 036c8a1c4dde80a666690afad1a7627096d32c41be872b10aff0a00f8c89ac49
|
4
|
+
data.tar.gz: 023bc640786b9aa3f75267ac62452f6de89ec803bf9c155031c0cc4cdaaf3756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2dc6bf75656154a3a3454a611df2db1f5ad5e6064bcb4415b07861e8df3548ece27074e0db066eba7bb98d5c6467708df8c2215f069b64896adbf280d038808
|
7
|
+
data.tar.gz: 3b5869730b6d131087e52d3c39ed2762c32649f5eab7251a85ad4a5cc5edde7b9fc6564035a50f59b056449404c2e709561426fd821dc3c993f5a90787e565a4
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -35,16 +35,18 @@ gem install cleanio
|
|
35
35
|
|
36
36
|
|
37
37
|
## Usage
|
38
|
-
To clean up comments from a .rb file,
|
38
|
+
To clean up comments from a .rb file or directory, use the `Cleanio::Remover.clean` method. This will remove all single-line comments and inline comments from the file or directory.
|
39
39
|
|
40
40
|
```ruby
|
41
41
|
require 'cleanio'
|
42
42
|
|
43
43
|
Cleanio::Remover.clean('path/to/your_file.rb')
|
44
|
+
Cleanio::Remover.clean('path/to/your_directory')
|
45
|
+
|
44
46
|
```
|
45
47
|
### Audit Mode
|
46
48
|
|
47
|
-
To use the audit mode, pass the `audit: true` flag to the `clean` method. This will output the file paths and lines containing comments without modifying the
|
49
|
+
To use the audit mode, pass the `audit: true` flag to the `clean` method. This will output the file paths and lines containing comments without modifying the files.
|
48
50
|
|
49
51
|
#### Example
|
50
52
|
|
@@ -68,14 +70,16 @@ You can use Cleanio directly from the command line to clean or audit `.rb` files
|
|
68
70
|
To remove comments from a file, use:
|
69
71
|
|
70
72
|
```bash
|
71
|
-
cleanio -
|
73
|
+
cleanio -p path/to/file.rb
|
74
|
+
cleanio -p path/to/directory
|
72
75
|
```
|
73
76
|
#### Audit mode
|
74
77
|
|
75
78
|
To run Cleanio in audit mode without modifying files, use the `--audit` flag:
|
76
79
|
|
77
80
|
```bash
|
78
|
-
cleanio -
|
81
|
+
cleanio -p path/to/file.rb --audit
|
82
|
+
cleanio -p path/to/directory --audit
|
79
83
|
```
|
80
84
|
|
81
85
|
## Testing
|
@@ -114,5 +118,4 @@ The gem is available as open source under the terms of the MIT License.
|
|
114
118
|
- Add support multi-line comments (`=begin`...`=end`)
|
115
119
|
- Add support to magic comments (e.g. `# frozen_string_literal: true`) https://docs.ruby-lang.org/en/3.2/syntax/comments_rdoc.html - thanks [Chris](https://github.com/khasinski)!
|
116
120
|
- Option to stay documentation comments (e.g. `# @param`) https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation
|
117
|
-
- Option to recursively clean all files in a directory
|
118
121
|
- Option to clean all files in a directory except for a specified file
|
data/exe/cleanio
CHANGED
@@ -8,22 +8,26 @@ options = {}
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: cleanio [options]"
|
10
10
|
|
11
|
-
opts.on("-
|
12
|
-
options[:
|
11
|
+
opts.on("-p", "--path PATH", "Path to a .rb file or directory") do |path|
|
12
|
+
options[:path] = path
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
opts.on("--audit", "Run in audit mode to display comments without modifying files") do
|
15
16
|
options[:audit] = true
|
16
17
|
end
|
17
18
|
end.parse!
|
18
19
|
|
19
|
-
if options[:
|
20
|
+
if options[:path]
|
20
21
|
begin
|
21
|
-
Cleanio::Remover.clean(options[:
|
22
|
-
|
23
|
-
|
22
|
+
Cleanio::Remover.clean(options[:path], audit: options[:audit])
|
23
|
+
if options[:audit]
|
24
|
+
puts "Audit completed successfully."
|
25
|
+
else
|
26
|
+
puts "Cleaning completed successfully."
|
27
|
+
end
|
24
28
|
rescue StandardError => e
|
25
29
|
puts "Error: #{e.message}"
|
26
30
|
end
|
27
31
|
else
|
28
|
-
puts "Please provide a file
|
32
|
+
puts "Please provide a file or directory with -p."
|
29
33
|
end
|
data/lib/cleanio/version.rb
CHANGED
data/lib/cleanio.rb
CHANGED
@@ -6,8 +6,19 @@ require "ripper"
|
|
6
6
|
module Cleanio
|
7
7
|
class Remover
|
8
8
|
def self.clean(file_path, audit: false)
|
9
|
+
if File.directory?(file_path)
|
10
|
+
Dir.glob("#{file_path}/**/*.rb").each do |file|
|
11
|
+
process_file(file, audit: audit)
|
12
|
+
end
|
13
|
+
else
|
14
|
+
process_file(file_path, audit: audit)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.process_file(file_path, audit: false)
|
9
19
|
validate_file_extension(file_path)
|
10
20
|
file_content = File.read(file_path)
|
21
|
+
|
11
22
|
if audit
|
12
23
|
audit_comments(file_path, file_content)
|
13
24
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cleanio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justyna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|