forked from sds/scss-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
property_spelling.rb
61 lines (49 loc) · 1.81 KB
/
property_spelling.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module SCSSLint
# Checks for misspelled properties.
class Linter::PropertySpelling < Linter
include LinterRegistry
KNOWN_PROPERTIES = File.open(File.join(SCSS_LINT_DATA, 'properties.txt'))
.read
.split
.to_set
def visit_root(_node)
@extra_properties = Array(config['extra_properties']).to_set
@disabled_properties = Array(config['disabled_properties']).to_set
yield # Continue linting children
end
def visit_prop(node)
# Ignore properties with interpolation
return if node.name.count > 1 || !node.name.first.is_a?(String)
nested_properties = node.children.select { |child| child.is_a?(Sass::Tree::PropNode) }
if nested_properties.any?
# Treat nested properties specially, as they are a concatenation of the
# parent with child property
nested_properties.each do |nested_prop|
check_property(nested_prop, node.name.join)
end
else
check_property(node)
end
end
private
def check_property(node, prefix = nil) # rubocop:disable CyclomaticComplexity
return if contains_interpolation?(node)
name = prefix ? "#{prefix}-" : ''
name += node.name.join
# Ignore vendor-prefixed properties
return if name.start_with?('-')
return if known_property?(name) && !@disabled_properties.include?(name)
if @disabled_properties.include?(name)
add_lint(node, "Property #{name} is prohibited")
else
add_lint(node, "Unknown property #{name}")
end
end
def known_property?(name)
KNOWN_PROPERTIES.include?(name) || @extra_properties.include?(name)
end
def contains_interpolation?(node)
node.name.count > 1 || !node.name.first.is_a?(String)
end
end
end