forked from sds/scss-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.rb
43 lines (36 loc) · 1002 Bytes
/
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
37
38
39
40
41
42
43
module SCSSLint
# Checks for uses of renderable comments (/* ... */)
class Linter::Comment < Linter
include LinterRegistry
def visit_comment(node)
add_lint(node, message) unless valid_comment?(node)
end
private
def valid_comment?(node)
allowed_type =
if config.fetch('style', 'silent') == 'silent'
node.invisible?
else
!node.invisible?
end
return true if allowed_type
# Otherwise check if comment contains content that excludes it (i.e. a
# copyright notice for loud comments)
allowed?(node)
end
# @param node [CommentNode]
# @return [Boolean]
def allowed?(node)
return false unless config['allowed']
re = Regexp.new(config['allowed'])
node.value.join.match(re)
end
def message
if config.fetch('style', 'silent') == 'silent'
'Use `//` comments everywhere'
else
'Use `/* */` comments everywhere'
end
end
end
end