scss_lint 0.47.1 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/scss_lint/linter/disable_linter_reason.rb +33 -9
- data/lib/scss_lint/linter/name_format.rb +1 -0
- data/lib/scss_lint/reporter/stats_reporter.rb +39 -0
- data/lib/scss_lint/version.rb +1 -1
- data/spec/scss_lint/linter/disable_linter_reason_spec.rb +11 -0
- data/spec/scss_lint/linter/name_format_spec.rb +10 -0
- data/spec/scss_lint/reporter/stats_reporter_spec.rb +115 -0
- metadata +7 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 836d64855e532ba7edb008a354400fdb3a752b40
|
4
|
+
data.tar.gz: 9712c133bc9cf2ff5b9bc5081fc27ab2a258263b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8da6137c2915033192ede52347dd8ed2384a134afb192f8f053957da5d6043ea24b100d93f8acf6391bbef92e88d36aa6d97e258413056996b4aef0538de090e
|
7
|
+
data.tar.gz: e043ed88d75c13b5343f18c2cab961853016bfce1533a721ed8cc7f323fe2bd37d24d50cb90ba5b76931f4fb94a3be67f9b009183c28d8967e9a5b6e27663846
|
@@ -7,19 +7,37 @@ module SCSSLint
|
|
7
7
|
# No lint if the first line of the comment is not a command (because then
|
8
8
|
# either this comment has no commands, or the first line serves as a the
|
9
9
|
# reason for a command on a later line).
|
10
|
-
|
10
|
+
if comment_lines(node).first.match(COMMAND_REGEX)
|
11
|
+
visit_command_comment(node)
|
12
|
+
else
|
13
|
+
@previous_comment = node
|
14
|
+
end
|
15
|
+
end
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
def visit_command_comment(node)
|
18
|
+
if @previous_comment.nil?
|
19
|
+
report_lint(node)
|
20
|
+
return
|
21
|
+
end
|
14
22
|
|
15
|
-
if
|
16
|
-
|
17
|
-
|
23
|
+
# Not a "disable linter reason" if the last line of the previous comment is a command.
|
24
|
+
if comment_lines(@previous_comment).last.match(COMMAND_REGEX)
|
25
|
+
report_lint(node)
|
26
|
+
return
|
18
27
|
end
|
19
28
|
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
# No lint if the last line of the previous comment is on the previous line.
|
30
|
+
if @previous_comment.source_range.end_pos.line == node.source_range.end_pos.line - 1
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
# The "reason" comment doesn't have to be on the previous line, as long as it is exactly
|
35
|
+
# the previous node.
|
36
|
+
if previous_node(node) == @previous_comment
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
report_lint(node)
|
23
41
|
end
|
24
42
|
|
25
43
|
private
|
@@ -35,5 +53,11 @@ module SCSSLint
|
|
35
53
|
def comment_lines(node)
|
36
54
|
node.value.join.split("\n")
|
37
55
|
end
|
56
|
+
|
57
|
+
def report_lint(node)
|
58
|
+
add_lint(node,
|
59
|
+
'scss-lint:disable control comments should be preceded by a ' \
|
60
|
+
'comment explaining why the linters need to be disabled.')
|
61
|
+
end
|
38
62
|
end
|
39
63
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SCSSLint
|
2
|
+
# Reports a single line per lint.
|
3
|
+
class Reporter::StatsReporter < Reporter
|
4
|
+
def report_lints # rubocop:disable Metrics/AbcSize
|
5
|
+
return unless lints.any?
|
6
|
+
|
7
|
+
stats = organize_stats
|
8
|
+
total_lints = lints.length
|
9
|
+
linter_name_length =
|
10
|
+
stats.inject('') { |memo, stat| memo.length > stat[0].length ? memo : stat[0] }.length
|
11
|
+
total_files = lints.group_by(&:filename).size
|
12
|
+
|
13
|
+
# Math.log10(1) is 0; avoid this by using at least 1.
|
14
|
+
lint_count_length = [1, Math.log10(total_lints).ceil].max
|
15
|
+
file_count_length = [1, Math.log10(total_files).ceil].max
|
16
|
+
|
17
|
+
str = ''
|
18
|
+
stats.each do |linter_name, lint_count, file_count|
|
19
|
+
str << "%#{lint_count_length}d %-#{linter_name_length}s" % [lint_count, linter_name]
|
20
|
+
str << " (across %#{file_count_length}d files)\n" % [file_count]
|
21
|
+
end
|
22
|
+
str << "#{'-' * lint_count_length} #{'-' * linter_name_length}"
|
23
|
+
str << " #{'-' * (file_count_length + 15)}\n"
|
24
|
+
str << "%#{lint_count_length}d #{'total'.ljust(linter_name_length)}" % total_lints
|
25
|
+
str << " (across %#{file_count_length}d files)\n" % total_files
|
26
|
+
str
|
27
|
+
end
|
28
|
+
|
29
|
+
def organize_stats
|
30
|
+
lints
|
31
|
+
.group_by(&:linter)
|
32
|
+
.sort_by { |_, lints_by_linter| -lints_by_linter.size }
|
33
|
+
.inject([]) do |ary, (linter, lints_by_linter)|
|
34
|
+
file_count = lints_by_linter.group_by(&:filename).size
|
35
|
+
ary << [linter.name, lints_by_linter.size, file_count]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/scss_lint/version.rb
CHANGED
@@ -60,4 +60,15 @@ describe SCSSLint::Linter::DisableLinterReason do
|
|
60
60
|
|
61
61
|
it { should_not report_lint }
|
62
62
|
end
|
63
|
+
|
64
|
+
context 'when a reason precedes an inline disabling comment' do
|
65
|
+
let(:scss) { <<-SCSS }
|
66
|
+
p {
|
67
|
+
// Disable for now
|
68
|
+
border: none; // scss-lint:disable BorderZero
|
69
|
+
}
|
70
|
+
SCSS
|
71
|
+
|
72
|
+
it { should_not report_lint }
|
73
|
+
end
|
63
74
|
end
|
@@ -163,6 +163,16 @@ describe SCSSLint::Linter::NameFormat do
|
|
163
163
|
it { should_not report_lint }
|
164
164
|
end
|
165
165
|
|
166
|
+
context 'when using whitelisted css function' do
|
167
|
+
let(:scss) { <<-SCSS }
|
168
|
+
.gradient {
|
169
|
+
background: linear-gradient(#000, #fff);
|
170
|
+
}
|
171
|
+
SCSS
|
172
|
+
|
173
|
+
it { should_not report_lint }
|
174
|
+
end
|
175
|
+
|
166
176
|
context 'when a mixin contains keyword arguments with underscores' do
|
167
177
|
let(:scss) { '@include mixin($some_var: 4);' }
|
168
178
|
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SCSSLint::Reporter::StatsReporter do
|
4
|
+
class SCSSLint::Linter::FakeLinter1 < SCSSLint::Linter; end
|
5
|
+
class SCSSLint::Linter::FakeLinter2 < SCSSLint::Linter; end
|
6
|
+
|
7
|
+
let(:logger) { SCSSLint::Logger.new($stdout) }
|
8
|
+
let(:linter_1) { SCSSLint::Linter::FakeLinter1.new }
|
9
|
+
let(:linter_2) { SCSSLint::Linter::FakeLinter2.new }
|
10
|
+
subject { SCSSLint::Reporter::StatsReporter.new(lints, [], logger) }
|
11
|
+
|
12
|
+
def new_lint(linter, filename, line)
|
13
|
+
SCSSLint::Lint.new(linter, filename, SCSSLint::Location.new(line), 'Description', :warning)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#report_lints' do
|
17
|
+
context 'when there are no lints' do
|
18
|
+
let(:lints) { [] }
|
19
|
+
|
20
|
+
it 'returns nil' do
|
21
|
+
subject.report_lints.should be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when there are lints from one linter in one file' do
|
26
|
+
let(:lints) do
|
27
|
+
[new_lint(linter_1, 'a.scss', 10), new_lint(linter_1, 'a.scss', 20)]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'prints one line per linter with lints, plus 2 summary lines' do
|
31
|
+
subject.report_lints.count("\n").should eq 3
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'prints the name of each linter with lints' do
|
35
|
+
subject.report_lints.scan(linter_1.name).count.should eq 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'prints the number of lints per linter' do
|
39
|
+
subject.report_lints.should include '2 FakeLinter1'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'prints the number of files where each linter found lints' do
|
43
|
+
subject.report_lints.should include '1 files'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'prints the total lints and total lines' do
|
47
|
+
subject.report_lints.should match /2 total +\(across 1/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when there are lints from multiple linters in one file' do
|
52
|
+
let(:lints) do
|
53
|
+
[new_lint(linter_1, 'a.scss', 10),
|
54
|
+
new_lint(linter_1, 'a.scss', 20),
|
55
|
+
new_lint(linter_2, 'a.scss', 30)]
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'prints one line per linter with lints, plus 2 summary lines' do
|
59
|
+
subject.report_lints.count("\n").should eq 4
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'prints the name of each linter with lints' do
|
63
|
+
subject.report_lints.scan(linter_1.name).count.should eq 1
|
64
|
+
subject.report_lints.scan(linter_2.name).count.should eq 1
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'prints the number of lints per linter' do
|
68
|
+
subject.report_lints.should include '2 FakeLinter1'
|
69
|
+
subject.report_lints.should include '1 FakeLinter2'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'prints the number of files where each linter found lints' do
|
73
|
+
subject.report_lints.scan(/FakeLinter\d +\(across 1 files/).count.should eq 2
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'prints the total lints and total lines' do
|
77
|
+
subject.report_lints.should match /3 total +\(across 1/
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when there are lints from multiple linters in multiple files' do
|
82
|
+
let(:lints) do
|
83
|
+
[new_lint(linter_1, 'a.scss', 10),
|
84
|
+
new_lint(linter_1, 'a.scss', 20),
|
85
|
+
new_lint(linter_2, 'a.scss', 30),
|
86
|
+
new_lint(linter_1, 'b.scss', 15),
|
87
|
+
new_lint(linter_2, 'b.scss', 25),
|
88
|
+
new_lint(linter_1, 'c.scss', 100)]
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'prints one line per linter with lints, plus 2 summary lines' do
|
92
|
+
subject.report_lints.count("\n").should eq 4
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'prints the name of each linter with lints' do
|
96
|
+
subject.report_lints.scan(linter_1.name).count.should eq 1
|
97
|
+
subject.report_lints.scan(linter_2.name).count.should eq 1
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'prints the number of lints per linter' do
|
101
|
+
subject.report_lints.should include '4 FakeLinter1'
|
102
|
+
subject.report_lints.should include '2 FakeLinter2'
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'prints the number of files where each linter found lints' do
|
106
|
+
subject.report_lints.scan(/FakeLinter2 +\(across 2 files/).count.should eq 1
|
107
|
+
subject.report_lints.scan(/FakeLinter1 +\(across 3 files/).count.should eq 1
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'prints the total lints and total lines' do
|
111
|
+
subject.report_lints.should match /6 total +\(across 3/
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
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.48.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brigade Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: '0.9'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '
|
23
|
+
version: '12'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: '0.9'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: sass
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,20 +45,6 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.4.15
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rspec
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 3.4.0
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 3.4.0
|
62
48
|
description: Configurable tool for writing clean and consistent SCSS
|
63
49
|
email:
|
64
50
|
- eng@brigade.com
|
@@ -164,6 +150,7 @@ files:
|
|
164
150
|
- lib/scss_lint/reporter/default_reporter.rb
|
165
151
|
- lib/scss_lint/reporter/files_reporter.rb
|
166
152
|
- lib/scss_lint/reporter/json_reporter.rb
|
153
|
+
- lib/scss_lint/reporter/stats_reporter.rb
|
167
154
|
- lib/scss_lint/reporter/tap_reporter.rb
|
168
155
|
- lib/scss_lint/runner.rb
|
169
156
|
- lib/scss_lint/sass/script.rb
|
@@ -253,6 +240,7 @@ files:
|
|
253
240
|
- spec/scss_lint/reporter/default_reporter_spec.rb
|
254
241
|
- spec/scss_lint/reporter/files_reporter_spec.rb
|
255
242
|
- spec/scss_lint/reporter/json_reporter_spec.rb
|
243
|
+
- spec/scss_lint/reporter/stats_reporter_spec.rb
|
256
244
|
- spec/scss_lint/reporter/tap_reporter_spec.rb
|
257
245
|
- spec/scss_lint/reporter_spec.rb
|
258
246
|
- spec/scss_lint/runner_spec.rb
|
@@ -367,6 +355,7 @@ test_files:
|
|
367
355
|
- spec/scss_lint/reporter/default_reporter_spec.rb
|
368
356
|
- spec/scss_lint/reporter/files_reporter_spec.rb
|
369
357
|
- spec/scss_lint/reporter/json_reporter_spec.rb
|
358
|
+
- spec/scss_lint/reporter/stats_reporter_spec.rb
|
370
359
|
- spec/scss_lint/reporter/tap_reporter_spec.rb
|
371
360
|
- spec/scss_lint/reporter_spec.rb
|
372
361
|
- spec/scss_lint/runner_spec.rb
|
@@ -374,4 +363,3 @@ test_files:
|
|
374
363
|
- spec/spec_helper.rb
|
375
364
|
- spec/support/isolated_environment.rb
|
376
365
|
- spec/support/matchers/report_lint.rb
|
377
|
-
has_rdoc:
|