Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit c626444

Browse files
committed
feat: upgrade to linter v2 API
Upgrade to the v2 version of the linter API, allowing this provider to continue working with newer versions of linter.
1 parent d900472 commit c626444

File tree

4 files changed

+456
-452
lines changed

4 files changed

+456
-452
lines changed

lib/worker.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/* global emit */
44

5-
import escapeHTML from 'escape-html';
65
import fs from 'fs';
76
import path from 'path';
87
import { getRuleUri } from 'tslint-rule-documentation';
@@ -171,6 +170,11 @@ async function getProgram(Linter, configurationPath) {
171170
return program;
172171
}
173172

173+
function getSeverity(failure) {
174+
const severity = failure.ruleSeverity.toLowerCase();
175+
return ['info', 'warning', 'error'].includes(severity) ? severity : 'warning';
176+
}
177+
174178
/**
175179
* Lint the provided TypeScript content
176180
* @param content {string} The content of the TypeScript file
@@ -240,13 +244,16 @@ async function lint(content, filePath, options) {
240244
const startPosition = failure.getStartPosition().getLineAndCharacter();
241245
const endPosition = failure.getEndPosition().getLineAndCharacter();
242246
return {
243-
type: failure.ruleSeverity || 'warning',
244-
html: `${escapeHTML(failure.getFailure())} (<a href="${ruleUri.uri}">${failure.getRuleName()}</a>)`,
245-
filePath: path.normalize(failure.getFileName()),
246-
range: [
247-
[startPosition.line, startPosition.character],
248-
[endPosition.line, endPosition.character],
249-
],
247+
severity: getSeverity(failure),
248+
excerpt: `${failure.getFailure()} (${failure.getRuleName()})`,
249+
url: ruleUri.uri,
250+
location: {
251+
file: path.normalize(failure.getFileName()),
252+
position: [
253+
[startPosition.line, startPosition.character],
254+
[endPosition.line, endPosition.character],
255+
],
256+
},
250257
};
251258
});
252259
}

0 commit comments

Comments
 (0)