Skip to content

Commit

Permalink
Merge 883a02d into 2b78a17
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 16, 2020
2 parents 2b78a17 + 883a02d commit a0d903a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions rules/prevent-abbreviations.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ const isShorthandExportIdentifier = identifier => {
);
};

const fixIdentifier = (fixer, replacement) => identifier => {
const fixIdentifier = (fixer, replacement, sourceCode) => identifier => {
if (
isShorthandPropertyIdentifier(identifier) ||
isAssignmentPatternShorthandPropertyIdentifier(identifier)
Expand All @@ -457,6 +457,11 @@ const fixIdentifier = (fixer, replacement) => identifier => {
return fixer.replaceText(identifier, `${replacement} as ${identifier.name}`);
}

// `TypeParameter` default value
if (identifier.default) {
return fixer.replaceText(identifier, `${replacement} = ${sourceCode.getText(identifier.default)}`);
}

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

Expand Down Expand Up @@ -572,6 +577,7 @@ const create = context => {
const {ecmaVersion} = context.parserOptions;
const options = prepareOptions(context.options[0]);
const filenameWithExtension = context.getFilename();
const sourceCode = context.getSourceCode();

// A `class` declaration produces two variables in two scopes:
// the inner class scope, and the outer one (whereever the class is declared).
Expand Down Expand Up @@ -691,7 +697,7 @@ const create = context => {

problem.fix = fixer => {
return variableIdentifiers(variable)
.map(fixIdentifier(fixer, replacement));
.map(fixIdentifier(fixer, replacement, sourceCode));
};
}

Expand Down
6 changes: 3 additions & 3 deletions test/integration/eslint-config-unicorn-tester/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "eslint-config-unicorn-tester",
"dependencies": {
"@typescript-eslint/parser": "2.19.2",
"babel-eslint": "^10.0.3",
"@typescript-eslint/parser": "2.23.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-plugin-unicorn": "file:../../..",
"typescript": "3.7.5",
"typescript": "3.8.3",
"vue-eslint-parser": "7.0.0"
}
}
1 change: 1 addition & 0 deletions test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const projects = [
},
'https://github.com/chakra-ui/chakra-ui',
'https://github.com/ReactTraining/react-router',
'https://github.com/facebook/relay',
'https://github.com/mozilla/pdf.js'
].map(project => {
if (typeof project === 'string') {
Expand Down
11 changes: 11 additions & 0 deletions test/prevent-abbreviations.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,17 @@ babelRuleTester.run('prevent-abbreviations', rule, {
errors: createErrors()
},

// https://github.com/facebook/relay/blob/597d2a17aa29d401830407b6814a5f8d148f632d/packages/relay-experimental/EntryPointTypes.flow.js#L138
{
code: outdent`
export type PreloadProps<TExtraProps = null> = {}
`,
output: outdent`
export type PreloadProperties<TExtraProperties = null> = {}
`,
errors: [...createErrors(), ...createErrors()]
},

noFixingTestCase({
code: '(class {e = 1})',
options: checkPropertiesOptions,
Expand Down

0 comments on commit a0d903a

Please sign in to comment.