Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Don't crash on parse errors #34

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

Merged
merged 5 commits into from
Aug 16, 2016
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ image:
docker build -t codeclimate/codeclimate-csslint .

test: image
docker run --rm codeclimate/codeclimate-csslint rake
docker run --rm codeclimate/codeclimate-csslint rspec $(RSPEC_ARGS)
7 changes: 6 additions & 1 deletion lib/cc/engine/csslint.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
require "json"
require "nokogiri"
require "ostruct"
require "shellwords"

module CC
module Engine
MissingAttributesError = Class.new(StandardError)

DEFAULT_IDENTIFIER = OpenStruct.new(value: "parse-error")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nifty


class CSSlint
autoload :CheckDetails, "cc/engine/csslint/check_details"

Expand All @@ -30,8 +33,9 @@ def run

private

# rubocop:disable Metrics/MethodLength
def create_issue(node, path)
check_name = node.attributes.fetch("identifier").value
check_name = node.attributes.fetch("identifier", DEFAULT_IDENTIFIER).value
check_details = CheckDetails.fetch(check_name)

{
Expand All @@ -57,6 +61,7 @@ def create_issue(node, path)
rescue KeyError => ex
raise MissingAttributesError, "#{ex.message} on XML '#{node}' when analyzing file '#{path}'"
end
# rubocop:enable Metrics/MethodLength

def results
@results ||= Nokogiri::XML(csslint_xml)
Expand Down
1 change: 1 addition & 0 deletions lib/cc/engine/csslint/check_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CheckDetails
"import" => { categories: "Bug Risk" },
"known-properties" => { categories: "Bug Risk" },
"overqualified-elements" => { categories: "Bug Risk" },
"parse-error" => { categories: "Bug Risk" },
"regex-selectors" => { categories: "Bug Risk" },
"shorthand" => { categories: "Bug Risk" },
"star-property-hack" => { categories: "Compatibility" },
Expand Down
2 changes: 1 addition & 1 deletion spec/cc/engine/csslint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Engine

it 'fails on malformed file' do
create_source_file('foo.css', '�6�')
expect{ lint.run }.to raise_error(MissingAttributesError)
expect{ lint.run }.to output(/Unexpected token/).to_stdout
end

it "doesn't analyze *.scss files" do
Expand Down