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

Commit

Permalink
feat: upgrade to linter v2 API
Browse files Browse the repository at this point in the history
Upgrade to the v2 version of the linter API, allowing this provider to 
continue working with newer versions of linter.
  • Loading branch information
Arcanemagus committed Jan 20, 2019
1 parent d900472 commit c626444
Show file tree
Hide file tree
Showing 4 changed files with 456 additions and 452 deletions.
23 changes: 15 additions & 8 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/* global emit */

import escapeHTML from 'escape-html';
import fs from 'fs';
import path from 'path';
import { getRuleUri } from 'tslint-rule-documentation';
Expand Down Expand Up @@ -171,6 +170,11 @@ async function getProgram(Linter, configurationPath) {
return program;
}

function getSeverity(failure) {
const severity = failure.ruleSeverity.toLowerCase();
return ['info', 'warning', 'error'].includes(severity) ? severity : 'warning';
}

/**
* Lint the provided TypeScript content
* @param content {string} The content of the TypeScript file
Expand Down Expand Up @@ -240,13 +244,16 @@ async function lint(content, filePath, options) {
const startPosition = failure.getStartPosition().getLineAndCharacter();
const endPosition = failure.getEndPosition().getLineAndCharacter();
return {
type: failure.ruleSeverity || 'warning',
html: `${escapeHTML(failure.getFailure())} (<a href="${ruleUri.uri}">${failure.getRuleName()}</a>)`,
filePath: path.normalize(failure.getFileName()),
range: [
[startPosition.line, startPosition.character],
[endPosition.line, endPosition.character],
],
severity: getSeverity(failure),
excerpt: `${failure.getFailure()} (${failure.getRuleName()})`,
url: ruleUri.uri,
location: {
file: path.normalize(failure.getFileName()),
position: [
[startPosition.line, startPosition.character],
[endPosition.line, endPosition.character],
],
},
};
});
}
Expand Down
Loading

0 comments on commit c626444

Please sign in to comment.