no_comments 0.1.11 → 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: c98d97eb96221297ef0ef1b6140abd04ac9a54ce759fdfd46b0708497b223022
4
- data.tar.gz: 42a109143ae3b1ab99a176e625a74dbe350d878838eb40b93c5f483f13428f11
3
+ metadata.gz: 5680480af7ba824c7591147b05fb53fc1368695d834518889d42707c9f98306b
4
+ data.tar.gz: 562fc50c7bcce1ee7dde8296c984dbde4935de25930c4adffbd3c99f22f5cac5
5
5
  SHA512:
6
- metadata.gz: 82418111acf7d4de92b39c52cd6bafb32959b1ae024836d53a7be3a2b66257cd13299e4b179f84506012debc71db3c48bcbade705e6df0cb18b7a83fa09cc550
7
- data.tar.gz: 01df35d37bc0e4200beb1c15c6b4f2846d2904faa681d20706e218681999e7f4e946ef7df0eab2ede035f415b095d784d06e37ffed15062dc5cbae206e52d510
6
+ metadata.gz: 7f26162ead8d4299371496f7c949aa0992bca529bc2e5ee63f52a2c159e2e493000255cf2676fd0ae79666c73521061fca2ee76fe5ace79bb33a6d1897f8cb39
7
+ data.tar.gz: c2205fc1deb3fac280a5b3b3b33bfc1106d68508a9c4b56987d1f7419778d6cba429b7c1f6ed8658d2dce3f3bc92bc37c3a33bc7fd7053960efb5a61106e73c8
data/AGENTS.md ADDED
@@ -0,0 +1,48 @@
1
+ # Instructions
2
+ - The user will provide a task.
3
+ - The task involves working with Git repositories in your current working directory.
4
+ - Wait for all terminal commands to be completed (or terminate them) before finishing.
5
+
6
+ # Git instructions
7
+ If completing the user's task requires writing or modifying files:
8
+ - Do not create new branches.
9
+ - Use git to commit your changes.
10
+ - If pre-commit fails, fix issues and retry.
11
+ - Check git status to confirm your commit. You must leave your worktree in a clean state.
12
+ - Only committed code will be evaluated.
13
+ - Do not modify or amend existing commits.
14
+
15
+ # AGENTS.md spec
16
+ - Containers often contain AGENTS.md files. These files can appear anywhere in the container's filesystem. Typical locations include `/`, `~`, and in various places inside of Git repos.
17
+ - These files are a way for humans to give you (the agent) instructions or tips for working within the container.
18
+ - Some examples might be: coding conventions, info about how code is organized, or instructions for how to run or test code.
19
+ - AGENTS.md files may provide instructions about PR messages (messages attached to a GitHub Pull Request produced by the agent, describing the PR). These instructions should be respected.
20
+ - Instructions in AGENTS.md files:
21
+ - The scope of an AGENTS.md file is the entire directory tree rooted at the folder that contains it.
22
+ - For every file you touch in the final patch, you must obey instructions in any AGENTS.md file whose scope includes that file.
23
+ - Instructions about code style, structure, naming, etc. apply only to code within the AGENTS.md file's scope, unless the file states otherwise.
24
+ - More-deeply-nested AGENTS.md files take precedence in the case of conflicting instructions.
25
+ - Direct system/developer/user instructions (as part of a prompt) take precedence over AGENTS.md instructions.
26
+ - AGENTS.md files need not live only in Git repos. For example, you may find one in your home directory.
27
+ - If the AGENTS.md includes programmatic checks to verify your work, you MUST run all of them and make a best effort to validate that the checks pass AFTER all code changes have been made.
28
+ - This applies even for changes that appear simple, i.e. documentation. You still must run all of the programmatic checks.
29
+
30
+ # Citations instructions
31
+ - If you browsed files or used terminal commands, you must add citations to the final response (not the body of the PR message) where relevant. Citations reference file paths and terminal outputs with the following formats:
32
+ 1) `F:<file_path>†L<line_start>(-L<line_end>)?`
33
+ - File path citations must start with `F:`. `file_path` is the exact file path of the file relative to the root of the repository that contains the relevant text.
34
+ - `line_start` is the 1-indexed start line number of the relevant output within that file.
35
+ 2) `<chunk_id>†L<line_start>(-L<line_end>)?`
36
+ - Where chunk_id is the chunk_id of the terminal output, line_start and line_end are the 1-indexed start and end line numbers of the relevant output within that chunk.
37
+ - Line ends are optional, and if not provided, line end is the same as line start, so only 1 line is cited.
38
+ - Ensure that the line numbers are correct, and that the cited file paths or terminal outputs are directly relevant to the word or clause before the citation.
39
+ - Do not cite completely empty lines inside the chunk, only cite lines that have content.
40
+ - Only cite from file paths and terminal outputs, DO NOT cite from previous pr diffs and comments, nor cite git hashes as chunk ids.
41
+ - Use file path citations that reference any code changes, documentation or files, and use terminal citations only for relevant terminal output.
42
+ - Prefer file citations over terminal citations unless the terminal output is directly relevant to the clauses before the citation, i.e. clauses on test results.
43
+ - For PR creation tasks, use file citations when referring to code changes in the summary section of your final response, and terminal citations in the testing section.
44
+ - For question-answering tasks, you should only use terminal citations if you need to programmatically verify an answer (i.e. counting lines of code). Otherwise, use file citations.
45
+
46
+ Add the crucial information that the branch name should be written in english if not please translate it into english.
47
+
48
+ Before commit run 'bundle exec rspec' 'bundle exec bundler-audit --update' and 'bundle exec rubocop --parallel' and the next fix the problems if appear
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
@@ -5,6 +5,8 @@ module NoComments
5
5
  MAGIC_COMMENT_REGEX = /\A#.*\b(?:frozen_string_literal|encoding|coding|warn_indent|fileencoding)\b.*\z/
6
6
  TOOL_COMMENT_REGEX = /\A#\s*(?:rubocop|reek|simplecov|coveralls|pry|byebug|noinspection|sorbet|type)\b/
7
7
  DOC_COMMENT_REGEX = /\A#\s*@\w+/
8
+ NODOC_STRING = ":nodoc:"
9
+ CLASS_OR_MODULE_REGEX = /\A(?:class|module)\b/
8
10
  def magic_comment?(stripped_line)
9
11
  stripped_line.match?(MAGIC_COMMENT_REGEX)
10
12
  end
@@ -13,8 +15,12 @@ module NoComments
13
15
  stripped_line.match?(TOOL_COMMENT_REGEX)
14
16
  end
15
17
 
16
- def documentation_comment?(stripped_line)
17
- stripped_line.match?(DOC_COMMENT_REGEX)
18
+ def documentation_comment?(stripped_line, next_line = nil)
19
+ return true if stripped_line.match?(DOC_COMMENT_REGEX)
20
+ return true if stripped_line.include?(NODOC_STRING)
21
+ return true if next_line&.match?(CLASS_OR_MODULE_REGEX)
22
+
23
+ false
18
24
  end
19
25
  end
20
26
  end
@@ -20,41 +20,42 @@ module NoComments
20
20
 
21
21
  def process(content)
22
22
  lines = content.lines
23
- lines.each do |line|
24
- @line_number += 1
23
+ lines.each_with_index do |line, index|
24
+ @line_number = index + 1
25
25
  stripped_line = line.strip
26
- process_line(line, stripped_line)
26
+ next_line = next_non_comment_line(lines, index)
27
+ process_line(line, stripped_line, next_line)
27
28
  end
28
29
  cleaned_content = @result_lines.join("\n")
29
30
  cleaned_content += "\n" unless cleaned_content.empty?
30
31
  [cleaned_content, @comments]
31
32
  end
32
33
 
33
- def process_line(line, stripped_line)
34
+ def process_line(line, stripped_line, next_line)
34
35
  if @in_multiline_comment
35
36
  handle_multiline_comment(stripped_line)
36
37
  elsif @in_heredoc
37
38
  handle_heredoc(line, stripped_line)
38
39
  elsif !@code_started
39
- handle_initial_lines(line, stripped_line)
40
+ handle_initial_lines(line, stripped_line, next_line)
40
41
  else
41
- handle_regular_line(line, stripped_line)
42
+ handle_regular_line(line, stripped_line, next_line)
42
43
  end
43
44
  end
44
45
 
45
- def handle_initial_lines(line, stripped_line)
46
+ def handle_initial_lines(line, stripped_line, next_line)
46
47
  if stripped_line.empty? || stripped_line.start_with?("#!") || magic_comment?(stripped_line)
47
48
  @result_lines << line.rstrip
48
49
  elsif stripped_line.start_with?("#")
49
- handle_initial_comment_line(line, stripped_line)
50
+ handle_initial_comment_line(line, stripped_line, next_line)
50
51
  else
51
52
  @code_started = true
52
- handle_regular_line(line, stripped_line)
53
+ handle_regular_line(line, stripped_line, next_line)
53
54
  end
54
55
  end
55
56
 
56
- def handle_initial_comment_line(line, stripped_line)
57
- if tool_comment?(stripped_line) || (@keep_doc_comments && documentation_comment?(stripped_line))
57
+ def handle_initial_comment_line(line, stripped_line, next_line)
58
+ if tool_comment?(stripped_line) || (@keep_doc_comments && documentation_comment?(stripped_line, next_line&.strip))
58
59
  @result_lines << line.rstrip
59
60
  else
60
61
  @comments << [@line_number, stripped_line]
@@ -73,19 +74,21 @@ module NoComments
73
74
  )
74
75
  end
75
76
 
76
- def handle_regular_line(line, stripped_line)
77
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
78
+ def handle_regular_line(line, stripped_line, next_line)
77
79
  if stripped_line == "=begin"
78
80
  start_multiline_comment(stripped_line)
79
81
  elsif (heredoc_start = detect_heredoc_start(line))
80
82
  start_heredoc(line, heredoc_start)
81
83
  elsif stripped_line.start_with?("#") &&
82
84
  (tool_comment?(stripped_line) ||
83
- (@keep_doc_comments && documentation_comment?(stripped_line)))
85
+ (@keep_doc_comments && documentation_comment?(stripped_line, next_line&.strip)))
84
86
  @result_lines << line.rstrip
85
87
  else
86
88
  process_code_line(line)
87
89
  end
88
90
  end
91
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
89
92
 
90
93
  def start_multiline_comment(stripped_line)
91
94
  @in_multiline_comment = true
@@ -113,6 +116,19 @@ module NoComments
113
116
 
114
117
  private
115
118
 
119
+ def next_non_comment_line(lines, index)
120
+ j = index + 1
121
+ while j < lines.length
122
+ line = lines[j]
123
+ stripped = line.strip
124
+ return nil if stripped.empty?
125
+ return line unless stripped.start_with?("#")
126
+
127
+ j += 1
128
+ end
129
+ nil
130
+ end
131
+
116
132
  def handle_empty_line(line)
117
133
  @result_lines << line.rstrip
118
134
  end
@@ -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.11"
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.11
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justyna
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - ".rspec"
20
20
  - ".rubocop.yml"
21
+ - AGENTS.md
21
22
  - LICENSE
22
23
  - README.md
23
24
  - Rakefile