cleanio 0.1.1 → 0.1.2
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 +7 -0
- data/README.md +34 -6
- data/exe/cleanio +8 -4
- data/lib/cleanio/version.rb +1 -1
- data/lib/cleanio.rb +17 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed57e0bb111c6d0b05161f098fd7494c13c5b1d3722e08f7199d4a8bbe12d162
|
4
|
+
data.tar.gz: b6ca75aebe1758166ef4dc7ddd2cf5ae154bd05274a6a451893e6832817dde4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bfc8e9e15d1c7d8ac647de328976f0acb4ee8790a50436a2ef4fcdac1f4ef40d9ef405bb5ad31c6c22405b24c7c62ab73bb1ad1d4ab4915718eab6a1f9edbf0
|
7
|
+
data.tar.gz: 972814f60a30461276fca1ac7c6ee171993082ed1c908ca68b6d0c5f569ff1f9f4f93398b02e807ca3b61889e6fb56c9321ff9696856d9d18c1c6fe264f65077
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Cleanio
|
2
2
|
|
3
|
-
`
|
3
|
+
`Cleanio` is a simple Ruby gem that removes comments from `.rb` files. It can handle single-line comments and inline comments, leaving your code clean and readable.
|
4
4
|
|
5
5
|
---
|
6
6
|
|
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
20
|
-
To install `
|
20
|
+
To install `Cleanio`, add it to your Gemfile:
|
21
21
|
|
22
22
|
```ruby
|
23
23
|
gem 'cleanio'
|
@@ -42,12 +42,41 @@ require 'cleanio'
|
|
42
42
|
|
43
43
|
Cleanio::Remover.clean('path/to/your_file.rb')
|
44
44
|
```
|
45
|
-
|
45
|
+
### Audit Mode
|
46
|
+
|
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 file.
|
48
|
+
|
49
|
+
#### Example
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Cleanio::Remover.clean('example.rb', audit: true)
|
53
|
+
```
|
54
|
+
#### Output
|
55
|
+
|
56
|
+
```bash
|
57
|
+
File: example.rb
|
58
|
+
Line 1: # This is a comment
|
59
|
+
Line 3: # Another comment
|
60
|
+
```
|
61
|
+
|
62
|
+
### Command-Line Interface (CLI)
|
63
|
+
|
64
|
+
You can use Cleanio directly from the command line to clean or audit `.rb` files.
|
65
|
+
|
66
|
+
#### Clean Comments
|
67
|
+
|
68
|
+
To remove comments from a file, use:
|
69
|
+
|
70
|
+
```bash
|
71
|
+
cleanio -f path/to/file.rb
|
72
|
+
```
|
73
|
+
#### Audit mode
|
74
|
+
|
75
|
+
To run Cleanio in audit mode without modifying files, use the `--audit` flag:
|
46
76
|
|
47
77
|
```bash
|
48
|
-
cleanio -f path/to/
|
78
|
+
cleanio -f path/to/file.rb --audit
|
49
79
|
```
|
50
|
-
This will remove all comments from the specified Ruby file.
|
51
80
|
|
52
81
|
## Testing
|
53
82
|
Cleanio uses RSpec for testing. To run the tests, first make sure all dependencies are installed:
|
@@ -87,4 +116,3 @@ The gem is available as open source under the terms of the MIT License.
|
|
87
116
|
- Option to stay documentation comments (e.g. `# @param`) https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation
|
88
117
|
- Option to recursively clean all files in a directory
|
89
118
|
- Option to clean all files in a directory except for a specified file
|
90
|
-
- Option for audit mode (show what would be removed without actually removing it)
|
data/exe/cleanio
CHANGED
@@ -6,20 +6,24 @@ require "cleanio"
|
|
6
6
|
|
7
7
|
options = {}
|
8
8
|
OptionParser.new do |opts|
|
9
|
-
opts.banner = "Usage: cleanio
|
9
|
+
opts.banner = "Usage: cleanio [options]"
|
10
10
|
|
11
11
|
opts.on("-f", "--file FIle", "Path to .rb file") do |file|
|
12
12
|
options[:file] = file
|
13
13
|
end
|
14
|
+
opts.on("--audit", "Run in audit mode to display file paths and comment lines without modifying files") do
|
15
|
+
options[:audit] = true
|
16
|
+
end
|
14
17
|
end.parse!
|
15
18
|
|
16
19
|
if options[:file]
|
17
20
|
begin
|
18
|
-
Cleanio::Remover.clean(options[:file])
|
19
|
-
puts "
|
21
|
+
Cleanio::Remover.clean(options[:file], audit: options[:audit])
|
22
|
+
puts "Audit completed successfully." if options[:audit]
|
23
|
+
puts "File cleaned successfully." unless options[:audit]
|
20
24
|
rescue StandardError => e
|
21
25
|
puts "Error: #{e.message}"
|
22
26
|
end
|
23
27
|
else
|
24
|
-
puts "
|
28
|
+
puts "Please provide a file path using the -f flag."
|
25
29
|
end
|
data/lib/cleanio/version.rb
CHANGED
data/lib/cleanio.rb
CHANGED
@@ -5,17 +5,31 @@ require "ripper"
|
|
5
5
|
|
6
6
|
module Cleanio
|
7
7
|
class Remover
|
8
|
-
def self.clean(file_path)
|
8
|
+
def self.clean(file_path, audit: false)
|
9
9
|
validate_file_extension(file_path)
|
10
10
|
file_content = File.read(file_path)
|
11
|
-
|
12
|
-
|
11
|
+
if audit
|
12
|
+
audit_comments(file_path, file_content)
|
13
|
+
else
|
14
|
+
content_cleaned = remove_comments(file_content)
|
15
|
+
File.write(file_path, content_cleaned)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
def self.validate_file_extension(file_path)
|
16
20
|
raise "Only Ruby files are supported" unless file_path.end_with?(".rb")
|
17
21
|
end
|
18
22
|
|
23
|
+
def self.audit_comments(file_path, content)
|
24
|
+
comments = extract_comments(content)
|
25
|
+
puts "File: #{file_path}" unless comments.empty?
|
26
|
+
|
27
|
+
comments.each do |(pos, _, tok, _)|
|
28
|
+
line, = pos
|
29
|
+
puts " Line #{line}: #{tok.strip}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
19
33
|
def self.remove_comments(content)
|
20
34
|
comments = extract_comments(content)
|
21
35
|
content = process_comments(content, comments)
|