no_comments 0.1.6 → 0.1.8

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: 71ade70ce6b697e2f4f4244766a9b7914c04b628eb9c87ba4f4273b8c4cbb846
4
- data.tar.gz: 9ed3453c9e8c9fe097e6b5506ada7917adcd54e10ec7bfd0e2297508612eff12
3
+ metadata.gz: c027187e4d044c39f2f94274675ac81db2753aca4824be006543aea44421de91
4
+ data.tar.gz: 024e089a04c15fd8528361d918c0da35a182551f14f0d4567d1aebc9e473d855
5
5
  SHA512:
6
- metadata.gz: 6768a1bafedf5cf9abb143c5a08cca1bd534122d888fde625ebb124fb1591b6f6fce9c8585463ab2f27692a322c85c1f119d454b4f4847c03428545174a8b0a9
7
- data.tar.gz: c3f05e89997be0923516daf3599a080b222d19c1cbca23e5b52553e282fcdfe7246e7cbbc1e2b4fa543181765b23dc36f35ee307337c2d29fd9ca39b72e3a55f
6
+ metadata.gz: d055e920017f0fd4deaa25ee331aaaf37b851120dc3297178fecc43bd06195ed3a1df9cea969298b66efbb0d0b0add3ec271abfa0f8b334426e6750facacadd0
7
+ data.tar.gz: 6307ff40e3e67b62794e41498fb4e3a80934ee13cfa376ea916dd81cf72b2506a020bc9fd9fe5243db9e1b230ef54f438faf13d41164a8127be0e1aea26269a1
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoComments
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
data/lib/no_comments.rb CHANGED
@@ -2,6 +2,5 @@
2
2
 
3
3
  require "no_comments/content_processor"
4
4
  require "no_comments/remover"
5
-
6
5
  module NoComments
7
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no_comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
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-17 00:00:00.000000000 Z
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -31,10 +31,12 @@ 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:
38
+ source_code_uri: https://github.com/justi/no_comments
39
+ homepage_uri: https://github.com/justi/no_comments
38
40
  rubygems_mfa_required: 'true'
39
41
  post_install_message:
40
42
  rdoc_options: []
@@ -54,5 +56,6 @@ requirements: []
54
56
  rubygems_version: 3.4.19
55
57
  signing_key:
56
58
  specification_version: 4
57
- summary: Remove comments from Ruby files
59
+ summary: NoComments is a Ruby gem designed to clean up .rb files by removing unnecessary
60
+ comments, leaving your code clean and ready for deployment.
58
61
  test_files: []