Skip to content

Commit

Permalink
feat(eslint-plugin-tslint): add fixer for config rule (#1342)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
  • Loading branch information
johnwiseheart and bradzacher committed Dec 17, 2019
1 parent 5c096de commit c52c5c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/eslint-plugin-tslint/src/rules/config.ts
Expand Up @@ -67,6 +67,7 @@ export default createRule<Options, MessageIds>({
category: 'TSLint' as any, // eslint-disable-line @typescript-eslint/no-explicit-any
recommended: false,
},
fixable: 'code',
type: 'problem',
messages: {
failure: '{{message}} (tslint:{{ruleName}})',
Expand Down Expand Up @@ -165,6 +166,23 @@ export default createRule<Options, MessageIds>({
column: end.character,
},
},
fix: fixer => {
const replacements = failure.getFix();

return Array.isArray(replacements)
? replacements.map(replacement =>
fixer.replaceTextRange(
[replacement.start, replacement.end],
replacement.text,
),
)
: replacements !== undefined
? fixer.replaceTextRange(
[replacements.start, replacements.end],
replacements.text,
)
: [];
},
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-tslint/tests/index.spec.ts
Expand Up @@ -86,7 +86,7 @@ ruleTester.run('tslint/config', rule, {
{
code: 'var foo = true // semicolon',
options: tslintRulesConfig,
output: 'var foo = true // semicolon',
output: 'var foo = true; // semicolon',
filename: './tests/fixture-project/4.ts',
errors: [
{
Expand Down
Expand Up @@ -5,7 +5,7 @@ Array [
Object {
"errorCount": 1,
"filePath": "/usr/linked/index.ts",
"fixableErrorCount": 0,
"fixableErrorCount": 1,
"fixableWarningCount": 0,
"messages": Array [
Object {
Expand All @@ -22,6 +22,13 @@ Array [
"column": 20,
"endColumn": 20,
"endLine": 1,
"fix": Object {
"range": Array [
19,
19,
],
"text": ";",
},
"line": 1,
"message": "Missing semicolon (tslint:semicolon)",
"messageId": "failure",
Expand Down

0 comments on commit c52c5c9

Please sign in to comment.