diff --git a/rules/utils/rename-identifier.js b/rules/utils/rename-identifier.js index 2edb64d23f..7b38e3e46e 100644 --- a/rules/utils/rename-identifier.js +++ b/rules/utils/rename-identifier.js @@ -28,7 +28,7 @@ function renameIdentifier(identifier, name, fixer, sourceCode) { // `typeAnnotation` if (identifier.typeAnnotation) { - return fixer.replaceText(identifier, `${name}${sourceCode.getText(identifier.typeAnnotation)}`); + return fixer.replaceText(identifier, `${name}${identifier.optional ? '?' : ''}${sourceCode.getText(identifier.typeAnnotation)}`); } return fixer.replaceText(identifier, name); diff --git a/test/prevent-abbreviations.js b/test/prevent-abbreviations.js index 2d5c33c13f..5b363b9887 100644 --- a/test/prevent-abbreviations.js +++ b/test/prevent-abbreviations.js @@ -1720,6 +1720,13 @@ typescriptRuleTester.run('prevent-abbreviations', rule, { code, output: code.replace('prop', 'property'), errors: createErrors() - })) + })), + + // #763 + { + code: 'const foo = (extraParams?: string) => {}', + output: 'const foo = (extraParameters?: string) => {}', + errors: createErrors() + } ] });