forked from Shopify/theme-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissing_enable_comment.rb
36 lines (29 loc) · 1001 Bytes
/
missing_enable_comment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true
module ThemeCheck
class MissingEnableComment < LiquidCheck
severity :error
doc docs_url(__FILE__)
# Don't allow this check to be disabled with a comment,
# as we need to be able to check for disabled checks.
can_disable false
def on_document(_node)
@disabled_checks = DisabledChecks.new
end
def on_comment(node)
@disabled_checks.update(node)
end
def on_inline_comment(node)
@disabled_checks.update(node)
end
def after_document(node)
checks_missing_end_index = @disabled_checks.checks_missing_end_index
return if checks_missing_end_index.empty?
message = if checks_missing_end_index.any? { |name| name == :all }
"All checks were"
else
checks_missing_end_index.join(', ') + " " + (checks_missing_end_index.size == 1 ? "was" : "were")
end
add_offense("#{message} disabled but not re-enabled with theme-check-enable", node: node)
end
end
end