Skip to content

Commit 4f21177

Browse files
committedApr 8, 2015
Handle custom scss-lint exit statuses
The `scss-lint` executable now returns a special status code when all files that were specified were filtered by exclusions specified by its configuration. Previously, this would return an error code that was ambiguous, but it now returns a custom error code specifically for this case. Handling it in Overcommit allows us to save developers the hassle of duplicating their exclusion configuration from `.scss-lint.yml` to `.overcommit.yml`. In the process, we also fixed the hook to always fail unless the status code indicates lint warnings/errors, since that means the tool was invoked incorrectly or some other problem is present.
1 parent 7f23eb4 commit 4f21177

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
 

‎lib/overcommit/hook/pre_commit/scss_lint.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ class ScssLint < Base
77

88
def run
99
result = execute(command + applicable_files)
10-
return :pass if result.success?
10+
11+
# Status code 81 indicates the applicable files were all filtered by
12+
# exclusions defined by the configuration. In this case, we're happy to
13+
# return success since there were technically no lints.
14+
return :pass if [0, 81].include?(result.status)
15+
16+
# Any status that isn't indicating lint warnings or errors indicates failure
17+
return :fail, result.stdout unless [1, 2].include?(result.status)
1118

1219
extract_messages(
1320
result.stdout.split("\n"),

‎spec/overcommit/hook/pre_commit/scss_lint_spec.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
context 'when scss-lint exits successfully' do
1313
before do
1414
result = double('result')
15-
result.stub(:success?).and_return(true)
15+
result.stub(:status).and_return(0)
16+
result.stub(:stdout).and_return('')
1617
subject.stub(:execute).and_return(result)
1718
end
1819

@@ -23,12 +24,12 @@
2324
let(:result) { double('result') }
2425

2526
before do
26-
result.stub(:success?).and_return(false)
2727
subject.stub(:execute).and_return(result)
2828
end
2929

3030
context 'and it reports a warning' do
3131
before do
32+
result.stub(:status).and_return(1)
3233
result.stub(:stdout).and_return([
3334
'file1.scss:1 [W] Prefer single quoted strings',
3435
].join("\n"))
@@ -39,12 +40,22 @@
3940

4041
context 'and it reports an error' do
4142
before do
43+
result.stub(:status).and_return(2)
4244
result.stub(:stdout).and_return([
4345
'file1.scss:1 [E] Syntax Error: Invalid CSS',
4446
].join("\n"))
4547
end
4648

4749
it { should fail_hook }
4850
end
51+
52+
context 'and it returns status code indicating all files were filtered' do
53+
before do
54+
result.stub(:status).and_return(81)
55+
result.stub(:stdout).and_return('')
56+
end
57+
58+
it { should pass }
59+
end
4960
end
5061
end

0 commit comments

Comments
 (0)
Please sign in to comment.