scss-lint 0.35.0 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +5 -0
- data/lib/scss_lint/cli.rb +24 -9
- data/lib/scss_lint/config.rb +4 -0
- data/lib/scss_lint/constants.rb +1 -1
- data/lib/scss_lint/exceptions.rb +11 -0
- data/lib/scss_lint/file_finder.rb +13 -2
- data/lib/scss_lint/linter/color_variable.rb +14 -1
- data/lib/scss_lint/linter/declaration_order.rb +16 -5
- data/lib/scss_lint/linter/property_units.rb +58 -0
- data/lib/scss_lint/linter/space_after_property_colon.rb +2 -0
- data/lib/scss_lint/runner.rb +0 -4
- data/lib/scss_lint/utils.rb +16 -0
- data/lib/scss_lint/version.rb +1 -1
- data/spec/scss_lint/cli_spec.rb +39 -0
- data/spec/scss_lint/file_finder_spec.rb +27 -3
- data/spec/scss_lint/linter/color_variable_spec.rb +23 -0
- data/spec/scss_lint/linter/declaration_order_spec.rb +19 -19
- data/spec/scss_lint/linter/property_units_spec.rb +199 -0
- data/spec/scss_lint/linter/space_after_property_colon_spec.rb +12 -0
- data/spec/scss_lint/runner_spec.rb +0 -8
- metadata +17 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f923a4288fb1d256d16d482a77e3c73a8aff84d
|
4
|
+
data.tar.gz: 2da5da450f72c3947f454bafe1c33d5244dfc304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 868fe445178e21cd235460029c6ab6ab914bc271a1e66c6fd462df517fd0deca3b08b2a974ddb3f362056da510d928f0e64c7aac33dbd6e932dc4752b2db042c
|
7
|
+
data.tar.gz: b7086af86736d1470bf627c7cd65cafeead516855e2431417eb1b6d4a4fd6283fff34157b59bea8eb19ccaddfe95c20722cce80565354fcda134859f911a51de
|
data/config/default.yml
CHANGED
@@ -98,6 +98,11 @@ linters:
|
|
98
98
|
include_nested: false
|
99
99
|
max_properties: 10
|
100
100
|
|
101
|
+
PropertyUnits:
|
102
|
+
enabled: true
|
103
|
+
global: ['em', 'ex', '%', 'px', 'ch', 'cm', 'mm', 'in', 'pt', 'pc', 'rem', 'vh', 'vw', 'vmin', 'vmax']
|
104
|
+
properties: {}
|
105
|
+
|
101
106
|
PropertySortOrder:
|
102
107
|
enabled: true
|
103
108
|
ignore_unspecified: false
|
data/lib/scss_lint/cli.rb
CHANGED
@@ -10,13 +10,16 @@ module SCSSLint
|
|
10
10
|
|
11
11
|
# Subset of semantic exit codes conforming to `sysexits` documentation.
|
12
12
|
EXIT_CODES = {
|
13
|
-
ok:
|
14
|
-
warning:
|
15
|
-
error:
|
16
|
-
usage:
|
17
|
-
no_input:
|
18
|
-
|
19
|
-
|
13
|
+
ok: 0,
|
14
|
+
warning: 1, # One or more warnings (but no errors) were reported
|
15
|
+
error: 2, # One or more errors were reported
|
16
|
+
usage: 64, # Command line usage error
|
17
|
+
no_input: 66, # Input file did not exist or was not readable
|
18
|
+
unavailable: 69, # Required library is unavailable
|
19
|
+
software: 70, # Internal software error
|
20
|
+
config: 78, # Configuration error
|
21
|
+
no_files: 80, # No files matched by specified glob patterns
|
22
|
+
files_filtered: 81, # All matched files were filtered by exclusions
|
20
23
|
}
|
21
24
|
|
22
25
|
def run(args)
|
@@ -60,7 +63,7 @@ module SCSSLint
|
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
63
|
-
def handle_runtime_exception(exception) # rubocop:disable Metrics/AbcSize
|
66
|
+
def handle_runtime_exception(exception) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/LineLength, Metrics/MethodLength
|
64
67
|
case exception
|
65
68
|
when SCSSLint::Exceptions::InvalidCLIOption
|
66
69
|
puts exception.message
|
@@ -69,7 +72,16 @@ module SCSSLint
|
|
69
72
|
when SCSSLint::Exceptions::InvalidConfiguration
|
70
73
|
puts exception.message
|
71
74
|
halt :config
|
72
|
-
when
|
75
|
+
when SCSSLint::Exceptions::RequiredLibraryMissingError
|
76
|
+
puts exception.message
|
77
|
+
halt :unavailable
|
78
|
+
when SCSSLint::Exceptions::AllFilesFilteredError
|
79
|
+
puts exception.message
|
80
|
+
halt :files_filtered
|
81
|
+
when SCSSLint::Exceptions::NoFilesError
|
82
|
+
puts exception.message
|
83
|
+
halt :no_files
|
84
|
+
when Errno::ENOENT
|
73
85
|
puts exception.message
|
74
86
|
halt :no_input
|
75
87
|
when NoSuchLinter
|
@@ -137,6 +149,9 @@ module SCSSLint
|
|
137
149
|
Array(options[:required_paths]).each do |path|
|
138
150
|
require path
|
139
151
|
end
|
152
|
+
rescue LoadError => ex
|
153
|
+
raise SCSSLint::Exceptions::RequiredLibraryMissingError,
|
154
|
+
"Required library not found: #{ex.message}"
|
140
155
|
end
|
141
156
|
|
142
157
|
def load_reporters(options)
|
data/lib/scss_lint/config.rb
CHANGED
data/lib/scss_lint/constants.rb
CHANGED
@@ -3,6 +3,6 @@ module SCSSLint
|
|
3
3
|
SCSS_LINT_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
4
4
|
SCSS_LINT_DATA = File.join(SCSS_LINT_HOME, 'data')
|
5
5
|
|
6
|
-
REPO_URL = 'https://github.com/
|
6
|
+
REPO_URL = 'https://github.com/brigade/scss-lint'
|
7
7
|
BUG_REPORT_URL = "#{REPO_URL}/issues"
|
8
8
|
end
|
data/lib/scss_lint/exceptions.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
module SCSSLint::Exceptions
|
2
|
+
# Raised when all files matched by the specified glob patterns were filtered
|
3
|
+
# by exclude patterns.
|
4
|
+
class AllFilesFilteredError < StandardError; end
|
5
|
+
|
2
6
|
# Raised when an invalid flag is given via the command line.
|
3
7
|
class InvalidCLIOption < StandardError; end
|
4
8
|
|
@@ -7,4 +11,11 @@ module SCSSLint::Exceptions
|
|
7
11
|
|
8
12
|
# Raised when an unexpected error occurs in a linter
|
9
13
|
class LinterError < StandardError; end
|
14
|
+
|
15
|
+
# Raised when no files were specified or specified glob patterns did not match
|
16
|
+
# any files.
|
17
|
+
class NoFilesError < StandardError; end
|
18
|
+
|
19
|
+
# Raised when a required library (specified via command line) does not exist.
|
20
|
+
class RequiredLibraryMissingError < StandardError; end
|
10
21
|
end
|
@@ -22,9 +22,20 @@ module SCSSLint
|
|
22
22
|
# If no explicit patterns given, use patterns listed in config
|
23
23
|
patterns = @config.scss_files if patterns.empty?
|
24
24
|
|
25
|
-
extract_files_from(patterns)
|
26
|
-
|
25
|
+
matched_files = extract_files_from(patterns)
|
26
|
+
if matched_files.empty?
|
27
|
+
raise SCSSLint::Exceptions::NoFilesError,
|
28
|
+
"No SCSS files matched by the patterns: #{patterns.join(' ')}"
|
27
29
|
end
|
30
|
+
|
31
|
+
filtered_files = matched_files.reject { |file| @config.excluded_file?(file) }
|
32
|
+
if filtered_files.empty?
|
33
|
+
raise SCSSLint::Exceptions::AllFilesFilteredError,
|
34
|
+
"All files matched by the patterns [#{patterns.join(', ')}] " \
|
35
|
+
"were excluded by the patterns: [#{@config.exclude_patterns.join(', ')}]"
|
36
|
+
end
|
37
|
+
|
38
|
+
filtered_files
|
28
39
|
end
|
29
40
|
|
30
41
|
private
|
@@ -4,7 +4,9 @@ module SCSSLint
|
|
4
4
|
include LinterRegistry
|
5
5
|
|
6
6
|
def visit_script_color(node)
|
7
|
-
return if in_variable_declaration?(node)
|
7
|
+
return if in_variable_declaration?(node) ||
|
8
|
+
in_map_declaration?(node) ||
|
9
|
+
in_rgba_function_call?(node)
|
8
10
|
|
9
11
|
# Source range sometimes includes closing parenthesis, so extract it
|
10
12
|
color = source_from_range(node.source_range)[/(#?[a-z0-9]+)/i, 1]
|
@@ -32,5 +34,16 @@ module SCSSLint
|
|
32
34
|
parent.is_a?(Sass::Script::Tree::Literal) &&
|
33
35
|
parent.node_parent.is_a?(Sass::Tree::VariableNode)
|
34
36
|
end
|
37
|
+
|
38
|
+
def in_rgba_function_call?(node)
|
39
|
+
grandparent = node_ancestor(node, 2)
|
40
|
+
|
41
|
+
grandparent.is_a?(Sass::Script::Tree::Funcall) &&
|
42
|
+
grandparent.name == 'rgba'
|
43
|
+
end
|
44
|
+
|
45
|
+
def in_map_declaration?(node)
|
46
|
+
node_ancestor(node, 2).is_a?(Sass::Script::Tree::MapLiteral)
|
47
|
+
end
|
35
48
|
end
|
36
49
|
end
|
@@ -35,14 +35,25 @@ module SCSSLint
|
|
35
35
|
|
36
36
|
def check_node(node)
|
37
37
|
children = node.children.select { |n| important_node?(n) }
|
38
|
-
.map { |n| node_declaration_type(n) }
|
38
|
+
.map { |n| [n, node_declaration_type(n)] }
|
39
39
|
|
40
|
-
sorted_children = children.sort do |
|
41
|
-
DECLARATION_ORDER.index(
|
40
|
+
sorted_children = children.sort do |(_, a_type), (_, b_type)|
|
41
|
+
DECLARATION_ORDER.index(a_type) <=> DECLARATION_ORDER.index(b_type)
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
check_children_order(sorted_children, children)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Find the child that is out of place
|
48
|
+
def check_children_order(sorted_children, children)
|
49
|
+
sorted_children.each_with_index do |sorted_item, index|
|
50
|
+
next if sorted_item == children[index]
|
51
|
+
|
52
|
+
add_lint(sorted_item.first.line,
|
53
|
+
"Expected item on line #{sorted_item.first.line} to appear " \
|
54
|
+
"before line #{children[index].first.line}. #{MESSAGE}")
|
55
|
+
break
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
def node_declaration_type(node)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module SCSSLint
|
2
|
+
# Check for allowed units
|
3
|
+
class Linter::PropertyUnits < Linter
|
4
|
+
include LinterRegistry
|
5
|
+
|
6
|
+
def visit_root(_node)
|
7
|
+
@globally_allowed_units = config['global'].to_set
|
8
|
+
@allowed_units_for_property = config['properties']
|
9
|
+
|
10
|
+
yield # Continue linting children
|
11
|
+
end
|
12
|
+
|
13
|
+
def visit_prop(node)
|
14
|
+
property = node.name.join
|
15
|
+
|
16
|
+
# Handle nested properties by ensuring the full name is extracted
|
17
|
+
if @nested_under
|
18
|
+
property = "#{@nested_under}-#{property}"
|
19
|
+
end
|
20
|
+
|
21
|
+
if units = node.value.value.to_s[/(?:\d+|\d*\.?\d+)([a-z%]+)/i, 1]
|
22
|
+
check_units(node, property, units)
|
23
|
+
end
|
24
|
+
|
25
|
+
@nested_under = property
|
26
|
+
yield # Continue linting nested properties
|
27
|
+
@nested_under = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Checks if a property value's units are allowed.
|
33
|
+
#
|
34
|
+
# @param node [Sass::Tree::Node]
|
35
|
+
# @param property [String]
|
36
|
+
# @param units [String]
|
37
|
+
def check_units(node, property, units)
|
38
|
+
allowed_units = allowed_units_for_property(property)
|
39
|
+
return if allowed_units.include?(units)
|
40
|
+
|
41
|
+
add_lint(node,
|
42
|
+
"#{units} units not allowed on `#{property}`; must be one of " \
|
43
|
+
"(#{allowed_units.to_a.sort.join(', ')})")
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the list of allowed units for a property.
|
47
|
+
#
|
48
|
+
# @param property [String]
|
49
|
+
# @return Array<String>
|
50
|
+
def allowed_units_for_property(property)
|
51
|
+
if @allowed_units_for_property.key?(property)
|
52
|
+
@allowed_units_for_property[property]
|
53
|
+
else
|
54
|
+
@globally_allowed_units
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/scss_lint/runner.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
module SCSSLint
|
2
|
-
class NoFilesError < StandardError; end
|
3
|
-
|
4
2
|
# Finds and aggregates all lints found by running the registered linters
|
5
3
|
# against a set of SCSS files.
|
6
4
|
class Runner
|
@@ -15,8 +13,6 @@ module SCSSLint
|
|
15
13
|
|
16
14
|
# @param files [Array]
|
17
15
|
def run(files)
|
18
|
-
raise NoFilesError, 'No SCSS files specified' if files.empty?
|
19
|
-
|
20
16
|
files.each do |file|
|
21
17
|
find_lints(file)
|
22
18
|
end
|
data/lib/scss_lint/utils.rb
CHANGED
@@ -82,6 +82,22 @@ module SCSSLint
|
|
82
82
|
.select { |child| child.is_a?(Sass::Tree::Node) }
|
83
83
|
end
|
84
84
|
|
85
|
+
# Return nth-ancestor of a node, where 1 is the parent, 2 is grandparent,
|
86
|
+
# etc.
|
87
|
+
#
|
88
|
+
# @param node [Sass::Tree::Node, Sass::Script::Tree::Node]
|
89
|
+
# @param level [Integer]
|
90
|
+
# @return [Sass::Tree::Node, Sass::Script::Tree::Node, nil]
|
91
|
+
def node_ancestor(node, levels)
|
92
|
+
while levels > 0
|
93
|
+
node = node.node_parent
|
94
|
+
return unless node
|
95
|
+
levels -= 1
|
96
|
+
end
|
97
|
+
|
98
|
+
node
|
99
|
+
end
|
100
|
+
|
85
101
|
def pluralize(value, word)
|
86
102
|
value == 1 ? "#{value} #{word}" : "#{value} #{word}s"
|
87
103
|
end
|
data/lib/scss_lint/version.rb
CHANGED
data/spec/scss_lint/cli_spec.rb
CHANGED
@@ -134,5 +134,44 @@ describe SCSSLint::CLI do
|
|
134
134
|
@output.should include SCSSLint::BUG_REPORT_URL
|
135
135
|
end
|
136
136
|
end
|
137
|
+
|
138
|
+
context 'when a required library is not found' do
|
139
|
+
let(:flags) { ['--require', 'some_non_existent_library'] }
|
140
|
+
|
141
|
+
before do
|
142
|
+
Kernel.stub(:require).with('some_non_existent_library').and_raise(
|
143
|
+
SCSSLint::Exceptions::RequiredLibraryMissingError
|
144
|
+
)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'exits with an appropriate status code' do
|
148
|
+
subject.should_receive(:halt).with(:unavailable)
|
149
|
+
safe_run
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when specified SCSS file globs match no files' do
|
154
|
+
before do
|
155
|
+
SCSSLint::FileFinder.any_instance.stub(:find)
|
156
|
+
.and_raise(SCSSLint::Exceptions::NoFilesError)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'exits with an appropriate status code' do
|
160
|
+
subject.should_receive(:halt).with(:no_files)
|
161
|
+
safe_run
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when all specified SCSS files are filtered by exclusions' do
|
166
|
+
before do
|
167
|
+
SCSSLint::FileFinder.any_instance.stub(:find)
|
168
|
+
.and_raise(SCSSLint::Exceptions::AllFilesFilteredError)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'exits with an appropriate status code' do
|
172
|
+
subject.should_receive(:halt).with(:files_filtered)
|
173
|
+
safe_run
|
174
|
+
end
|
175
|
+
end
|
137
176
|
end
|
138
177
|
end
|
@@ -14,7 +14,9 @@ describe SCSSLint::FileFinder do
|
|
14
14
|
let(:patterns) { [] }
|
15
15
|
|
16
16
|
context 'and there are no SCSS files under the current directory' do
|
17
|
-
it
|
17
|
+
it 'raises an error' do
|
18
|
+
expect { subject }.to raise_error SCSSLint::Exceptions::NoFilesError
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
context 'and there are SCSS files under the current directory' do
|
@@ -68,6 +70,16 @@ describe SCSSLint::FileFinder do
|
|
68
70
|
end
|
69
71
|
|
70
72
|
it { should == ['some-dir/test.scss'] }
|
73
|
+
|
74
|
+
context 'and those SCSS files are excluded by the config' do
|
75
|
+
before do
|
76
|
+
config.exclude_file('some-dir/test.scss')
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'raises an error' do
|
80
|
+
expect { subject }.to raise_error SCSSLint::Exceptions::AllFilesFilteredError
|
81
|
+
end
|
82
|
+
end
|
71
83
|
end
|
72
84
|
|
73
85
|
context 'and they contain CSS files' do
|
@@ -85,14 +97,26 @@ describe SCSSLint::FileFinder do
|
|
85
97
|
end
|
86
98
|
|
87
99
|
it { should == ['some-dir/more-dir/test.scss'] }
|
100
|
+
|
101
|
+
context 'and those SCSS files are excluded by the config' do
|
102
|
+
before do
|
103
|
+
config.exclude_file('**/*.scss')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'raises an error' do
|
107
|
+
expect { subject }.to raise_error SCSSLint::Exceptions::AllFilesFilteredError
|
108
|
+
end
|
109
|
+
end
|
88
110
|
end
|
89
111
|
|
90
|
-
context 'and they contain
|
112
|
+
context 'and they contain no SCSS files' do
|
91
113
|
before do
|
92
114
|
`touch some-dir/test.txt`
|
93
115
|
end
|
94
116
|
|
95
|
-
it
|
117
|
+
it 'raises an error' do
|
118
|
+
expect { subject }.to raise_error SCSSLint::Exceptions::NoFilesError
|
119
|
+
end
|
96
120
|
end
|
97
121
|
end
|
98
122
|
|
@@ -119,4 +119,27 @@ describe SCSSLint::Linter::ColorVariable do
|
|
119
119
|
|
120
120
|
it { should_not report_lint }
|
121
121
|
end
|
122
|
+
|
123
|
+
context 'when a color literal is used in the special rgba shorthand helper' do
|
124
|
+
let(:scss) { <<-SCSS }
|
125
|
+
p {
|
126
|
+
color: rgba(#fff, .5);
|
127
|
+
}
|
128
|
+
SCSS
|
129
|
+
|
130
|
+
it { should_not report_lint }
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when a color literal is used in a map declaration' do
|
134
|
+
let(:scss) { <<-SCSS }
|
135
|
+
$shades-of-gray: (
|
136
|
+
darker: #4c4c4c,
|
137
|
+
dark: #626262,
|
138
|
+
light: #7d7d7d,
|
139
|
+
lighter: #979797
|
140
|
+
);
|
141
|
+
SCSS
|
142
|
+
|
143
|
+
it { should_not report_lint }
|
144
|
+
end
|
122
145
|
end
|
@@ -89,7 +89,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
89
89
|
}
|
90
90
|
SCSS
|
91
91
|
|
92
|
-
it { should report_lint }
|
92
|
+
it { should report_lint line: 6 }
|
93
93
|
end
|
94
94
|
|
95
95
|
context 'when nested rule set' do
|
@@ -116,7 +116,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
116
116
|
}
|
117
117
|
SCSS
|
118
118
|
|
119
|
-
it { should report_lint }
|
119
|
+
it { should report_lint line: 4 }
|
120
120
|
end
|
121
121
|
|
122
122
|
context 'contains @extend after nested rule set' do
|
@@ -131,7 +131,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
131
131
|
}
|
132
132
|
SCSS
|
133
133
|
|
134
|
-
it { should report_lint }
|
134
|
+
it { should report_lint line: 6 }
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
@@ -161,7 +161,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
161
161
|
}
|
162
162
|
SCSS
|
163
163
|
|
164
|
-
it { should report_lint }
|
164
|
+
it { should report_lint line: 3 }
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -176,7 +176,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
176
176
|
}
|
177
177
|
SCSS
|
178
178
|
|
179
|
-
it { should report_lint }
|
179
|
+
it { should report_lint line: 5 }
|
180
180
|
end
|
181
181
|
|
182
182
|
context 'after a property' do
|
@@ -202,7 +202,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
202
202
|
}
|
203
203
|
SCSS
|
204
204
|
|
205
|
-
it { should report_lint }
|
205
|
+
it { should report_lint line: 5 }
|
206
206
|
end
|
207
207
|
|
208
208
|
context 'before a rule set' do
|
@@ -232,7 +232,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
232
232
|
}
|
233
233
|
SCSS
|
234
234
|
|
235
|
-
it { should report_lint }
|
235
|
+
it { should report_lint line: 5 }
|
236
236
|
end
|
237
237
|
|
238
238
|
context 'with its own nested rule set' do
|
@@ -246,7 +246,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
246
246
|
}
|
247
247
|
SCSS
|
248
248
|
|
249
|
-
it { should report_lint }
|
249
|
+
it { should report_lint line: 5 }
|
250
250
|
end
|
251
251
|
|
252
252
|
context 'after a property' do
|
@@ -303,7 +303,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
303
303
|
}
|
304
304
|
SCSS
|
305
305
|
|
306
|
-
it { should report_lint }
|
306
|
+
it { should report_lint line: 7 }
|
307
307
|
end
|
308
308
|
end
|
309
309
|
|
@@ -331,7 +331,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
331
331
|
}
|
332
332
|
SCSS
|
333
333
|
|
334
|
-
it { should report_lint }
|
334
|
+
it { should report_lint line: 4 }
|
335
335
|
end
|
336
336
|
|
337
337
|
context 'contains @extend after nested rule set' do
|
@@ -346,7 +346,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
346
346
|
}
|
347
347
|
SCSS
|
348
348
|
|
349
|
-
it { should report_lint }
|
349
|
+
it { should report_lint line: 6 }
|
350
350
|
end
|
351
351
|
end
|
352
352
|
|
@@ -360,7 +360,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
360
360
|
}
|
361
361
|
SCSS
|
362
362
|
|
363
|
-
it { should report_lint }
|
363
|
+
it { should report_lint line: 5 }
|
364
364
|
end
|
365
365
|
|
366
366
|
context 'when a pseudo-element appears after a property' do
|
@@ -399,7 +399,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
399
399
|
}
|
400
400
|
SCSS
|
401
401
|
|
402
|
-
it { should report_lint }
|
402
|
+
it { should report_lint line: 5 }
|
403
403
|
end
|
404
404
|
|
405
405
|
context 'when a selector with parent reference appears after a property' do
|
@@ -425,7 +425,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
425
425
|
}
|
426
426
|
SCSS
|
427
427
|
|
428
|
-
it { should report_lint }
|
428
|
+
it { should report_lint line: 5 }
|
429
429
|
end
|
430
430
|
|
431
431
|
context 'when a pseudo-element appears after a property' do
|
@@ -451,7 +451,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
451
451
|
}
|
452
452
|
SCSS
|
453
453
|
|
454
|
-
it { should report_lint }
|
454
|
+
it { should report_lint line: 5 }
|
455
455
|
end
|
456
456
|
|
457
457
|
context 'when a direct descendent appears after a property' do
|
@@ -477,7 +477,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
477
477
|
}
|
478
478
|
SCSS
|
479
479
|
|
480
|
-
it { should report_lint }
|
480
|
+
it { should report_lint line: 5 }
|
481
481
|
end
|
482
482
|
|
483
483
|
context 'when an adjacent sibling appears after a property' do
|
@@ -503,7 +503,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
503
503
|
}
|
504
504
|
SCSS
|
505
505
|
|
506
|
-
it { should report_lint }
|
506
|
+
it { should report_lint line: 5 }
|
507
507
|
end
|
508
508
|
|
509
509
|
context 'when a general sibling appears after a property' do
|
@@ -529,7 +529,7 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
529
529
|
}
|
530
530
|
SCSS
|
531
531
|
|
532
|
-
it { should report_lint }
|
532
|
+
it { should report_lint line: 5 }
|
533
533
|
end
|
534
534
|
|
535
535
|
context 'when a descendent appears after a property' do
|
@@ -555,6 +555,6 @@ describe SCSSLint::Linter::DeclarationOrder do
|
|
555
555
|
}
|
556
556
|
SCSS
|
557
557
|
|
558
|
-
it { should report_lint }
|
558
|
+
it { should report_lint line: 5 }
|
559
559
|
end
|
560
560
|
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SCSSLint::Linter::PropertyUnits do
|
4
|
+
context 'when global units are set and local are not set' do
|
5
|
+
let(:linter_config) { { 'global' => ['rem'], 'properties' => {} } }
|
6
|
+
|
7
|
+
context 'when unit is allowed' do
|
8
|
+
let(:scss) { <<-SCSS }
|
9
|
+
p {
|
10
|
+
font-size: 1.54rem;
|
11
|
+
margin: 1rem;
|
12
|
+
padding: .1rem;
|
13
|
+
}
|
14
|
+
SCSS
|
15
|
+
|
16
|
+
it { should_not report_lint }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when unit is not allowed' do
|
20
|
+
let(:scss) { <<-SCSS }
|
21
|
+
p {
|
22
|
+
font-size: 16.54px;
|
23
|
+
margin: 1px;
|
24
|
+
padding: .1px;
|
25
|
+
}
|
26
|
+
SCSS
|
27
|
+
|
28
|
+
it { should report_lint line: 2 }
|
29
|
+
it { should report_lint line: 3 }
|
30
|
+
it { should report_lint line: 4 }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when using a shorthand property' do
|
34
|
+
context 'and the unit is allowed' do
|
35
|
+
let(:scss) { <<-SCSS }
|
36
|
+
p {
|
37
|
+
font: italic 1rem Serif;
|
38
|
+
}
|
39
|
+
SCSS
|
40
|
+
|
41
|
+
it { should_not report_lint }
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'and the unit is not allowed' do
|
45
|
+
let(:scss) { <<-SCSS }
|
46
|
+
p {
|
47
|
+
font: italic 16px Serif;
|
48
|
+
}
|
49
|
+
SCSS
|
50
|
+
|
51
|
+
it { should report_lint line: 2 }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when global and local units are set' do
|
57
|
+
let(:linter_config) { { 'global' => ['rem'], 'properties' => { 'font-size' => ['px'] } } }
|
58
|
+
|
59
|
+
context 'when unit is allowed locally not globally' do
|
60
|
+
let(:scss) { <<-SCSS }
|
61
|
+
p {
|
62
|
+
font-size: 16px;
|
63
|
+
}
|
64
|
+
SCSS
|
65
|
+
|
66
|
+
it { should_not report_lint }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when unit is allowed globally not locally' do
|
70
|
+
let(:scss) { <<-SCSS }
|
71
|
+
p {
|
72
|
+
margin: 1rem;
|
73
|
+
}
|
74
|
+
SCSS
|
75
|
+
|
76
|
+
it { should_not report_lint }
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when unit is not allowed globally nor locally' do
|
80
|
+
let(:scss) { <<-SCSS }
|
81
|
+
p {
|
82
|
+
margin: 1vh;
|
83
|
+
}
|
84
|
+
SCSS
|
85
|
+
|
86
|
+
it { should report_lint line: 2 }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when local units are set and global are not set' do
|
91
|
+
let(:linter_config) { { 'global' => [], 'properties' => { 'margin' => ['rem'] } } }
|
92
|
+
|
93
|
+
context 'when unit is allowed locally not globally' do
|
94
|
+
let(:scss) { <<-SCSS }
|
95
|
+
p {
|
96
|
+
margin: 1rem;
|
97
|
+
}
|
98
|
+
SCSS
|
99
|
+
|
100
|
+
it { should_not report_lint }
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when unit is not allowed locally nor globally' do
|
104
|
+
let(:scss) { <<-SCSS }
|
105
|
+
p {
|
106
|
+
margin: 10px;
|
107
|
+
}
|
108
|
+
SCSS
|
109
|
+
|
110
|
+
it { should report_lint line: 2 }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'when multiple units are set on a property' do
|
115
|
+
let(:linter_config) { { 'global' => [], 'properties' => { 'margin' => %w[rem em] } } }
|
116
|
+
|
117
|
+
context 'when one of multiple units is used' do
|
118
|
+
let(:scss) { <<-SCSS }
|
119
|
+
p {
|
120
|
+
margin: 1rem;
|
121
|
+
}
|
122
|
+
SCSS
|
123
|
+
|
124
|
+
it { should_not report_lint }
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when another of multiple units is used' do
|
128
|
+
let(:scss) { <<-SCSS }
|
129
|
+
p {
|
130
|
+
margin: 1em;
|
131
|
+
}
|
132
|
+
SCSS
|
133
|
+
|
134
|
+
it { should_not report_lint }
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when a not allowed unit is used' do
|
138
|
+
let(:scss) { <<-SCSS }
|
139
|
+
p {
|
140
|
+
margin: 10px;
|
141
|
+
}
|
142
|
+
SCSS
|
143
|
+
|
144
|
+
it { should report_lint line: 2 }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when no local units are allowed' do
|
149
|
+
let(:linter_config) { { 'global' => ['px'], 'properties' => { 'line-height' => [] } } }
|
150
|
+
|
151
|
+
context 'when a disallowed unit is used' do
|
152
|
+
let(:scss) { <<-SCSS }
|
153
|
+
p {
|
154
|
+
line-height: 10px;
|
155
|
+
}
|
156
|
+
SCSS
|
157
|
+
|
158
|
+
it { should report_lint line: 2 }
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'when no unit is used' do
|
162
|
+
let(:scss) { <<-SCSS }
|
163
|
+
p {
|
164
|
+
line-height: 1;
|
165
|
+
}
|
166
|
+
SCSS
|
167
|
+
|
168
|
+
it { should_not report_lint }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when nested properties are used' do
|
173
|
+
let(:linter_config) { { 'global' => ['rem'], 'properties' => { 'font-size' => ['em'] } } }
|
174
|
+
|
175
|
+
context 'and an allowed unit is used' do
|
176
|
+
let(:scss) { <<-SCSS }
|
177
|
+
p {
|
178
|
+
font: {
|
179
|
+
size: 1em;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
SCSS
|
183
|
+
|
184
|
+
it { should_not report_lint }
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'and a disallowed unit is used' do
|
188
|
+
let(:scss) { <<-SCSS }
|
189
|
+
p {
|
190
|
+
font: {
|
191
|
+
size: 16px;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
SCSS
|
195
|
+
|
196
|
+
it { should report_lint line: 3 }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
@@ -69,6 +69,18 @@ describe SCSSLint::Linter::SpaceAfterPropertyColon do
|
|
69
69
|
it { should report_lint }
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
context 'when there are nested properties with incorrect spacing' do
|
74
|
+
let(:scss) { <<-SCSS }
|
75
|
+
.class {
|
76
|
+
font: {
|
77
|
+
weight :bold;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
SCSS
|
81
|
+
|
82
|
+
it { should report_lint line: 3 }
|
83
|
+
end
|
72
84
|
end
|
73
85
|
|
74
86
|
context 'when no spaces are allowed' do
|
@@ -36,14 +36,6 @@ describe SCSSLint::Runner do
|
|
36
36
|
subject
|
37
37
|
end
|
38
38
|
|
39
|
-
context 'when no files are given' do
|
40
|
-
let(:files) { [] }
|
41
|
-
|
42
|
-
it 'raises an error' do
|
43
|
-
expect { subject }.to raise_error SCSSLint::NoFilesError
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
39
|
context 'when all linters are disabled' do
|
48
40
|
let(:config_options) do
|
49
41
|
{
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scss-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Brigade Engineering
|
8
8
|
- Shane da Silva
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rainbow
|
@@ -69,8 +69,8 @@ dependencies:
|
|
69
69
|
version: '3.0'
|
70
70
|
description: Configurable tool for writing clean and consistent SCSS
|
71
71
|
email:
|
72
|
-
- eng@
|
73
|
-
- shane@
|
72
|
+
- eng@brigade.com
|
73
|
+
- shane.dasilva@brigade.com
|
74
74
|
executables:
|
75
75
|
- scss-lint
|
76
76
|
extensions: []
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/scss_lint/linter/property_count.rb
|
124
124
|
- lib/scss_lint/linter/property_sort_order.rb
|
125
125
|
- lib/scss_lint/linter/property_spelling.rb
|
126
|
+
- lib/scss_lint/linter/property_units.rb
|
126
127
|
- lib/scss_lint/linter/qualifying_element.rb
|
127
128
|
- lib/scss_lint/linter/selector_depth.rb
|
128
129
|
- lib/scss_lint/linter/selector_format.rb
|
@@ -192,6 +193,7 @@ files:
|
|
192
193
|
- spec/scss_lint/linter/property_count_spec.rb
|
193
194
|
- spec/scss_lint/linter/property_sort_order_spec.rb
|
194
195
|
- spec/scss_lint/linter/property_spelling_spec.rb
|
196
|
+
- spec/scss_lint/linter/property_units_spec.rb
|
195
197
|
- spec/scss_lint/linter/qualifying_element_spec.rb
|
196
198
|
- spec/scss_lint/linter/selector_depth_spec.rb
|
197
199
|
- spec/scss_lint/linter/selector_format_spec.rb
|
@@ -229,7 +231,7 @@ files:
|
|
229
231
|
- spec/spec_helper.rb
|
230
232
|
- spec/support/isolated_environment.rb
|
231
233
|
- spec/support/matchers/report_lint.rb
|
232
|
-
homepage: https://github.com/
|
234
|
+
homepage: https://github.com/brigade/scss-lint
|
233
235
|
licenses:
|
234
236
|
- MIT
|
235
237
|
metadata: {}
|
@@ -255,15 +257,13 @@ specification_version: 4
|
|
255
257
|
summary: SCSS lint tool
|
256
258
|
test_files:
|
257
259
|
- spec/scss_lint/config_spec.rb
|
258
|
-
- spec/scss_lint/
|
260
|
+
- spec/scss_lint/engine_spec.rb
|
259
261
|
- spec/scss_lint/linter/bang_format_spec.rb
|
260
262
|
- spec/scss_lint/linter/border_zero_spec.rb
|
261
263
|
- spec/scss_lint/linter/color_keyword_spec.rb
|
262
|
-
- spec/scss_lint/linter/color_variable_spec.rb
|
263
264
|
- spec/scss_lint/linter/comment_spec.rb
|
264
265
|
- spec/scss_lint/linter/compass/property_with_mixin_spec.rb
|
265
266
|
- spec/scss_lint/linter/debug_statement_spec.rb
|
266
|
-
- spec/scss_lint/linter/declaration_order_spec.rb
|
267
267
|
- spec/scss_lint/linter/duplicate_property_spec.rb
|
268
268
|
- spec/scss_lint/linter/else_placement_spec.rb
|
269
269
|
- spec/scss_lint/linter/empty_line_between_blocks_spec.rb
|
@@ -275,6 +275,7 @@ test_files:
|
|
275
275
|
- spec/scss_lint/linter/id_selector_spec.rb
|
276
276
|
- spec/scss_lint/linter/import_path_spec.rb
|
277
277
|
- spec/scss_lint/linter/important_rule_spec.rb
|
278
|
+
- spec/scss_lint/linter/indentation_spec.rb
|
278
279
|
- spec/scss_lint/linter/leading_zero_spec.rb
|
279
280
|
- spec/scss_lint/linter/mergeable_selector_spec.rb
|
280
281
|
- spec/scss_lint/linter/name_format_spec.rb
|
@@ -304,7 +305,9 @@ test_files:
|
|
304
305
|
- spec/scss_lint/linter/variable_for_property_spec.rb
|
305
306
|
- spec/scss_lint/linter/vendor_prefix_spec.rb
|
306
307
|
- spec/scss_lint/linter/zero_unit_spec.rb
|
307
|
-
- spec/scss_lint/linter/
|
308
|
+
- spec/scss_lint/linter/color_variable_spec.rb
|
309
|
+
- spec/scss_lint/linter/property_units_spec.rb
|
310
|
+
- spec/scss_lint/linter/declaration_order_spec.rb
|
308
311
|
- spec/scss_lint/linter_registry_spec.rb
|
309
312
|
- spec/scss_lint/linter_spec.rb
|
310
313
|
- spec/scss_lint/location_spec.rb
|
@@ -316,10 +319,10 @@ test_files:
|
|
316
319
|
- spec/scss_lint/reporter/json_reporter_spec.rb
|
317
320
|
- spec/scss_lint/reporter/xml_reporter_spec.rb
|
318
321
|
- spec/scss_lint/reporter_spec.rb
|
319
|
-
- spec/scss_lint/cli_spec.rb
|
320
|
-
- spec/scss_lint/engine_spec.rb
|
321
|
-
- spec/scss_lint/runner_spec.rb
|
322
322
|
- spec/scss_lint/selector_visitor_spec.rb
|
323
|
+
- spec/scss_lint/file_finder_spec.rb
|
324
|
+
- spec/scss_lint/runner_spec.rb
|
325
|
+
- spec/scss_lint/cli_spec.rb
|
326
|
+
- spec/spec_helper.rb
|
323
327
|
- spec/support/isolated_environment.rb
|
324
328
|
- spec/support/matchers/report_lint.rb
|
325
|
-
- spec/spec_helper.rb
|