cleanio 0.1.0 → 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 +35 -6
- data/exe/cleanio +8 -4
- data/lib/cleanio/version.rb +1 -1
- data/lib/cleanio.rb +17 -3
- metadata +2 -3
- data/LICENSE.txt +0 -21
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:
|
@@ -83,7 +112,7 @@ The gem is available as open source under the terms of the MIT License.
|
|
83
112
|
|
84
113
|
## TODO
|
85
114
|
- Add support multi-line comments (`=begin`...`=end`)
|
115
|
+
- 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)!
|
86
116
|
- Option to stay documentation comments (e.g. `# @param`) https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation
|
87
117
|
- Option to recursively clean all files in a directory
|
88
118
|
- Option to clean all files in a directory except for a specified file
|
89
|
-
- 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)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justyna
|
@@ -21,7 +21,6 @@ files:
|
|
21
21
|
- ".rspec"
|
22
22
|
- ".rubocop.yml"
|
23
23
|
- LICENSE
|
24
|
-
- LICENSE.txt
|
25
24
|
- README.md
|
26
25
|
- Rakefile
|
27
26
|
- exe/cleanio
|
@@ -41,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
40
|
requirements:
|
42
41
|
- - ">="
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
version: 3.
|
43
|
+
version: 3.2.4
|
45
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
45
|
requirements:
|
47
46
|
- - ">="
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2024 Justyna
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|