Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
tslint 5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
egamma committed Mar 30, 2017
1 parent c90c882 commit bd698af
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
48 changes: 24 additions & 24 deletions tslint-server/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "tslint-server",
"version": "0.2.0",
"description": "TSLint Linter Server",
"engines": {
"node": "*"
},
"private": true,
"dependencies": {
"minimatch": "^3.0.0",
"vscode-languageserver": "^3.0.2-beta.3",
"semver": "^5.1.0"
},
"devDependencies": {
"@types/minimatch": "^2.0.29",
"@types/node": "^6.0.41",
"@types/semver": "^5.3.30",
"typescript": "^2.0.3",
"tslint": "^4.0.1"
},
"scripts": {
"compile": "installServerIntoExtension ../tslint ./package.json ./src/tsconfig.json && tsc -p ./src",
"watch": "installServerIntoExtension ../tslint ./package.json ./src/tsconfig.json && tsc --watch -p ./src"
}
{
"name": "tslint-server",
"version": "0.2.0",
"description": "TSLint Linter Server",
"engines": {
"node": "*"
},
"private": true,
"dependencies": {
"minimatch": "^3.0.0",
"vscode-languageserver": "^3.0.2-beta.3",
"semver": "^5.1.0"
},
"devDependencies": {
"@types/minimatch": "^2.0.29",
"@types/node": "^6.0.41",
"@types/semver": "^5.3.30",
"typescript": "^2.0.3",
"tslint": "^5.0.0"
},
"scripts": {
"compile": "installServerIntoExtension ../tslint ./package.json ./src/tsconfig.json && tsc -p ./src",
"watch": "installServerIntoExtension ../tslint ./package.json ./src/tsconfig.json && tsc --watch -p ./src"
}
}
36 changes: 30 additions & 6 deletions tslint-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function recordCodeAction(document: server.TextDocument, diagnostic: server.Diag
let fix: AutoFix = null;

// tslint can return a fix with an empty replacements array, these fixes are ignored
if (problem.getFix && problem.getFix() && problem.getFix().replacements.length > 0) { // tslint fixes are not available in tslint < 3.17
if (problem.getFix && problem.getFix() && !replacementsAreEmpty(problem.getFix())) { // tslint fixes are not available in tslint < 3.17
fix = createAutoFix(problem, document, problem.getFix());
}
if (!fix) {
Expand Down Expand Up @@ -707,17 +707,41 @@ connection.onCodeAction((params) => {
return result;
});


function replacementsAreEmpty(fix: tslint.Fix): boolean {
// in tslint 4 a Fix has a replacement property witht the Replacements
if ((<any>fix).replacements) {
return (<any>fix).replacements.length === 0;
}
// tslint 5
if (Array.isArray(fix)) {
return fix.length === 0;
}
return false;
}

function createAutoFix(problem: tslint.RuleFailure, document: server.TextDocument, fix: tslint.Fix | TSLintAutofixEdit): AutoFix {
let edits: TSLintAutofixEdit[] = null;

function isTslintFix(fix: tslint.Fix | TSLintAutofixEdit): fix is tslint.Fix {
return (<tslint.Fix>fix).replacements !== undefined;
function isTslintAutofixEdit(fix: tslint.Fix | TSLintAutofixEdit): fix is TSLintAutofixEdit {
return (<TSLintAutofixEdit>fix).range !== undefined;
}

if (isTslintFix(fix)) {
edits = fix.replacements.map(each => convertReplacementToAutoFix(document, each));
} else {
if (isTslintAutofixEdit(fix)) {
edits = [fix];
} else {
let ff: any = fix;
// in tslint4 a Fix has a replacement property witht the Replacements
if (ff.replacements) {
// tslint4
edits = ff.replacements.map(each => convertReplacementToAutoFix(document, each));
} else {
// in tslint 5 a Fix is a Replacment | Replacement[]
if (!Array.isArray(fix)) {
fix = [fix];
}
edits = fix.map(each => convertReplacementToAutoFix(document, each));
}
}

let autofix: AutoFix = {
Expand Down
2 changes: 1 addition & 1 deletion tslint-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"gulp": "^3.9.1",
"gulp-tslint": "^7.1.0",
"tslint": "^4.4.2"
"tslint": "^5.0.0"
},
"devDependencies": {
"typescript": "^2.0.10"
Expand Down

0 comments on commit bd698af

Please sign in to comment.