forked from houndci/hound
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Sass-lint (houndci#1349)
This commit adds support for Sass-lint using the new singular linters queue. It's disabled by default in favor of SCSSLint and updates `/configuration` with configuration instructions.
- Loading branch information
1 parent
5a839d5
commit fdc7806
Showing
9 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Config | ||
class SassLint < Base | ||
def serialize(data = content) | ||
Serializer.yaml(data) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Linter | ||
class SassLint < Base | ||
FILE_REGEXP = /.+\.s(a|c)ss\z/ | ||
|
||
def job_class | ||
LintersJob | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require "app/models/config/base" | ||
require "app/models/config/sass_lint" | ||
require "app/models/config/parser" | ||
require "app/models/config/parser_error" | ||
require "app/models/config/serializer" | ||
require "app/models/config_content" | ||
require "app/models/missing_owner" | ||
|
||
describe Config::SassLint do | ||
describe "#content" do | ||
context "when an owner is provided" do | ||
it "merges the configuration into the owner's configuration" do | ||
raw_config = <<~EOS | ||
rules: | ||
indentation: | ||
- 2 | ||
- | ||
size: 2 | ||
EOS | ||
owner_config = { | ||
"rules" => { | ||
"brace-style" => [ | ||
2, | ||
{ "style" => "stroustrup" }, | ||
], | ||
}, | ||
} | ||
owner = instance_double("Owner", config_content: owner_config) | ||
config = build_config(raw_config, owner) | ||
|
||
expect(config.content).to eq( | ||
"rules" => { | ||
"indentation" => [2, { "size" => 2 }], | ||
"brace-style" => [2, { "style" => "stroustrup" }], | ||
}, | ||
) | ||
end | ||
end | ||
|
||
context "when there is no owner" do | ||
it "parses the configuration using to return a hash" do | ||
raw_config = <<~EOS | ||
rules: | ||
indentation: | ||
- 2 | ||
- | ||
size: 2 | ||
EOS | ||
config = build_config(raw_config) | ||
|
||
expect(config.content).to eq( | ||
"rules" => { | ||
"indentation" => [2, { "size" => 2 }], | ||
}, | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe "#serialize" do | ||
it "serializes the parsed content into YAML" do | ||
raw_config = <<~EOS | ||
rules: | ||
indentation: | ||
- 2 | ||
- | ||
size: 2 | ||
foo: bar | ||
EOS | ||
config = build_config(raw_config) | ||
|
||
expect(config.serialize).to eq <<~EOS | ||
--- | ||
rules: | ||
indentation: | ||
- 2 | ||
- size: 2 | ||
foo: bar | ||
EOS | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Linter::SassLint do | ||
it_behaves_like "a linter" do | ||
let(:lintable_files) { %w(foo.scss foo.sass) } | ||
let(:not_lintable_files) { %w(foo.css bar.html) } | ||
end | ||
|
||
describe "#file_review" do | ||
it "returns a saved and incomplete file review" do | ||
linter = build_linter | ||
commit_file = build_commit_file(filename: "scss/styles.scss") | ||
|
||
result = linter.file_review(commit_file) | ||
|
||
expect(result).to be_persisted | ||
expect(result).not_to be_completed | ||
end | ||
|
||
it "schedule a review job" do | ||
build = build(:build, commit_sha: "baa", pull_request_number: 23) | ||
linter = build_linter(build) | ||
stub_sass_config({}) | ||
commit_file = build_commit_file(filename: "scss/styles.scss") | ||
allow(Resque).to receive(:enqueue) | ||
|
||
linter.file_review(commit_file) | ||
|
||
expect(Resque).to have_received(:enqueue).with( | ||
LintersJob, | ||
filename: commit_file.filename, | ||
commit_sha: build.commit_sha, | ||
linter_name: "sass_lint", | ||
pull_request_number: build.pull_request_number, | ||
patch: commit_file.patch, | ||
content: commit_file.content, | ||
config: "{}", | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def stub_sass_config(config = {}) | ||
stubbed_sass_config = double( | ||
"SassConfig", | ||
content: config, | ||
serialize: config.to_s, | ||
) | ||
allow(Config::SassLint).to receive(:new).and_return(stubbed_sass_config) | ||
|
||
stubbed_sass_config | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters