Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support stylelint 16+, which emits messages on stderr #848

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/overcommit/hook/pre_commit/stylelint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Stylelint < Base

def run
result = execute(command, args: applicable_files)
output = result.stdout.chomp
output = result.stdout + result.stderr.chomp
return :pass if result.success? && output.empty?

extract_messages(
Expand Down
29 changes: 28 additions & 1 deletion spec/overcommit/hook/pre_commit/stylelint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
before do
result = double('result')
result.stub(:success?).and_return(true)
result.stub(:stderr).and_return('')
result.stub(:stdout).and_return('')
subject.stub(:execute).and_return(result)
end

it { should pass }
end

context 'when stylelint exits unsucessfully' do
context 'when stylelint exits unsucessfully with messages on stdout (stylelint < 16)' do
let(:result) { double('result') }

before do
Expand All @@ -32,6 +33,7 @@
context 'and it reports an error' do
before do
result.stub(:success?).and_return(false)
result.stub(:stderr).and_return('')
result.stub(:stdout).and_return([
'index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)',
'form.css: line 10, col 6, error - Expected indentation of 4 spaces (indentation)',
Expand All @@ -45,4 +47,29 @@
end
end
end

context 'when stylelint exits unsucessfully with messages on stderr (stylelint >= 16)' do
let(:result) { double('result') }

before do
subject.stub(:execute).and_return(result)
end

context 'and it reports an error' do
before do
result.stub(:success?).and_return(false)
result.stub(:stdout).and_return('')
result.stub(:stderr).and_return([
'index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)',
'form.css: line 10, col 6, error - Expected indentation of 4 spaces (indentation)',
].join("\n"))
end

it { should fail_hook }

it 'extracts lines numbers correctly from output' do
expect(subject.run.map(&:line)).to eq([4, 10])
end
end
end
end