no_comments 0.1.10 → 0.1.12
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 +4 -4
- data/AGENTS.md +48 -0
- data/README.md +7 -4
- data/exe/no_comments +5 -1
- data/lib/no_comments/comment_detector.rb +11 -0
- data/lib/no_comments/content_processor.rb +48 -16
- data/lib/no_comments/remover.rb +5 -5
- data/lib/no_comments/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8b64729d21c62f938c510fe179a75bdd4e642336830f043e37852351fe2f7e7
|
4
|
+
data.tar.gz: 5e36dc7b0751f92f6dba54b42e4f1b89d8612a2ac15e236dbe362e09152b51e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86877162d04e05f36347fb23b9259064e44acae9b0e9bda4411af13884195b023e909ffbf57dca41b04dfe371ef748d663db22c4fcefd5336d0a3e691addaf58
|
7
|
+
data.tar.gz: 0bd8e85a51c4d495aacfa42d8c1c7c755064116761fd56e2a46cc53b14a298bfae65399027daf31dc93a537a5ff64e52bf88f9414be67a10efb91ccac6510a7c
|
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
@@ -13,6 +13,7 @@ It preserves:
|
|
13
13
|
- Shebangs (e.g., #!/usr/bin/env ruby)
|
14
14
|
- Magic comments (e.g., # frozen_string_literal: true)
|
15
15
|
- Tool-defined comments (e.g., # rubocop:disable all)
|
16
|
+
- Documentation comments (e.g., # @param id)
|
16
17
|
|
17
18
|
## Table of Contents
|
18
19
|
1. [When to Use This Gem](#When-to-Use-This-Gem)
|
@@ -112,6 +113,12 @@ no_comments -p path/to/file.rb --audit
|
|
112
113
|
no_comments -p path/to/directory --audit
|
113
114
|
```
|
114
115
|
|
116
|
+
#### Preserve Documentation Comments
|
117
|
+
```bash
|
118
|
+
no_comments -p path/to/file.rb --keep-doc-comments
|
119
|
+
no_comments -p path/to/directory --keep-doc-comments
|
120
|
+
```
|
121
|
+
|
115
122
|
## Testing
|
116
123
|
|
117
124
|
This gem uses RSpec for testing. To run tests:
|
@@ -152,10 +159,6 @@ Please ensure your code follows the existing style and that all tests pass befor
|
|
152
159
|
This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
153
160
|
|
154
161
|
## TODO
|
155
|
-
Planned features for future updates:
|
156
|
-
- **Option to Keep Documentation Comments:**
|
157
|
-
- Preserve comments like # @param or # @return for tools like YARD.
|
158
|
-
Reference: [RuboCop documentation cop](https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Documentation).
|
159
162
|
- **Selective Cleaning:**
|
160
163
|
- Allow users to clean all files in a directory except for specified ones.
|
161
164
|
|
data/exe/no_comments
CHANGED
@@ -15,11 +15,15 @@ OptionParser.new do |opts|
|
|
15
15
|
opts.on("--audit", "Run in audit mode to display comments without modifying files") do
|
16
16
|
options[:audit] = true
|
17
17
|
end
|
18
|
+
|
19
|
+
opts.on("-d", "--keep-doc-comments", "Preserve documentation comments like @param") do
|
20
|
+
options[:keep_doc_comments] = true
|
21
|
+
end
|
18
22
|
end.parse!
|
19
23
|
|
20
24
|
if options[:path]
|
21
25
|
begin
|
22
|
-
NoComments::Remover.clean(options[:path], audit: options[:audit])
|
26
|
+
NoComments::Remover.clean(options[:path], audit: options[:audit], keep_doc_comments: options[:keep_doc_comments])
|
23
27
|
if options[:audit]
|
24
28
|
puts "Audit completed successfully."
|
25
29
|
else
|
@@ -4,6 +4,9 @@ module NoComments
|
|
4
4
|
module CommentDetector
|
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
|
+
DOC_COMMENT_REGEX = /\A#\s*@\w+/
|
8
|
+
NODOC_STRING = ":nodoc:"
|
9
|
+
CLASS_OR_MODULE_REGEX = /\A(?:class|module)\b/
|
7
10
|
def magic_comment?(stripped_line)
|
8
11
|
stripped_line.match?(MAGIC_COMMENT_REGEX)
|
9
12
|
end
|
@@ -11,5 +14,13 @@ module NoComments
|
|
11
14
|
def tool_comment?(stripped_line)
|
12
15
|
stripped_line.match?(TOOL_COMMENT_REGEX)
|
13
16
|
end
|
17
|
+
|
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
|
24
|
+
end
|
14
25
|
end
|
15
26
|
end
|
@@ -7,7 +7,7 @@ module NoComments
|
|
7
7
|
class ContentProcessor
|
8
8
|
include CommentDetector
|
9
9
|
include LineParser
|
10
|
-
def initialize
|
10
|
+
def initialize(keep_doc_comments: false)
|
11
11
|
@comments = []
|
12
12
|
@result_lines = []
|
13
13
|
@in_multiline_comment = false
|
@@ -15,44 +15,50 @@ module NoComments
|
|
15
15
|
@heredoc_delimiter = nil
|
16
16
|
@line_number = 0
|
17
17
|
@code_started = false
|
18
|
+
@keep_doc_comments = keep_doc_comments
|
18
19
|
end
|
19
20
|
|
20
21
|
def process(content)
|
21
22
|
lines = content.lines
|
22
|
-
lines.
|
23
|
-
@line_number
|
23
|
+
lines.each_with_index do |line, index|
|
24
|
+
@line_number = index + 1
|
24
25
|
stripped_line = line.strip
|
25
|
-
|
26
|
+
next_line = next_non_comment_line(lines, index)
|
27
|
+
process_line(line, stripped_line, next_line)
|
26
28
|
end
|
27
29
|
cleaned_content = @result_lines.join("\n")
|
28
30
|
cleaned_content += "\n" unless cleaned_content.empty?
|
29
31
|
[cleaned_content, @comments]
|
30
32
|
end
|
31
33
|
|
32
|
-
def process_line(line, stripped_line)
|
34
|
+
def process_line(line, stripped_line, next_line)
|
33
35
|
if @in_multiline_comment
|
34
36
|
handle_multiline_comment(stripped_line)
|
35
37
|
elsif @in_heredoc
|
36
38
|
handle_heredoc(line, stripped_line)
|
37
39
|
elsif !@code_started
|
38
|
-
handle_initial_lines(line, stripped_line)
|
40
|
+
handle_initial_lines(line, stripped_line, next_line)
|
39
41
|
else
|
40
|
-
handle_regular_line(line, stripped_line)
|
42
|
+
handle_regular_line(line, stripped_line, next_line)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
|
-
def handle_initial_lines(line, stripped_line)
|
46
|
+
def handle_initial_lines(line, stripped_line, next_line)
|
45
47
|
if stripped_line.empty? || stripped_line.start_with?("#!") || magic_comment?(stripped_line)
|
46
48
|
@result_lines << line.rstrip
|
47
49
|
elsif stripped_line.start_with?("#")
|
48
|
-
|
49
|
-
@result_lines << line.rstrip
|
50
|
-
else
|
51
|
-
@comments << [@line_number, stripped_line]
|
52
|
-
end
|
50
|
+
handle_initial_comment_line(line, stripped_line, next_line)
|
53
51
|
else
|
54
52
|
@code_started = true
|
55
|
-
handle_regular_line(line, stripped_line)
|
53
|
+
handle_regular_line(line, stripped_line, next_line)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
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))
|
59
|
+
@result_lines << line.rstrip
|
60
|
+
else
|
61
|
+
@comments << [@line_number, stripped_line]
|
56
62
|
end
|
57
63
|
end
|
58
64
|
|
@@ -68,17 +74,21 @@ module NoComments
|
|
68
74
|
)
|
69
75
|
end
|
70
76
|
|
71
|
-
|
77
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
78
|
+
def handle_regular_line(line, stripped_line, next_line)
|
72
79
|
if stripped_line == "=begin"
|
73
80
|
start_multiline_comment(stripped_line)
|
74
81
|
elsif (heredoc_start = detect_heredoc_start(line))
|
75
82
|
start_heredoc(line, heredoc_start)
|
76
|
-
elsif stripped_line.start_with?("#") &&
|
83
|
+
elsif stripped_line.start_with?("#") &&
|
84
|
+
(tool_comment?(stripped_line) ||
|
85
|
+
(@keep_doc_comments && documentation_comment?(stripped_line, next_line&.strip)))
|
77
86
|
@result_lines << line.rstrip
|
78
87
|
else
|
79
88
|
process_code_line(line)
|
80
89
|
end
|
81
90
|
end
|
91
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
82
92
|
|
83
93
|
def start_multiline_comment(stripped_line)
|
84
94
|
@in_multiline_comment = true
|
@@ -95,12 +105,30 @@ module NoComments
|
|
95
105
|
code_part, comment_part = split_line(line)
|
96
106
|
return handle_empty_line(line) if code_part.strip.empty? && comment_part.nil?
|
97
107
|
return handle_tool_comment_line(code_part, comment_part) if comment_part && tool_comment?(comment_part.strip)
|
108
|
+
return handle_doc_comment_line(code_part, comment_part) if keep_doc_comment?(comment_part)
|
98
109
|
|
99
110
|
handle_regular_code_line(code_part, comment_part)
|
100
111
|
end
|
101
112
|
|
113
|
+
def keep_doc_comment?(comment_part)
|
114
|
+
comment_part && @keep_doc_comments && documentation_comment?(comment_part.strip)
|
115
|
+
end
|
116
|
+
|
102
117
|
private
|
103
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
|
+
|
104
132
|
def handle_empty_line(line)
|
105
133
|
@result_lines << line.rstrip
|
106
134
|
end
|
@@ -109,6 +137,10 @@ module NoComments
|
|
109
137
|
@result_lines << ("#{code_part.rstrip} #{comment_part.strip}")
|
110
138
|
end
|
111
139
|
|
140
|
+
def handle_doc_comment_line(code_part, comment_part)
|
141
|
+
@result_lines << ("#{code_part.rstrip} #{comment_part.strip}")
|
142
|
+
end
|
143
|
+
|
112
144
|
def handle_regular_code_line(code_part, comment_part)
|
113
145
|
@comments << [@line_number, comment_part.strip] if comment_part
|
114
146
|
return if code_part.strip.empty?
|
data/lib/no_comments/remover.rb
CHANGED
@@ -4,20 +4,20 @@ 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)
|
7
|
+
def self.clean(file_path, audit: false, keep_doc_comments: false)
|
8
8
|
if File.directory?(file_path)
|
9
9
|
Dir.glob("#{file_path}/**/*.rb").each do |file|
|
10
|
-
process_file(file, audit: audit)
|
10
|
+
process_file(file, audit: audit, keep_doc_comments: keep_doc_comments)
|
11
11
|
end
|
12
12
|
else
|
13
|
-
process_file(file_path, audit: audit)
|
13
|
+
process_file(file_path, audit: audit, keep_doc_comments: keep_doc_comments)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.process_file(file_path, audit: false)
|
17
|
+
def self.process_file(file_path, audit: false, keep_doc_comments: false)
|
18
18
|
validate_file_extension(file_path)
|
19
19
|
content = File.read(file_path)
|
20
|
-
processor = ContentProcessor.new
|
20
|
+
processor = ContentProcessor.new(keep_doc_comments: keep_doc_comments)
|
21
21
|
cleaned_content, comments = processor.process(content)
|
22
22
|
if audit
|
23
23
|
print_audit(file_path, comments)
|
data/lib/no_comments/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.12
|
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
|