Skip to content

Commit c52c5c9

Browse files
feat(eslint-plugin-tslint): add fixer for config rule (typescript-eslint#1342)
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
1 parent 5c096de commit c52c5c9

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

packages/eslint-plugin-tslint/src/rules/config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default createRule<Options, MessageIds>({
6767
category: 'TSLint' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
6868
recommended: false,
6969
},
70+
fixable: 'code',
7071
type: 'problem',
7172
messages: {
7273
failure: '{{message}} (tslint:{{ruleName}})',
@@ -165,6 +166,23 @@ export default createRule<Options, MessageIds>({
165166
column: end.character,
166167
},
167168
},
169+
fix: fixer => {
170+
const replacements = failure.getFix();
171+
172+
return Array.isArray(replacements)
173+
? replacements.map(replacement =>
174+
fixer.replaceTextRange(
175+
[replacement.start, replacement.end],
176+
replacement.text,
177+
),
178+
)
179+
: replacements !== undefined
180+
? fixer.replaceTextRange(
181+
[replacements.start, replacements.end],
182+
replacements.text,
183+
)
184+
: [];
185+
},
168186
});
169187
});
170188
}

packages/eslint-plugin-tslint/tests/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ ruleTester.run('tslint/config', rule, {
8686
{
8787
code: 'var foo = true // semicolon',
8888
options: tslintRulesConfig,
89-
output: 'var foo = true // semicolon',
89+
output: 'var foo = true; // semicolon',
9090
filename: './tests/fixture-project/4.ts',
9191
errors: [
9292
{

tests/integration/fixtures/typescript-and-tslint-plugins-together/test.js.snap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Array [
55
Object {
66
"errorCount": 1,
77
"filePath": "/usr/linked/index.ts",
8-
"fixableErrorCount": 0,
8+
"fixableErrorCount": 1,
99
"fixableWarningCount": 0,
1010
"messages": Array [
1111
Object {
@@ -22,6 +22,13 @@ Array [
2222
"column": 20,
2323
"endColumn": 20,
2424
"endLine": 1,
25+
"fix": Object {
26+
"range": Array [
27+
19,
28+
19,
29+
],
30+
"text": ";",
31+
},
2532
"line": 1,
2633
"message": "Missing semicolon (tslint:semicolon)",
2734
"messageId": "failure",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy