ngworder 0.1.2 → 0.1.3

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: 23598b09a95c1a5d1c7362d008a6fd720abedca91cd3c3203c785184f3e44c71
4
- data.tar.gz: 980852622d530f10d99555c6f7ec15d4979882ca61b1d605cd92f19af914e5d5
3
+ metadata.gz: 58b3776df5c32d087309ec1988bc4fdb20627dc5140f66833ed2e6fed8d6e828
4
+ data.tar.gz: 5cc6fbd146932a83bef18dd91f3c939ca9d7f4bb99b7270ccd29ebb27664b630
5
5
  SHA512:
6
- metadata.gz: b2b577059d5e7f2c6c0491f03ac5d89dda7ae0593fee619e43918c897734330b746e170370e3602b2ac7bb7f59066370a9ce56254643df3ab511129f6acc86b3
7
- data.tar.gz: 2686e87281aab43bb92e6413a502bcc1fd6d733f446f3a1d8e8438790d48dae85bcdac3f985f50ddbfe5b117170b8b3e59ee9a2dbae91f22c92375fc9958a2d9
6
+ metadata.gz: c628c99ca4def6086d7c1df8ccb927bcea84cb89901c967d3c1eb03a6c58b5dd0d107359118fd85e033cad7a2a0ada609b1e74d6d8d7f0a287e805c43e737ece
7
+ data.tar.gz: 755cb4ea9bc96a0bd62f5f40acba64d1d2c8b0fb838a8ea80eb00bb3d42753bb840ddb45e77be94cd6a5d04bbf8ca980a730a81b4cc971fe9e0dd17cf92fa850
data/README.md CHANGED
@@ -38,7 +38,7 @@ Example:
38
38
 
39
39
  ## Output
40
40
  ```
41
- path/to/file:line:col match NG:<rule>
41
+ path/to/file:line:col match # comment
42
42
  ```
43
43
 
44
44
  ## Performance
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ngworder
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/ngworder.rb CHANGED
@@ -5,17 +5,18 @@ require "tempfile"
5
5
  require_relative "ngworder/version"
6
6
 
7
7
  module Ngworder
8
- Rule = Struct.new(:matcher, :label, :excludes)
8
+ Rule = Struct.new(:matcher, :label, :excludes, :comment)
9
9
  Matcher = Struct.new(:type, :pattern, :label)
10
10
 
11
11
  module Parser
12
12
  module_function
13
13
 
14
- def strip_comment(line)
14
+ def split_comment(line)
15
15
  out = +""
16
16
  escaped = false
17
+ comment = nil
17
18
 
18
- line.each_char do |ch|
19
+ line.each_char.with_index do |ch, idx|
19
20
  if escaped
20
21
  out << ch
21
22
  escaped = false
@@ -28,12 +29,15 @@ module Ngworder
28
29
  next
29
30
  end
30
31
 
31
- break if ch == "#"
32
+ if ch == "#"
33
+ comment = line[(idx + 1)..-1]
34
+ break
35
+ end
32
36
 
33
37
  out << ch
34
38
  end
35
39
 
36
- out
40
+ [out, comment]
37
41
  end
38
42
 
39
43
  def split_unescaped_bang(line)
@@ -127,7 +131,7 @@ module Ngworder
127
131
  rules = []
128
132
 
129
133
  File.readlines(path, chomp: true).each do |line|
130
- content = strip_comment(line)
134
+ content, comment = split_comment(line)
131
135
  next if content.strip.empty?
132
136
 
133
137
  parts = split_unescaped_bang(content)
@@ -135,7 +139,9 @@ module Ngworder
135
139
  next unless base
136
140
 
137
141
  excludes = parts.map { |part| parse_matcher(part, trim: :both) }.compact
138
- rules << Rule.new(base, base.label, excludes)
142
+ comment = comment&.strip
143
+ comment = nil if comment.nil? || comment.empty?
144
+ rules << Rule.new(base, base.label, excludes, comment)
139
145
  end
140
146
 
141
147
  rules
@@ -272,6 +278,12 @@ module Ngworder
272
278
  "\e[35m#{text}\e[0m"
273
279
  end
274
280
 
281
+ colorize_path = lambda do |text|
282
+ return text unless color_enabled
283
+
284
+ "\e[36m#{text}\e[0m"
285
+ end
286
+
275
287
  highlight_line = lambda do |line, span|
276
288
  return line unless color_enabled
277
289
 
@@ -323,7 +335,9 @@ module Ngworder
323
335
  found = true
324
336
  col_no = span[0] + 1
325
337
  match_text = colorize_match.call(span[2])
326
- puts "#{path}:#{line_no}:#{col_no} #{match_text} NG:#{rule.label}"
338
+ suffix = rule.comment ? " # #{rule.comment}" : ""
339
+ path_text = colorize_path.call(path)
340
+ puts "#{path_text}:#{line_no}:#{col_no} #{match_text}#{suffix}"
327
341
  puts highlight_line.call(line, span) if line_enabled
328
342
  end
329
343
  end
@@ -353,7 +367,9 @@ module Ngworder
353
367
  found = true
354
368
  col_no = span[0] + 1
355
369
  match_text = colorize_match.call(span[2])
356
- puts "#{path}:#{line_no}:#{col_no} #{match_text} NG:#{rule.label}"
370
+ suffix = rule.comment ? " # #{rule.comment}" : ""
371
+ path_text = colorize_path.call(path)
372
+ puts "#{path_text}:#{line_no}:#{col_no} #{match_text}#{suffix}"
357
373
  puts highlight_line.call(line, span) if line_enabled
358
374
  end
359
375
  end
@@ -372,7 +388,9 @@ module Ngworder
372
388
  found = true
373
389
  col_no = span[0] + 1
374
390
  match_text = colorize_match.call(span[2])
375
- puts "#{path}:#{line_no}:#{col_no} #{match_text} NG:#{rule.label}"
391
+ suffix = rule.comment ? " # #{rule.comment}" : ""
392
+ path_text = colorize_path.call(path)
393
+ puts "#{path_text}:#{line_no}:#{col_no} #{match_text}#{suffix}"
376
394
  puts highlight_line.call(line, span) if line_enabled
377
395
  end
378
396
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ngworder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masanori Kado