cleanio 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c42e0f9f14418be63dd899e7464b0436c7b5818ab58caa6b4e337a1991d4bc7
4
- data.tar.gz: a363d3fee96907139c93f50962a73fd4e3ca0ea22fa81285baee09e3c96b448c
3
+ metadata.gz: 036c8a1c4dde80a666690afad1a7627096d32c41be872b10aff0a00f8c89ac49
4
+ data.tar.gz: 023bc640786b9aa3f75267ac62452f6de89ec803bf9c155031c0cc4cdaaf3756
5
5
  SHA512:
6
- metadata.gz: b80973d46215050482dee5c9fa2aae917c1d6fafea0f731bc47a9c491f0754faaba0f773238f618ab56bfa0e4c43a9f384581c24d642c2b8f68faf935cb5f92d
7
- data.tar.gz: f5fca8330175e5e246aec51483465ba58fb19aaaafb97b0e4676dce33e2027c51ea0449e4b564f6e8df19722bb1c81f008a1d0d89d90934d0218be9bd0444dfb
6
+ metadata.gz: f2dc6bf75656154a3a3454a611df2db1f5ad5e6064bcb4415b07861e8df3548ece27074e0db066eba7bb98d5c6467708df8c2215f069b64896adbf280d038808
7
+ data.tar.gz: 3b5869730b6d131087e52d3c39ed2762c32649f5eab7251a85ad4a5cc5edde7b9fc6564035a50f59b056449404c2e709561426fd821dc3c993f5a90787e565a4
data/.rubocop.yml CHANGED
@@ -22,3 +22,13 @@ Style/Documentation:
22
22
  RSpec/ExampleLength:
23
23
  Exclude:
24
24
  - 'spec/cleanio/**/*'
25
+
26
+ RSpec/MultipleExpectations:
27
+ Enabled: false
28
+
29
+ RSpec/DescribeClass:
30
+ Exclude:
31
+ - 'spec/cleanio/cleanio_cli_spec.rb'
32
+
33
+ RSpec/NestedGroups:
34
+ Enabled: false
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cleanio
2
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.
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 `cleanio`, add it to your Gemfile:
20
+ To install `Cleanio`, add it to your Gemfile:
21
21
 
22
22
  ```ruby
23
23
  gem 'cleanio'
@@ -35,19 +35,52 @@ gem install cleanio
35
35
 
36
36
 
37
37
  ## Usage
38
- To clean up comments from a .rb file, simply run:
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
+
46
+ ```
47
+ ### Audit Mode
48
+
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.
50
+
51
+ #### Example
52
+
53
+ ```ruby
54
+ Cleanio::Remover.clean('example.rb', audit: true)
55
+ ```
56
+ #### Output
57
+
58
+ ```bash
59
+ File: example.rb
60
+ Line 1: # This is a comment
61
+ Line 3: # Another comment
44
62
  ```
45
- Alternatively, you can use the command line tool:
63
+
64
+ ### Command-Line Interface (CLI)
65
+
66
+ You can use Cleanio directly from the command line to clean or audit `.rb` files.
67
+
68
+ #### Clean Comments
69
+
70
+ To remove comments from a file, use:
71
+
72
+ ```bash
73
+ cleanio -p path/to/file.rb
74
+ cleanio -p path/to/directory
75
+ ```
76
+ #### Audit mode
77
+
78
+ To run Cleanio in audit mode without modifying files, use the `--audit` flag:
46
79
 
47
80
  ```bash
48
- cleanio -f path/to/your_file.rb
81
+ cleanio -p path/to/file.rb --audit
82
+ cleanio -p path/to/directory --audit
49
83
  ```
50
- This will remove all comments from the specified Ruby file.
51
84
 
52
85
  ## Testing
53
86
  Cleanio uses RSpec for testing. To run the tests, first make sure all dependencies are installed:
@@ -85,6 +118,4 @@ The gem is available as open source under the terms of the MIT License.
85
118
  - Add support multi-line comments (`=begin`...`=end`)
86
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)!
87
120
  - Option to stay documentation comments (e.g. `# @param`) https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation
88
- - Option to recursively clean all files in a directory
89
121
  - 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,28 @@ require "cleanio"
6
6
 
7
7
  options = {}
8
8
  OptionParser.new do |opts|
9
- opts.banner = "Usage: cleanio -f FILE"
9
+ opts.banner = "Usage: cleanio [options]"
10
10
 
11
- opts.on("-f", "--file FIle", "Path to .rb file") do |file|
12
- options[:file] = file
11
+ opts.on("-p", "--path PATH", "Path to a .rb file or directory") do |path|
12
+ options[:path] = path
13
+ end
14
+
15
+ opts.on("--audit", "Run in audit mode to display comments without modifying files") do
16
+ options[:audit] = true
13
17
  end
14
18
  end.parse!
15
19
 
16
- if options[:file]
20
+ if options[:path]
17
21
  begin
18
- Cleanio::Remover.clean(options[:file])
19
- puts "The comments were removed from #{options[:file]}"
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
20
28
  rescue StandardError => e
21
29
  puts "Error: #{e.message}"
22
30
  end
23
31
  else
24
- puts "You need to provide a file path with -f option"
32
+ puts "Please provide a file or directory with -p."
25
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cleanio
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/cleanio.rb CHANGED
@@ -5,17 +5,42 @@ 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
+ 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)
11
- content_cleaned = remove_comments(file_content)
12
- File.write(file_path, content_cleaned)
21
+
22
+ if audit
23
+ audit_comments(file_path, file_content)
24
+ else
25
+ content_cleaned = remove_comments(file_content)
26
+ File.write(file_path, content_cleaned)
27
+ end
13
28
  end
14
29
 
15
30
  def self.validate_file_extension(file_path)
16
31
  raise "Only Ruby files are supported" unless file_path.end_with?(".rb")
17
32
  end
18
33
 
34
+ def self.audit_comments(file_path, content)
35
+ comments = extract_comments(content)
36
+ puts "File: #{file_path}" unless comments.empty?
37
+
38
+ comments.each do |(pos, _, tok, _)|
39
+ line, = pos
40
+ puts " Line #{line}: #{tok.strip}"
41
+ end
42
+ end
43
+
19
44
  def self.remove_comments(content)
20
45
  comments = extract_comments(content)
21
46
  content = process_comments(content, comments)
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.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-15 00:00:00.000000000 Z
11
+ date: 2024-11-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: