Skip to content

Commit 7781c3f

Browse files
authored
prevent-abbreviations: Fix optional parameter (#764)
1 parent 56f6e76 commit 7781c3f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

rules/utils/rename-identifier.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function renameIdentifier(identifier, name, fixer, sourceCode) {
2828

2929
// `typeAnnotation`
3030
if (identifier.typeAnnotation) {
31-
return fixer.replaceText(identifier, `${name}${sourceCode.getText(identifier.typeAnnotation)}`);
31+
return fixer.replaceText(identifier, `${name}${identifier.optional ? '?' : ''}${sourceCode.getText(identifier.typeAnnotation)}`);
3232
}
3333

3434
return fixer.replaceText(identifier, name);

test/prevent-abbreviations.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,13 @@ typescriptRuleTester.run('prevent-abbreviations', rule, {
17201720
code,
17211721
output: code.replace('prop', 'property'),
17221722
errors: createErrors()
1723-
}))
1723+
})),
1724+
1725+
// #763
1726+
{
1727+
code: 'const foo = (extraParams?: string) => {}',
1728+
output: 'const foo = (extraParameters?: string) => {}',
1729+
errors: createErrors()
1730+
}
17241731
]
17251732
});

0 commit comments

Comments
 (0)