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

Commit

Permalink
Merge pull request #231 from AdenFlorian/master
Browse files Browse the repository at this point in the history
Allows naming which quick fixes should be run on save
  • Loading branch information
egamma committed Jul 24, 2017
2 parents a97b287 + 6c5993a commit 41750ce
Show file tree
Hide file tree
Showing 8 changed files with 2,589 additions and 13 deletions.
6 changes: 4 additions & 2 deletions tslint-server/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"javascript.validate.enable": false,
"files.trimTrailingWhitespace": true,
"editor.insertSpaces": false,
"editor.tabSize": 4
}
"editor.tabSize": 4,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
"editor.formatOnSave": false
}
13 changes: 11 additions & 2 deletions tslint-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ interface Settings {
exclude: string | string[];
validateWithDefaultConfig: boolean;
run: 'onSave' | 'onType';
alwaysShowRuleFailuresAsWarnings: boolean
alwaysShowRuleFailuresAsWarnings: boolean,
autoFixOnSave: boolean | string[]
};
}

Expand Down Expand Up @@ -838,7 +839,7 @@ export function overlaps(lastFix: AutoFix, nextFix: AutoFix): boolean {
return true;
} else if (last.range[1].line < next.range[0].line) {
return false;
} else if (last.range[1].character >= next.range[0].character){
} else if (last.range[1].character >= next.range[0].character) {
doesOverlap = true;
return true;
}
Expand Down Expand Up @@ -873,6 +874,7 @@ function createTextEdit(autoFix: AutoFix): server.TextEdit[] {

interface AllFixesParams {
textDocument: server.TextDocumentIdentifier;
isOnSave: boolean;
}

interface AllFixesResult {
Expand Down Expand Up @@ -902,6 +904,13 @@ connection.onRequest(AllFixesRequest.type, (params) => {
break;
}
}

// Filter out fixes for problems that aren't set to be autofixable on save
if (params.isOnSave && Array.isArray(settings.tslint.autoFixOnSave)) {
const autoFixOnSave = settings.tslint.autoFixOnSave as Array<string>;
fixes = fixes.filter(fix => autoFixOnSave.indexOf(fix.problem.getRuleName()) > -1);
}

let allFixes = getAllNonOverlappingFixes(fixes);

result = {
Expand Down
8 changes: 5 additions & 3 deletions tslint-tests/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.autoSave": "off",
"tslint.autoFixOnSave": true,
"tslint.autoFixOnSave": [
"arrow-parens"
],
// "tslint.nodePath": "c:\\tmp",
"tslint.jsEnable": true
// "tslint.trace.server": "verbose"
// "tslint.alwaysShowRuleFailuresAsWarnings": true
}
// "tslint.alwaysShowRuleFailuresAsWarnings": true,
}
3 changes: 3 additions & 0 deletions tslint-tests/tests/selective-auto-fix-on-save.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let z = 'quotemark';

[1, 2].map(num => console.log('test: ' + num));
6 changes: 4 additions & 2 deletions tslint/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
},
"files.trimTrailingWhitespace": true,
"editor.insertSpaces": false,
"editor.tabSize": 4
}
"editor.tabSize": 4,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
"editor.formatOnSave": false
}
3 changes: 2 additions & 1 deletion tslint/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const tslintConfig: string = [

interface AllFixesParams {
textDocument: TextDocumentIdentifier;
isOnSave: boolean;
}

interface AllFixesResult {
Expand Down Expand Up @@ -315,7 +316,7 @@ export function activate(context: ExtensionContext) {
}
const version = document.version;
event.waitUntil(
client.sendRequest(AllFixesRequest.type, { textDocument: { uri: document.uri.toString() } }).then((result) => {
client.sendRequest(AllFixesRequest.type, { textDocument: { uri: document.uri.toString() }, isOnSave: true }).then((result) => {
if (result && version === result.documentVersion) {
return client.protocol2CodeConverter.asTextEdits(result.edits);
} else {
Expand Down
Loading

0 comments on commit 41750ce

Please sign in to comment.