Cleanio
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.
Table of Contents
Installation
To install Cleanio, add it to your Gemfile:
gem 'cleanio'
Then execute:
bundle install
Or install it yourself using the following command:
gem install cleanio
Usage
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.
require 'cleanio'
Cleanio::Remover.clean('path/to/your_file.rb')
Cleanio::Remover.clean('path/to/your_directory')
Audit Mode
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.
Example
Cleanio::Remover.clean('example.rb', audit: true)
Output
File: example.rb
Line 1: # This is a comment
Line 3: # Another comment
Command-Line Interface (CLI)
You can use Cleanio directly from the command line to clean or audit .rb files.
Clean Comments
To remove comments from a file, use:
cleanio -p path/to/file.rb
cleanio -p path/to/directory
Audit mode
To run Cleanio in audit mode without modifying files, use the --audit flag:
cleanio -p path/to/file.rb --audit
cleanio -p path/to/directory --audit
Testing
Cleanio uses RSpec for testing. To run the tests, first make sure all dependencies are installed:
bundle install
Then, run the tests with:
bundle exec rspec
All tests are located in the spec directory and cover the main functionality of the gem, ensuring it properly removes comments from Ruby files.
Contribution
Bug reports and pull requests are welcome on GitHub at https://github.com/justi/cleanio.
To contribute:
Fork the repository. Create a new branch (git checkout -b feature-branch). Make your changes. Commit your changes (git commit -m 'Add new feature'). Push to the branch (git push origin feature-branch). Open a pull request.
Please ensure that your code follows the existing style and that all tests pass.
License
The gem is available as open source under the terms of the MIT License.
TODO
- Add support multi-line comments (
=begin...=end) - 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! - Option to stay documentation comments (e.g.
# @param) https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation - Option to clean all files in a directory except for a specified file