scss-lint 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,6 @@ module SCSSLint
|
|
6
6
|
|
7
7
|
DECLARATION_ORDER = [
|
8
8
|
Sass::Tree::ExtendNode,
|
9
|
-
Sass::Tree::MixinNode,
|
10
9
|
Sass::Tree::PropNode,
|
11
10
|
Sass::Tree::RuleNode,
|
12
11
|
]
|
@@ -14,17 +13,17 @@ module SCSSLint
|
|
14
13
|
class << self
|
15
14
|
def run(engine)
|
16
15
|
lints = []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
engine.tree.each do |node|
|
17
|
+
if node.is_a?(Sass::Tree::RuleNode)
|
18
|
+
lints << check_order_of_declarations(node)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
lints.compact
|
23
22
|
end
|
24
23
|
|
25
24
|
def description
|
26
25
|
'Rule sets should start with @extend declarations, followed by ' <<
|
27
|
-
'
|
26
|
+
'properties and nested rule sets, in that order'
|
28
27
|
end
|
29
28
|
|
30
29
|
private
|
@@ -37,18 +36,17 @@ module SCSSLint
|
|
37
36
|
end
|
38
37
|
|
39
38
|
def check_order_of_declarations(rule_node)
|
40
|
-
children = rule_node.children.select { |node| important_node?(node) }
|
39
|
+
children = rule_node.children.select { |node| important_node?(node) }.
|
40
|
+
map { |node| node.class }
|
41
41
|
|
42
|
-
#
|
42
|
+
# Inefficient, but we're not sorting thousands of declarations
|
43
43
|
sorted_children = children.sort do |x,y|
|
44
|
-
DECLARATION_ORDER.index(x
|
44
|
+
DECLARATION_ORDER.index(x) <=> DECLARATION_ORDER.index(y)
|
45
45
|
end
|
46
46
|
|
47
47
|
if children != sorted_children
|
48
|
-
return create_lint(children.first)
|
48
|
+
return create_lint(rule_node.children.first)
|
49
49
|
end
|
50
|
-
|
51
|
-
nil
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
@@ -17,13 +17,23 @@ module SCSSLint
|
|
17
17
|
|
18
18
|
def description
|
19
19
|
'Property declarations should always be on one line of the form ' <<
|
20
|
-
'`
|
20
|
+
'`name: value;` or `name: [value] {`'
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
VALUE_RE = %r{(\S+\s)*\S+} # eg. "10px", "10px normal"
|
26
|
+
PROPERTY_RE = %r{
|
27
|
+
^\s*[\w-]+:\s # property name, colon, one space
|
28
|
+
( # followed by
|
29
|
+
#{VALUE_RE}; # property and terminating semi-colon eg. a b c;
|
30
|
+
| # or
|
31
|
+
((#{VALUE_RE}\s)?\{) # nested property, optional value, trailing curly
|
32
|
+
)
|
33
|
+
}x
|
34
|
+
|
25
35
|
def check_property_format(prop_node, line)
|
26
|
-
return create_lint(prop_node) unless line =~
|
36
|
+
return create_lint(prop_node) unless line =~ PROPERTY_RE
|
27
37
|
end
|
28
38
|
end
|
29
39
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'sass'
|
2
|
+
|
3
|
+
module SCSSLint
|
4
|
+
class Linter::ShorthandLinter < Linter
|
5
|
+
include LinterRegistry
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def run(engine)
|
9
|
+
lints = []
|
10
|
+
engine.tree.each do |node|
|
11
|
+
if node.is_a?(Sass::Tree::PropNode)
|
12
|
+
lints << check_valid_shorthand_value(node)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
lints.compact
|
16
|
+
end
|
17
|
+
|
18
|
+
def description
|
19
|
+
'Property values should use the shortest shorthand syntax allowed'
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def check_valid_shorthand_value(prop_node)
|
25
|
+
if prop_node.value.is_a?(Sass::Script::String) &&
|
26
|
+
prop_node.value.to_s.strip =~ /\A(\S+\s+\S+\s+\S+(\s+\S+)?)\Z/
|
27
|
+
return create_lint(prop_node) unless valid_shorthand?($1)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid_shorthand?(shorthand)
|
32
|
+
values = shorthand.split(/\s+/)
|
33
|
+
|
34
|
+
if values[0] == values[1] &&
|
35
|
+
values[1] == values[2] &&
|
36
|
+
values[2] == values[3]
|
37
|
+
false
|
38
|
+
elsif values[0] == values[2] && values[1] == values[3]
|
39
|
+
false
|
40
|
+
elsif values[0] == values[2] && values[3].nil?
|
41
|
+
false
|
42
|
+
elsif values[1] == values[3]
|
43
|
+
false
|
44
|
+
else
|
45
|
+
true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/scss_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scss-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/scss_lint/linter/empty_rule_linter.rb
|
77
77
|
- lib/scss_lint/linter/debug_linter.rb
|
78
78
|
- lib/scss_lint/linter/sorted_properties_linter.rb
|
79
|
+
- lib/scss_lint/linter/shorthand_linter.rb
|
79
80
|
- lib/scss_lint/linter/property_format_linter.rb
|
80
81
|
- lib/scss_lint/linter/zero_unit_linter.rb
|
81
82
|
- lib/scss_lint/linter/hex_linter.rb
|