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

Commit f80d3b8

Browse files
committed
Fix fix-all actions showing up even on non-fixable errors
1 parent ab8e96d commit f80d3b8

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

e2e/project-fixture/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
true,
55
"array-simple"
66
],
7+
"no-unused-expression": true,
78
"arrow-parens": true,
89
"no-var-keyword": true,
910
"no-unused-variable": [

e2e/tests/codeFixes.test.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function createServerForFile(fileContents) {
1919

2020
/**
2121
* @param {*} server
22-
* @param {{ startLine: number, startOffset: number, endLine: number, endOffset: number }} data
22+
* @param {{ startLine: number, startOffset: number, endLine: number, endOffset: number, additionalErrorCodes?: number[] }} data
2323
*/
2424
const getCodeFixes = async (server, data) => {
2525

@@ -32,7 +32,7 @@ const getCodeFixes = async (server, data) => {
3232
startOffset: data.startOffset,
3333
endLine: data.endLine,
3434
endOffset: data.endOffset,
35-
errorCodes: [1]
35+
errorCodes: [1, ...(data.additionalErrorCodes || [])]
3636
});
3737
};
3838

@@ -374,4 +374,24 @@ describe('CodeFixes', () => {
374374
assert.isTrue(codeFixesResponse.success);
375375
assert.deepEqual(codeFixesResponse.body, []);
376376
});
377+
378+
it('should not return TS Lint fix-all for non-fixable errors', async () => {
379+
server = createServerForFile(
380+
`const foo = 123; food`
381+
);
382+
await getCodeFixes(server, {
383+
startLine: 1,
384+
startOffset: 18,
385+
endLine: 1,
386+
endOffset: 22,
387+
additionalErrorCodes: [2552]
388+
});
389+
await server.close();
390+
const codeFixesResponse = await getFirstResponseOfType('getCodeFixes', server);
391+
392+
assert.isTrue(codeFixesResponse.success);
393+
assert.deepEqual(codeFixesResponse.body.length, 2);
394+
assert.deepEqual(codeFixesResponse.body[0].fixName, 'spelling');
395+
assert.deepEqual(codeFixesResponse.body[1].fixName, 'tslint:disable:no-unused-expression');
396+
});
377397
});

src/plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ export class TSLintPlugin {
212212
codeFixAction.fixId = TsLintFixId.fromFailure(problem.failure);
213213
codeFixAction.fixAllDescription = `Fix all '${problem.failure.getRuleName()}'`;
214214
}
215+
216+
fixes.push(this.getFixAllAutoFixableQuickFix(documentFixes, fileName));
215217
}
216218
}
217219

218-
fixes.push(this.getFixAllAutoFixableQuickFix(documentFixes, fileName));
219220
fixes.push(this.getDisableRuleQuickFix(problem.failure, fileName, this.getProgram().getSourceFile(fileName)!));
220221
}
221222
}

0 commit comments

Comments
 (0)