Skip to content

Commit

Permalink
Make all lint to have linter attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke authored and sds committed Nov 5, 2017
1 parent 88425bf commit bdde989
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 19 deletions.
4 changes: 4 additions & 0 deletions lib/scss_lint/linter/encoding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module SCSSLint
class Linter::Encoding < Linter
end
end
4 changes: 4 additions & 0 deletions lib/scss_lint/linter/syntax.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module SCSSLint
class Linter::Syntax < Linter
end
end
1 change: 0 additions & 1 deletion lib/scss_lint/reporter/config_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def linters
end

def linter_name(linter)
return unless linter
linter.class.to_s.split('::').last
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/reporter/default_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def type(lint)
end

def message(lint)
linter_name = log.green("#{lint.linter.name}: ") if lint.linter
linter_name = log.green("#{lint.linter.name}: ")
"#{linter_name}#{lint.description}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/scss_lint/reporter/json_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def issue_hash(lint)
'severity' => lint.severity,
'reason' => lint.description,
}.tap do |hash|
hash['linter'] = lint.linter.name if lint.linter
hash['linter'] = lint.linter.name
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/scss_lint/reporter/tap_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ def format_not_ok(lint, test_number) # rubocop:disable Metrics/AbcSize
'column' => lint.location.column,
}

if lint.linter
test_line_description += " #{lint.linter.name}" if lint.linter
data['name'] = lint.linter.name
end
test_line_description += " #{lint.linter.name}"
data['name'] = lint.linter.name

data_yaml = data.to_yaml.strip.gsub(/^/, ' ')

Expand Down
4 changes: 2 additions & 2 deletions lib/scss_lint/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def find_lints(file) # rubocop:disable AbcSize
end
end
rescue Sass::SyntaxError => ex
@lints << Lint.new(nil, ex.sass_filename, Location.new(ex.sass_line),
@lints << Lint.new(Linter::Syntax.new, ex.sass_filename, Location.new(ex.sass_line),
"Syntax Error: #{ex}", :error)
rescue FileEncodingError => ex
@lints << Lint.new(nil, file[:path], Location.new, ex.to_s, :error)
@lints << Lint.new(Linter::Encoding.new, file[:path], Location.new, ex.to_s, :error)
end

# For stubbing in tests.
Expand Down
4 changes: 2 additions & 2 deletions spec/scss_lint/reporter/clean_files_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

let(:lints) do
dirty_files.map do |file|
SCSSLint::Lint.new(nil, file, SCSSLint::Location.new, '')
SCSSLint::Lint.new(SCSSLint::Linter::Comment.new, file, SCSSLint::Location.new, '')
end
end

Expand All @@ -61,7 +61,7 @@

let(:lints) do
files.map do |file|
SCSSLint::Lint.new(nil, file, SCSSLint::Location.new, '')
SCSSLint::Lint.new(SCSSLint::Linter::Comment.new, file, SCSSLint::Location.new, '')
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/scss_lint/reporter/config_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
context 'when there are lints' do
let(:linters) do
[SCSSLint::Linter::FinalNewline, SCSSLint::Linter::BorderZero,
SCSSLint::Linter::BorderZero, nil]
SCSSLint::Linter::BorderZero]
end
let(:lints) do
linters.each.map do |linter|
SCSSLint::Lint.new(linter ? linter.new : nil, '',
SCSSLint::Lint.new(linter.new, '',
SCSSLint::Location.new, '')
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/scss_lint/reporter/default_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
filenames.each_with_index.map do |filename, index|
line, column = locations[index]
location = SCSSLint::Location.new(line, column, 10)
SCSSLint::Lint.new(nil, filename, location, descriptions[index],
SCSSLint::Lint.new(SCSSLint::Linter::Comment, filename, location, descriptions[index],
severities[index])
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/scss_lint/reporter/files_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

let(:lints) do
filenames.map do |filename|
SCSSLint::Lint.new(nil, filename, SCSSLint::Location.new, '')
SCSSLint::Lint.new(SCSSLint::Linter::Comment.new, filename, SCSSLint::Location.new, '')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/scss_lint/reporter/json_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

let(:lints) do
filenames.each_with_index.map do |filename, index|
SCSSLint::Lint.new(nil, filename, locations[index],
SCSSLint::Lint.new(SCSSLint::LinterRegistry.linters.sample, filename, locations[index],
descriptions[index], severities[index])
end
end
Expand Down
42 changes: 39 additions & 3 deletions spec/scss_lint/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,51 @@ class SCSSLint::Linter::FakeLinter2 < SCSSLint::Linter; end

context 'when the engine raises a FileEncodingError' do
let(:error) do
SCSSLint::FileEncodingError.new('Some error message')
SCSSLint::FileEncodingError.new('File encoding error!')
end

before do
SCSSLint::Engine.stub(:new).and_raise(error)
subject
end

it 'records the error as a lint' do
subject.count.should == 2
it 'records the error as an Encoding lint' do
expect(runner.lints).to(
be_all { |lint| lint.linter.is_a?(SCSSLint::Linter::Encoding) }
)
end

it 'records the error with the error message' do
expect(runner.lints).to(
be_all { |lint| lint.description == error.message }
)
end
end

context 'when the engine raises a Sass::SyntaxError' do
let(:error) do
Sass::SyntaxError.new('Syntax error!', line: 42)
end

before do
SCSSLint::Engine.stub(:new).and_raise(error)
subject
end

it 'records the error as a Syntax lint' do
expect(runner.lints).to(
be_all { |lint| lint.linter.is_a?(SCSSLint::Linter::Syntax) }
)
end

it 'records the error with the error message' do
expect(runner.lints).to(
be_all { |lint| lint.description == "Syntax Error: #{error.message}" }
)
end

it 'records the error with the line number' do
expect(runner.lints).to(be_all { |lint| lint.location.line == 42 })
end
end

Expand Down

0 comments on commit bdde989

Please sign in to comment.