Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 14, 2023
1 parent ff86030 commit df5edab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 11 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
})
}

/**
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down

0 comments on commit df5edab

Please sign in to comment.