no_comments 0.1.12 → 0.1.14

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: e8b64729d21c62f938c510fe179a75bdd4e642336830f043e37852351fe2f7e7
4
- data.tar.gz: 5e36dc7b0751f92f6dba54b42e4f1b89d8612a2ac15e236dbe362e09152b51e5
3
+ metadata.gz: 5680480af7ba824c7591147b05fb53fc1368695d834518889d42707c9f98306b
4
+ data.tar.gz: 562fc50c7bcce1ee7dde8296c984dbde4935de25930c4adffbd3c99f22f5cac5
5
5
  SHA512:
6
- metadata.gz: 86877162d04e05f36347fb23b9259064e44acae9b0e9bda4411af13884195b023e909ffbf57dca41b04dfe371ef748d663db22c4fcefd5336d0a3e691addaf58
7
- data.tar.gz: 0bd8e85a51c4d495aacfa42d8c1c7c755064116761fd56e2a46cc53b14a298bfae65399027daf31dc93a537a5ff64e52bf88f9414be67a10efb91ccac6510a7c
6
+ metadata.gz: 7f26162ead8d4299371496f7c949aa0992bca529bc2e5ee63f52a2c159e2e493000255cf2676fd0ae79666c73521061fca2ee76fe5ace79bb33a6d1897f8cb39
7
+ data.tar.gz: c2205fc1deb3fac280a5b3b3b33bfc1106d68508a9c4b56987d1f7419778d6cba429b7c1f6ed8658d2dce3f3bc92bc37c3a33bc7fd7053960efb5a61106e73c8
data/README.md CHANGED
@@ -16,8 +16,8 @@ It preserves:
16
16
  - Documentation comments (e.g., # @param id)
17
17
 
18
18
  ## Table of Contents
19
- 1. [When to Use This Gem](#When-to-Use-This-Gem)
20
- 2. [When Not to Use This Gem](#When-Not-to-Use-This-Gem)
19
+ 1. [When to Use This Gem](#when-to-use-this-gem)
20
+ 2. [When Not to Use This Gem](#when-not-to-use-this-gem)
21
21
  3. [Installation](#Installation)
22
22
  4. [Usage](#Usage)
23
23
  - [Audit Mode](#Audit-Mode)
@@ -29,21 +29,22 @@ It preserves:
29
29
 
30
30
  ## When to Use This Gem
31
31
 
32
- NoComments is particularly useful in the following scenarios:
32
+ NoComments keeps Ruby code tidy by automatically removing unnecessary comments. It can be integrated into an MCP server to sanitize scripts before deployment, ensuring that the code published on the server is clean and production ready.
33
33
 
34
- - **Auto-Generated or Boilerplate Code:** Helps clean up scaffolding or boilerplate comments, commonly generated in frameworks like Rails.
35
- - **Codebases with Overused Comments:** Removes redundant comments that restate obvious code.
36
- - **Continuous Integration/Code Review Workflows:** Automates comment cleanup during CI/CD processes.
37
- - **Educational Projects:** Streamlines code by removing teaching-related comments after the learning phase.
38
- - **Maintaining Open Source Projects:** Ensures consistency by removing unnecessary comments in contributions.
34
+ **Example use cases:**
35
+ - **Auto-generated code** clear scaffolding comments produced by frameworks such as Rails.
36
+ - **Projects with excessive comments** remove remarks that simply restate obvious code.
37
+ - **CI/CD pipelines** incorporate NoComments as a step that enforces code cleanliness.
38
+ - **Educational projects** clean files once learning phases are complete.
39
+ - **Maintaining open source projects** – keep contributions consistent and readable.
39
40
 
40
41
  ## When Not to Use This Gem
41
42
 
42
- While the gem is powerful, it may not be suitable in these scenarios:
43
+ While NoComments streamlines your code, it is not a replacement for documentation comments or notes that are required for compliance.
43
44
 
44
- - **Code with Valuable Documentation Comments:** Avoid using the gem if your code relies on comments for explaining complex logic or business rules.
45
- - **Codebases Requiring Compliance:** In regulated industries, where specific comments are required for audits or documentation purposes.
46
- - **Highly Dynamic Environments:** In fast-changing projects, comments might provide crucial context for recent changes or decisions.
45
+ - **Code with valuable documentation** when comments explain complex algorithms or important business decisions.
46
+ - **Regulated industries** if comments are mandatory for audit purposes.
47
+ - **Rapidly changing projects** when comments capture ongoing discussions or decisions.
47
48
 
48
49
  ## Installation
49
50
 
@@ -77,6 +78,12 @@ NoComments::Remover.clean('path/to/your_file.rb')
77
78
 
78
79
  # Clean all `.rb` files in a directory
79
80
  NoComments::Remover.clean('path/to/your_directory')
81
+
82
+ # Clean all `.rb` files except selected ones or directories
83
+ NoComments::Remover.clean('path/to/your_directory', exclude: ['skip.rb', 'subdir'])
84
+ # Multiple files or directories can be provided, and blank entries are ignored.
85
+ # Absolute or relative paths work, and directories may have a trailing slash.
86
+ NoComments::Remover.clean('/abs/path/project', exclude: ['/abs/path/project/subdir/'])
80
87
  ```
81
88
  ### Audit Mode
82
89
  Audit mode allows you to preview the comments that would be removed without modifying the files. Use the `audit: true` flag with the `clean` method:
@@ -119,6 +126,13 @@ no_comments -p path/to/file.rb --keep-doc-comments
119
126
  no_comments -p path/to/directory --keep-doc-comments
120
127
  ```
121
128
 
129
+ #### Exclude Paths
130
+ ```bash
131
+ no_comments -p path/to/directory --exclude file1.rb,subdir
132
+ # absolute paths and trailing slashes are supported. Blank entries are ignored.
133
+ no_comments -p /project --exclude /project/subdir/
134
+ ```
135
+
122
136
  ## Testing
123
137
 
124
138
  This gem uses RSpec for testing. To run tests:
@@ -127,7 +141,7 @@ This gem uses RSpec for testing. To run tests:
127
141
  ```bash
128
142
  bundle install
129
143
  ```
130
- 2. Run the test suite::
144
+ 2. Run the test suite:
131
145
  ```bash
132
146
  bundle exec rspec
133
147
  ```
@@ -159,7 +173,7 @@ Please ensure your code follows the existing style and that all tests pass befor
159
173
  This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
160
174
 
161
175
  ## TODO
162
- - **Selective Cleaning:**
176
+ - [x] **Selective Cleaning:**
163
177
  - Allow users to clean all files in a directory except for specified ones.
164
178
 
165
179
  ---
data/exe/no_comments CHANGED
@@ -19,11 +19,20 @@ OptionParser.new do |opts|
19
19
  opts.on("-d", "--keep-doc-comments", "Preserve documentation comments like @param") do
20
20
  options[:keep_doc_comments] = true
21
21
  end
22
+
23
+ opts.on("-e", "--exclude x,y,z", Array, "Files to exclude when cleaning a directory") do |list|
24
+ options[:exclude] = list
25
+ end
22
26
  end.parse!
23
27
 
24
28
  if options[:path]
25
29
  begin
26
- NoComments::Remover.clean(options[:path], audit: options[:audit], keep_doc_comments: options[:keep_doc_comments])
30
+ NoComments::Remover.clean(
31
+ options[:path],
32
+ audit: options[:audit],
33
+ keep_doc_comments: options[:keep_doc_comments],
34
+ exclude: options[:exclude] || []
35
+ )
27
36
  if options[:audit]
28
37
  puts "Audit completed successfully."
29
38
  else
@@ -4,9 +4,14 @@ require "no_comments/version"
4
4
  require "no_comments/content_processor"
5
5
  module NoComments
6
6
  class Remover
7
- def self.clean(file_path, audit: false, keep_doc_comments: false)
7
+ def self.clean(file_path, audit: false, keep_doc_comments: false, exclude: [])
8
8
  if File.directory?(file_path)
9
+ filtered = exclude.reject { |p| p.nil? || p.strip.empty? }
10
+ excluded = filtered.map { |f| File.expand_path(f, file_path) }
9
11
  Dir.glob("#{file_path}/**/*.rb").each do |file|
12
+ absolute = File.expand_path(file)
13
+ next if excluded_file?(absolute, excluded)
14
+
10
15
  process_file(file, audit: audit, keep_doc_comments: keep_doc_comments)
11
16
  end
12
17
  else
@@ -14,6 +19,13 @@ module NoComments
14
19
  end
15
20
  end
16
21
 
22
+ def self.excluded_file?(absolute, paths)
23
+ paths.any? do |path|
24
+ absolute == path ||
25
+ (File.directory?(path) && absolute.start_with?(File.join(path, "")))
26
+ end
27
+ end
28
+
17
29
  def self.process_file(file_path, audit: false, keep_doc_comments: false)
18
30
  validate_file_extension(file_path)
19
31
  content = File.read(file_path)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoComments
4
- VERSION = "0.1.12"
4
+ VERSION = "0.1.14"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no_comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justyna