Skip to content

Commit

Permalink
Update tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 6, 2023
1 parent 700ed7b commit 07f6f03
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
36 changes: 24 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +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
*/

import {statistics} from 'vfile-statistics'
Expand All @@ -15,18 +17,7 @@ export function toESLint(vfiles) {

return {
filePath: vfile.path,
messages: vfile.messages.map((x) => {
return {
fatal: x.fatal === true ? true : undefined,
severity: x.fatal ? 2 : 1,
ruleId: [x.source, x.ruleId].filter(Boolean).join(':') || null,
line: x.line,
column: x.column,
endLine: x.position.end.line,
endColumn: x.position.end.column,
message: x.reason
}
}),
messages: vfile.messages.map((x) => mapMessage(x)),
fatalErrorCount: stats.fatal,
errorCount: stats.fatal,
warningCount: stats.nonfatal,
Expand All @@ -37,3 +28,24 @@ export function toESLint(vfiles) {
}
})
}

/**
* Map a message.
*
* @param {VFileMessage} x
* @returns {LintMessage}
*/
function mapMessage(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,
ruleId: [x.source, x.ruleId].filter(Boolean).join(':') || null,
line: x.line || 0,
column: x.column || 0,
endLine: end.line || undefined,
endColumn: end.column || undefined,
message: x.reason
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
Expand Down
19 changes: 16 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {toESLint} from './index.js'
test('toESLint', (t) => {
const file = new VFile({path: '~/example.md'})

const message = file.info('?')
message.position = null

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

file.message('This should be fixed', {
Expand All @@ -27,14 +30,24 @@ test('toESLint', (t) => {
{
filePath: '~/example.md',
messages: [
{
fatal: undefined,
severity: 1,
ruleId: null,
line: 0,
column: 0,
endLine: undefined,
endColumn: undefined,
message: '?'
},
{
fatal: undefined,
severity: 1,
ruleId: 'alpha:bravo',
line: 5,
column: 3,
endLine: null,
endColumn: null,
endLine: undefined,
endColumn: undefined,
message: 'This is perfect'
},
{
Expand All @@ -60,7 +73,7 @@ test('toESLint', (t) => {
],
fatalErrorCount: 1,
errorCount: 1,
warningCount: 2,
warningCount: 3,
fixableErrorCount: 0,
fixableWarningCount: 0,
usedDeprecatedRules: [],
Expand Down
18 changes: 10 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"include": ["*.js"],
"include": ["**/*.js"],
"exclude": ["coverage/", "node_modules/"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2020"],
"module": "node16",
"newLine": "lf",
"skipLibCheck": true,
"strict": true,
"target": "es2020"
}
}

0 comments on commit 07f6f03

Please sign in to comment.