diff --git a/index.js b/index.js index ee47e1f..d2e6cf6 100644 --- a/index.js +++ b/index.js @@ -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 } }) diff --git a/package.json b/package.json index 1f4fc6d..49f06f3 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "files": [ "index.js" ], - "dependencies": {}, + "dependencies": { + "vfile-statistics": "^1.1.1" + }, "devDependencies": { "ava": "^0.25.0", "nyc": "^13.1.0", diff --git a/test.js b/test.js index cfc9870..33c5fb3 100644 --- a/test.js +++ b/test.js @@ -5,11 +5,22 @@ 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]), [ @@ -17,24 +28,33 @@ test(t => { 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' } ],