no_comments 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/no_comments/comment_detector.rb +0 -3
- data/lib/no_comments/content_processor.rb +0 -12
- data/lib/no_comments/line_parser.rb +2 -14
- data/lib/no_comments/remover.rb +0 -5
- data/lib/no_comments/version.rb +1 -1
- data/lib/no_comments.rb +0 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0866e1f078f1e7465e0196ca4a71cac6956bb607452f7fec15f55ebf7e2f417
|
4
|
+
data.tar.gz: fbec43970d78b83199c3c5288e72fb300bb4382c82c98555c4e7089c4abddf88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32de2f75bcaf62648b319e6bab3da0020115ce52454c63081f91e71a6670a0fa6c5f66e0da0043a1bd22fc68a547a2622c19ddb55feb95046ff06843b34c175e
|
7
|
+
data.tar.gz: 292f77329f185d695359a9d14e0b724118409a2bb44904488d761e7ff89eeaf9ef6f6286630fb6f0ff40f2b8d63089420c774d29a8b575585b72daa197994658
|
@@ -1,12 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# lib/no_comments/comment_detector.rb
|
4
|
-
|
5
3
|
module NoComments
|
6
4
|
module CommentDetector
|
7
5
|
MAGIC_COMMENT_REGEX = /\A#.*\b(?:frozen_string_literal|encoding|coding|warn_indent|fileencoding)\b.*\z/
|
8
6
|
TOOL_COMMENT_REGEX = /\A#\s*(?:rubocop|reek|simplecov|coveralls|pry|byebug|noinspection|sorbet|type)\b/
|
9
|
-
|
10
7
|
def magic_comment?(stripped_line)
|
11
8
|
stripped_line.match?(MAGIC_COMMENT_REGEX)
|
12
9
|
end
|
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# lib/no_comments/content_processor.rb
|
4
|
-
|
5
3
|
require "no_comments/version"
|
6
4
|
require "no_comments/comment_detector"
|
7
5
|
require "no_comments/line_parser"
|
8
|
-
|
9
6
|
module NoComments
|
10
7
|
class ContentProcessor
|
11
8
|
include CommentDetector
|
12
9
|
include LineParser
|
13
|
-
|
14
10
|
def initialize
|
15
11
|
@comments = []
|
16
12
|
@result_lines = []
|
@@ -23,13 +19,11 @@ module NoComments
|
|
23
19
|
|
24
20
|
def process(content)
|
25
21
|
lines = content.lines
|
26
|
-
|
27
22
|
lines.each do |line|
|
28
23
|
@line_number += 1
|
29
24
|
stripped_line = line.strip
|
30
25
|
process_line(line, stripped_line)
|
31
26
|
end
|
32
|
-
|
33
27
|
cleaned_content = @result_lines.join("\n")
|
34
28
|
cleaned_content += "\n" unless cleaned_content.empty?
|
35
29
|
[cleaned_content, @comments]
|
@@ -49,18 +43,14 @@ module NoComments
|
|
49
43
|
|
50
44
|
def handle_initial_lines(line, stripped_line)
|
51
45
|
if stripped_line.empty? || stripped_line.start_with?("#!") || magic_comment?(stripped_line)
|
52
|
-
# Preserve blank lines, shebang lines, and magic comments
|
53
46
|
@result_lines << line.rstrip
|
54
47
|
elsif stripped_line.start_with?("#")
|
55
48
|
if tool_comment?(stripped_line)
|
56
|
-
# Preserve tool-specific comments
|
57
49
|
@result_lines << line.rstrip
|
58
50
|
else
|
59
|
-
# Regular comment at the top, remove it
|
60
51
|
@comments << [@line_number, stripped_line]
|
61
52
|
end
|
62
53
|
else
|
63
|
-
# First code line encountered
|
64
54
|
@code_started = true
|
65
55
|
handle_regular_line(line, stripped_line)
|
66
56
|
end
|
@@ -84,7 +74,6 @@ module NoComments
|
|
84
74
|
elsif (heredoc_start = detect_heredoc_start(line))
|
85
75
|
start_heredoc(line, heredoc_start)
|
86
76
|
elsif stripped_line.start_with?("#") && tool_comment?(stripped_line)
|
87
|
-
# Preserve tool-specific comments anywhere in the code
|
88
77
|
@result_lines << line.rstrip
|
89
78
|
else
|
90
79
|
process_code_line(line)
|
@@ -105,7 +94,6 @@ module NoComments
|
|
105
94
|
def process_code_line(line)
|
106
95
|
code_part, comment_part = split_line(line)
|
107
96
|
if comment_part && tool_comment?(comment_part.strip)
|
108
|
-
# Preserve tool-specific inline comments
|
109
97
|
@result_lines << ("#{code_part.rstrip} #{comment_part.strip}")
|
110
98
|
else
|
111
99
|
@comments << [@line_number, comment_part.strip] if comment_part
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# lib/no_comments/line_parser.rb
|
4
|
-
|
5
3
|
module NoComments
|
6
4
|
module LineParser
|
7
5
|
# rubocop:disable Metrics/MethodLength
|
@@ -9,17 +7,14 @@ module NoComments
|
|
9
7
|
# rubocop:disable Metrics/CyclomaticComplexity
|
10
8
|
# rubocop:disable Metrics/PerceivedComplexity
|
11
9
|
# rubocop:disable Metrics/BlockNesting
|
12
|
-
#
|
13
10
|
def split_line(line)
|
14
11
|
in_single_quote = false
|
15
12
|
in_double_quote = false
|
16
13
|
in_regex = false
|
17
14
|
escape = false
|
18
15
|
index = 0
|
19
|
-
|
20
16
|
while index < line.length
|
21
17
|
char = line[index]
|
22
|
-
|
23
18
|
if escape
|
24
19
|
escape = false
|
25
20
|
else
|
@@ -46,12 +41,12 @@ module NoComments
|
|
46
41
|
end
|
47
42
|
[line, nil]
|
48
43
|
end
|
44
|
+
|
49
45
|
# rubocop:enable Metrics/MethodLength
|
50
46
|
# rubocop:enable Metrics/AbcSize
|
51
47
|
# rubocop:enable Metrics/CyclomaticComplexity
|
52
48
|
# rubocop:enable Metrics/PerceivedComplexity
|
53
49
|
# rubocop:enable Metrics/BlockNesting
|
54
|
-
|
55
50
|
def handle_comment_character(line, index, in_single_quote, in_double_quote, in_regex)
|
56
51
|
unless in_single_quote || in_double_quote || in_regex
|
57
52
|
code_part = line[0...index]
|
@@ -78,18 +73,11 @@ module NoComments
|
|
78
73
|
def preceding_char_is_operator?(line, index)
|
79
74
|
idx = index - 1
|
80
75
|
idx -= 1 while idx >= 0 && line[idx] =~ /\s/
|
81
|
-
|
82
|
-
return true if idx.negative? # Beginning of line or after whitespace
|
83
|
-
|
84
|
-
# Handle special case where preceding character is part of a multi-character operator
|
76
|
+
return true if idx.negative?
|
85
77
|
return true if line[idx - 1..idx] == "::"
|
86
78
|
|
87
79
|
prev_char = line[idx]
|
88
|
-
|
89
|
-
# List of operator characters
|
90
80
|
operator_chars = %w[\[ = + - * / % | & ! < > ^ ~ ( , ? : ; {]
|
91
|
-
|
92
|
-
# Return true if preceding character is an operator
|
93
81
|
operator_chars.include?(prev_char)
|
94
82
|
end
|
95
83
|
end
|
data/lib/no_comments/remover.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# lib/no_comments/remover.rb
|
4
|
-
|
5
3
|
require "no_comments/version"
|
6
4
|
require "no_comments/content_processor"
|
7
|
-
|
8
5
|
module NoComments
|
9
6
|
class Remover
|
10
7
|
def self.clean(file_path, audit: false)
|
@@ -20,10 +17,8 @@ module NoComments
|
|
20
17
|
def self.process_file(file_path, audit: false)
|
21
18
|
validate_file_extension(file_path)
|
22
19
|
content = File.read(file_path)
|
23
|
-
|
24
20
|
processor = ContentProcessor.new
|
25
21
|
cleaned_content, comments = processor.process(content)
|
26
|
-
|
27
22
|
if audit
|
28
23
|
print_audit(file_path, comments)
|
29
24
|
else
|
data/lib/no_comments/version.rb
CHANGED
data/lib/no_comments.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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justyna
|
@@ -31,7 +31,7 @@ files:
|
|
31
31
|
- lib/no_comments/remover.rb
|
32
32
|
- lib/no_comments/version.rb
|
33
33
|
- sig/no_comments.rbs
|
34
|
-
homepage:
|
34
|
+
homepage: https://github.com/justi/no_comments
|
35
35
|
licenses:
|
36
36
|
- MIT
|
37
37
|
metadata:
|
@@ -54,5 +54,6 @@ requirements: []
|
|
54
54
|
rubygems_version: 3.4.19
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
|
-
summary:
|
57
|
+
summary: NoComments is a Ruby gem designed to clean up .rb files by removing unnecessary
|
58
|
+
comments, leaving your code clean and ready for deployment.
|
58
59
|
test_files: []
|