Skip to content

Commit

Permalink
Add support for ruleId, newer formatter fields
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Oct 28, 2018
1 parent 743bf28 commit c8cb145
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
39 changes: 18 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
'use strict'
module.exports = vfiles =>
vfiles.map(vfile => {
let errorCount = 0
let warningCount = 0

const messages = vfile.messages.map(x => {
if (x.fatal) {
errorCount++
} else {
warningCount++
}
const statistics = require('vfile-statistics')

return {
severity: x.fatal === true ? 2 : 1,
ruleId: x.ruleId,
line: x.line,
column: x.column,
message: x.reason
}
})
module.exports = vfiles =>
vfiles.map(vfile => {
const stats = statistics(vfile)

return {
filePath: vfile.path,
messages,
errorCount,
warningCount
messages: vfile.messages.map(x => {
return {
fatal: x.fatal === true,
severity: x.fatal ? 2 : 1,
ruleId: [x.source, x.ruleId].filter(Boolean).join(':') || null,
line: x.line,
column: x.column,
endLine: x.location.end.line,
endColumn: x.location.end.column,
message: x.reason
}
}),
errorCount: stats.fatal,
warningCount: stats.nonfatal
}
})
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"files": [
"index.js"
],
"dependencies": {},
"dependencies": {
"vfile-statistics": "^1.1.1"
},
"devDependencies": {
"ava": "^0.25.0",
"nyc": "^13.1.0",
Expand Down
28 changes: 24 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,56 @@ import m from '.'
test(t => {
const file = vfile({path: '~/example.md'})

file.info('This is perfect', {line: 5, column: 3})
file.message('This should be fixed', {line: 3, column: 5})
file.info('This is perfect', {line: 5, column: 3}, 'alpha:bravo')

file.message('This should be fixed', {
start: {line: 3, column: 5},
end: {line: 3, column: 7}
})

try {
file.fail('This is horrible', {line: 2, column: 1})
file.fail('This is horrible', {
type: 'charlie',
value: 'bravo',
position: {
start: {line: 2, column: 1},
end: {line: 2, column: 8}
}
})
} catch (error) {}

t.deepEqual(m([file]), [
{
filePath: '~/example.md',
messages: [
{
fatal: false,
severity: 1,
ruleId: null,
line: 5,
column: 3,
endLine: null,
endColumn: null,
ruleId: 'alpha:bravo',
message: 'This is perfect'
},
{
fatal: false,
severity: 1,
ruleId: null,
line: 3,
column: 5,
endLine: 3,
endColumn: 7,
message: 'This should be fixed'
},
{
fatal: true,
severity: 2,
ruleId: null,
line: 2,
column: 1,
endLine: 2,
endColumn: 8,
message: 'This is horrible'
}
],
Expand Down

0 comments on commit c8cb145

Please sign in to comment.