Skip to content

Commit

Permalink
Merge c5e94ee into ee6a915
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 16, 2020
2 parents ee6a915 + c5e94ee commit f85b635
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rules/prevent-abbreviations.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ const fixIdentifier = (fixer, replacement, sourceCode) => identifier => {
return fixer.replaceText(identifier, `${replacement} = ${sourceCode.getText(identifier.default)}`);
}

// `typeAnnotation`
if (identifier.typeAnnotation) {
return fixer.replaceText(identifier, `${replacement}${sourceCode.getText(identifier.typeAnnotation)}`);
}

return fixer.replaceText(identifier, replacement);
};

Expand Down
29 changes: 29 additions & 0 deletions test/prevent-abbreviations.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,35 @@ babelRuleTester.run('prevent-abbreviations', rule, {
errors: createErrors()
},

// #347
{
code: outdent`
function onKeyDown(e: KeyboardEvent) {
if (e.keyCode) {
// ...
}
}
`,
output: outdent`
function onKeyDown(event: KeyboardEvent) {
if (event.keyCode) {
// ...
}
}
`,
options: [
{
extendDefaultReplacements: false,
replacements: {
e: {
event: true
}
}
}
],
errors: createErrors()
},

// https://github.com/facebook/relay/blob/597d2a17aa29d401830407b6814a5f8d148f632d/packages/relay-experimental/EntryPointTypes.flow.js#L138
{
code: outdent`
Expand Down

0 comments on commit f85b635

Please sign in to comment.