Skip to content

Commit

Permalink
Add linter field to JSON reporter
Browse files Browse the repository at this point in the history
This change adds a new field `linter` into `offenses` with the JSON reporter.
The default reporter outputs linter names,
so I think it useful if the JSON reporter also does it.
  • Loading branch information
ybiquitous committed Feb 2, 2021
1 parent a89a91d commit e55e6ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Gemfile.lock
/coverage
/pkg
.ruby-version
1 change: 1 addition & 0 deletions lib/slim_lint/reporter/json_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def map_offense(offense)
location: {
line: offense.line,
},
linter: offense.linter&.name,
}
end
end
Expand Down
14 changes: 13 additions & 1 deletion spec/slim_lint/reporter/json_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
let(:lines) { [502, 724] }
let(:descriptions) { ['Description of lint 1', 'Description of lint 2'] }
let(:severities) { [:warning, :error] }
let(:linters) { [double(name: 'SomeLinter'), nil] }

let(:lints) do
filenames.each_with_index.map do |filename, index|
SlimLint::Lint.new(nil, filename, lines[index], descriptions[index], severities[index])
SlimLint::Lint.new(linters[index], filename, lines[index], descriptions[index],
severities[index])
end
end

Expand All @@ -60,6 +62,16 @@
output['files'].map { |f| f['path'] }.sort.should eq filenames.sort
end

it 'list of offenses' do
subject
output['files'].sort_by { |f| f['path'] }.map { |f| f['offenses'] }.should eq [
[{ 'linter' => nil, 'location' => { 'line' => 724 },
'message' => 'Description of lint 2', 'severity' => 'error' }],
[{ 'linter' => 'SomeLinter', 'location' => { 'line' => 502 },
'message' => 'Description of lint 1', 'severity' => 'warning' }],
]
end

it_behaves_like 'output format specification'
end
end
Expand Down

0 comments on commit e55e6ac

Please sign in to comment.