Skip to content

Commit

Permalink
prevent-abbreviations: Fix optional parameter (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jun 2, 2020
1 parent 56f6e76 commit 7781c3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rules/utils/rename-identifier.js
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion test/prevent-abbreviations.js
Expand Up @@ -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()
}
]
});

0 comments on commit 7781c3f

Please sign in to comment.