cleanio 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +12 -0
- data/exe/cleanio +25 -0
- data/lib/cleanio/version.rb +5 -0
- data/lib/cleanio.rb +51 -0
- data/sig/cleanio.rbs +4 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b2f0e7b2724b16024bbe777ea410ef369495f544ebcc3ca40f3cdd98219b18af
|
4
|
+
data.tar.gz: dfe2856b027bff85005a3957b44283544ba7ca171d3f010a7481a4f4c2f28814
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aaf2ea9478bc1a29d8bbd7198fd31315f22f79f59c51e8db3f88473abd0a5808f12ab5e50be920ccf3eff714bc9c9ea71aa696f979832bbebbdc5e230f4f845b
|
7
|
+
data.tar.gz: 71f9d89066caa22d6c24ba2f1a33937215f2e7594b73969153586a3c57439a8646b7020e40acacd9e5036cba3eaef52b00a160f7e8153bc1ff781bb15ce3f06d
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
- rubocop-rake
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.2
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Style/StringLiteralsInInterpolation:
|
13
|
+
EnforcedStyle: double_quotes
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Exclude:
|
17
|
+
- 'spec/cleanio/**/*'
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
RSpec/ExampleLength:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/cleanio/**/*'
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Justyna Wojtczak
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Cleanio
|
2
|
+
|
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
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
## Table of Contents
|
8
|
+
|
9
|
+
1. [Installation](#installation)
|
10
|
+
2. [Usage](#usage)
|
11
|
+
3. [Testing](#testing)
|
12
|
+
4. [Contribution](#contribution)
|
13
|
+
5. [License](#license)
|
14
|
+
6. [TODO](#todo)
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
To install `cleanio`, add it to your Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'cleanio'
|
24
|
+
```
|
25
|
+
Then execute:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
bundle install
|
29
|
+
```
|
30
|
+
Or install it yourself using the following command:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
gem install cleanio
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
To clean up comments from a .rb file, simply run:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require 'cleanio'
|
42
|
+
|
43
|
+
Cleanio::Remover.clean('path/to/your_file.rb')
|
44
|
+
```
|
45
|
+
Alternatively, you can use the command line tool:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
cleanio -f path/to/your_file.rb
|
49
|
+
```
|
50
|
+
This will remove all comments from the specified Ruby file.
|
51
|
+
|
52
|
+
## Testing
|
53
|
+
Cleanio uses RSpec for testing. To run the tests, first make sure all dependencies are installed:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
bundle install
|
57
|
+
```
|
58
|
+
Then, run the tests with:
|
59
|
+
|
60
|
+
```bash
|
61
|
+
bundle exec rspec
|
62
|
+
```
|
63
|
+
All tests are located in the spec directory and cover the main functionality of the gem, ensuring it properly removes comments from Ruby files.
|
64
|
+
|
65
|
+
## Contribution
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/justi/cleanio.
|
68
|
+
|
69
|
+
To contribute:
|
70
|
+
|
71
|
+
Fork the repository.
|
72
|
+
Create a new branch (git checkout -b feature-branch).
|
73
|
+
Make your changes.
|
74
|
+
Commit your changes (git commit -m 'Add new feature').
|
75
|
+
Push to the branch (git push origin feature-branch).
|
76
|
+
Open a pull request.
|
77
|
+
|
78
|
+
Please ensure that your code follows the existing style and that all tests pass.
|
79
|
+
|
80
|
+
## License
|
81
|
+
The gem is available as open source under the terms of the MIT License.
|
82
|
+
|
83
|
+
|
84
|
+
## TODO
|
85
|
+
- Add support multi-line comments (`=begin`...`=end`)
|
86
|
+
- Option to stay documentation comments (e.g. `# @param`) https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation
|
87
|
+
- Option to recursively clean all files in a directory
|
88
|
+
- 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/Rakefile
ADDED
data/exe/cleanio
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "optparse"
|
5
|
+
require "cleanio"
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: cleanio -f FILE"
|
10
|
+
|
11
|
+
opts.on("-f", "--file FIle", "Path to .rb file") do |file|
|
12
|
+
options[:file] = file
|
13
|
+
end
|
14
|
+
end.parse!
|
15
|
+
|
16
|
+
if options[:file]
|
17
|
+
begin
|
18
|
+
Cleanio::Remover.clean(options[:file])
|
19
|
+
puts "The comments were removed from #{options[:file]}"
|
20
|
+
rescue StandardError => e
|
21
|
+
puts "Error: #{e.message}"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
puts "You need to provide a file path with -f option"
|
25
|
+
end
|
data/lib/cleanio.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cleanio/version"
|
4
|
+
require "ripper"
|
5
|
+
|
6
|
+
module Cleanio
|
7
|
+
class Remover
|
8
|
+
def self.clean(file_path)
|
9
|
+
validate_file_extension(file_path)
|
10
|
+
file_content = File.read(file_path)
|
11
|
+
content_cleaned = remove_comments(file_content)
|
12
|
+
File.write(file_path, content_cleaned)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.validate_file_extension(file_path)
|
16
|
+
raise "Only Ruby files are supported" unless file_path.end_with?(".rb")
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.remove_comments(content)
|
20
|
+
comments = extract_comments(content)
|
21
|
+
content = process_comments(content, comments)
|
22
|
+
remove_empty_lines(content)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.extract_comments(content)
|
26
|
+
Ripper.lex(content).select { |_pos, type, _tok, _| type == :on_comment }
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.process_comments(content, comments)
|
30
|
+
comments.sort_by { |(pos, _, _, _)| [pos[0], pos[1]] }.reverse.each do |(pos, _, _, _)|
|
31
|
+
line, col = pos
|
32
|
+
lines = content.lines
|
33
|
+
lines[line - 1] = process_comment_line(lines[line - 1], col)
|
34
|
+
content = lines.join
|
35
|
+
end
|
36
|
+
content
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.process_comment_line(line, col)
|
40
|
+
if line[col..].strip.start_with?("#")
|
41
|
+
"#{line[0...col].rstrip}\n"
|
42
|
+
else
|
43
|
+
"\n"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.remove_empty_lines(content)
|
48
|
+
content.gsub(/^\s*$\n/, "")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/sig/cleanio.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cleanio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justyna
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- justine84@gmail.com
|
16
|
+
executables:
|
17
|
+
- cleanio
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- LICENSE
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- exe/cleanio
|
28
|
+
- lib/cleanio.rb
|
29
|
+
- lib/cleanio/version.rb
|
30
|
+
- sig/cleanio.rbs
|
31
|
+
homepage:
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
rubygems_mfa_required: 'true'
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 3.0.0
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubygems_version: 3.4.19
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: Remove comments from Ruby files
|
55
|
+
test_files: []
|