diff --git a/lib/index.js b/lib/index.js index 7f9093b..7720690 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,8 @@ /** - * @typedef {import('vfile').VFile} VFile - * @typedef {import('vfile-message').VFileMessage} VFileMessage * @typedef {import('eslint').ESLint.LintResult} LintResult * @typedef {import('eslint').Linter.LintMessage} LintMessage + * @typedef {import('vfile').VFile} VFile + * @typedef {import('vfile-message').VFileMessage} VFileMessage */ import {statistics} from 'vfile-statistics' @@ -17,7 +17,9 @@ import {statistics} from 'vfile-statistics' * Lint results. */ export function toESLint(files) { - return files.map((x) => file(x)) + return files.map(function (file) { + return transformFile(file) + }) } /** @@ -28,12 +30,14 @@ export function toESLint(files) { * @returns {LintResult} * ESLint result. */ -function file(file) { +function transformFile(file) { const stats = statistics(file) return { filePath: file.path, - messages: file.messages.map((x) => message(x)), + messages: file.messages.map(function (message) { + return transformMessage(message) + }), fatalErrorCount: stats.fatal, errorCount: stats.fatal, warningCount: stats.nonfatal, @@ -52,9 +56,10 @@ function file(file) { * @returns {LintMessage} * ESLint message. */ -function message(x) { +function transformMessage(x) { /* c8 ignore next */ const end = x.position ? x.position.end : {line: undefined, column: undefined} + return { fatal: x.fatal === true ? true : undefined, severity: x.fatal ? 2 : 1, diff --git a/test.js b/test.js index a7eb6c4..839e4d0 100644 --- a/test.js +++ b/test.js @@ -2,11 +2,10 @@ import assert from 'node:assert/strict' import test from 'node:test' import {VFile} from 'vfile' import {toESLint} from './index.js' -import * as mod from './index.js' -test('toESLint', () => { +test('toESLint', async function () { assert.deepEqual( - Object.keys(mod).sort(), + Object.keys(await import('./index.js')).sort(), ['toESLint'], 'should expose the public api' )