New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: no-useless-rename also reports default values (fixes #12301) #12322
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,12 @@ module.exports = { | |
}, | ||
|
||
create(context) { | ||
const options = context.options[0] || {}, | ||
const sourceCode = context.getSourceCode(), | ||
options = context.options[0] || {}, | ||
ignoreDestructuring = options.ignoreDestructuring === true, | ||
ignoreImport = options.ignoreImport === true, | ||
ignoreExport = options.ignoreExport === true; | ||
|
||
const sourceCode = context.getSourceCode(); | ||
|
||
//-------------------------------------------------------------------------- | ||
// Helpers | ||
//-------------------------------------------------------------------------- | ||
|
@@ -69,10 +68,15 @@ module.exports = { | |
if (sourceCode.commentsExistBetween(initial, result)) { | ||
return null; | ||
} | ||
|
||
const replacementText = result.type === "AssignmentPattern" | ||
? sourceCode.getText(result) | ||
: name; | ||
|
||
return fixer.replaceTextRange([ | ||
initial.range[0], | ||
result.range[1] | ||
], name); | ||
], replacementText); | ||
} | ||
}); | ||
} | ||
|
@@ -87,26 +91,21 @@ module.exports = { | |
return; | ||
} | ||
|
||
const properties = node.properties; | ||
|
||
for (let i = 0; i < properties.length; i++) { | ||
if (properties[i].shorthand) { | ||
continue; | ||
} | ||
for (const property of node.properties) { | ||
|
||
/** | ||
* If an ObjectPattern property is computed, we have no idea | ||
* if a rename is useless or not. If an ObjectPattern property | ||
* lacks a key, it is likely an ExperimentalRestProperty and | ||
* so there is no "renaming" occurring here. | ||
* Properties using shorthand syntax and rest elements can not be renamed. | ||
* If the property is computed, we have no idea if a rename is useless or not. | ||
*/ | ||
if (properties[i].computed || !properties[i].key) { | ||
if (property.shorthand || property.type === "RestElement" || property.computed) { | ||
continue; | ||
} | ||
|
||
if (properties[i].key.type === "Identifier" && properties[i].key.name === properties[i].value.name || | ||
properties[i].key.type === "Literal" && properties[i].key.value === properties[i].value.name) { | ||
reportError(properties[i], properties[i].key, properties[i].value, "Destructuring assignment"); | ||
const key = (property.key.type === "Identifier" && property.key.name) || (property.key.type === "Literal" && property.key.value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some change here seems to break! Failing line: https://github.com/nuxt/nuxt.js/blob/13331a02b4d5ef37932f42a845ca1754fb834243/packages/webpack/src/builder.js#L169 (just informational! I'll try to reproduce it better and make PR or Issue) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please track this issue: #12335 . |
||
const renamedKey = property.value.type === "AssignmentPattern" ? property.value.left.name : property.value.name; | ||
|
||
if (key === renamedKey) { | ||
reportError(property, property.key, property.value, "Destructuring assignment"); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are already tests covering the
property.type === "RestElement"
change on this line.