erblint-github 0.4.0 → 0.4.1

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: d329206d7b3c42304a1279e5077122c74757ce8959272c1c76bd870559becc0a
4
- data.tar.gz: e0d34fb46bc77014dd2124fbab66af6bffe1385cd381b0c2e54a4520d5b02876
3
+ metadata.gz: dcbe592387330f5ba0247660e9ed42074c9efbf0a0b2fa2ac02b9a846ecd2173
4
+ data.tar.gz: 51111580933382545db7a1603b897026cb5566febc494f83aaf4a57e2b02c525
5
5
  SHA512:
6
- metadata.gz: 2893fe01bc4fa5f16be61698646f649c5098eeefa4268be7f69ee7ef7bd3c7fbe4a6b4f5c09ecfeedbba3441c62e96ae767253d1058171b00c92c7f88992aedd
7
- data.tar.gz: 0a3cbff707c22df4bbcb4e6da28e86ad9f2d46cbe0cc61a241a7f163e584846eaa671639a736a32efdfc90463f8abb14c45069b7f71aaea2fd3467f0812a86a2
6
+ metadata.gz: 6bec2b9610ad690d506abc4b4e3e450cf492ccd36ee4784ef95902bc322d229b3435f3a19e9e06a434b7dc3c2d502872f1767c8301dfc3182625c7b5a4d1efa8
7
+ data.tar.gz: 3796bc95ceebd37e04f711a40363eefe4681f91837d4936dee34d78b815a1cb50b8186cfce295a815147c010c56fed596a824e08d74596a028c0582b9ffda5c9
@@ -27,6 +27,39 @@ module ERBLint
27
27
  [value].compact
28
28
  end
29
29
 
30
+ def counter_correct?(processed_source)
31
+ comment_node = nil
32
+ expected_count = 0
33
+ rule_name = self.class.name.gsub("ERBLint::Linters::", "")
34
+ offenses_count = @offenses.length
35
+
36
+ processed_source.parser.ast.descendants(:erb).each do |node|
37
+ indicator_node, _, code_node, = *node
38
+ indicator = indicator_node&.loc&.source
39
+ comment = code_node&.loc&.source&.strip
40
+
41
+ if indicator == "#" && comment.start_with?("erblint:counter") && comment.match(rule_name)
42
+ comment_node = node
43
+ expected_count = comment.match(/\s(\d+)\s?$/)[1].to_i
44
+ end
45
+ end
46
+
47
+ if offenses_count.zero?
48
+ # have to adjust to get `\n` so we delete the whole line
49
+ add_offense(processed_source.to_source_range(comment_node.loc.adjust(end_pos: 1)), "Unused erblint:counter comment for #{rule_name}", "") if comment_node
50
+ return
51
+ end
52
+
53
+ first_offense = @offenses[0]
54
+
55
+ if comment_node.nil?
56
+ add_offense(processed_source.to_source_range(first_offense.source_range), "#{rule_name}: If you must, add <%# erblint:counter #{rule_name} #{offenses_count} %> to bypass this check.", "<%# erblint:counter #{rule_name} #{offenses_count} %>")
57
+ else
58
+ clear_offenses
59
+ add_offense(processed_source.to_source_range(comment_node.loc), "Incorrect erblint:counter number for #{rule_name}. Expected: #{expected_count}, actual: #{offenses_count}.", "<%# erblint:counter #{rule_name} #{offenses_count} %>") if expected_count != offenses_count
60
+ end
61
+ end
62
+
30
63
  # Map possible values from condition
31
64
  def basic_conditional_code_check(code)
32
65
  conditional_match = code.match(/["'](.+)["']\sif|unless\s.+/) || code.match(/.+\s?\s["'](.+)["']\s:\s["'](.+)["']/)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erblint-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-09 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb_lint