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
Refactor declaration-block-no-duplicate-properties #6545
Refactor declaration-block-no-duplicate-properties #6545
Conversation
|
} | ||
|
||
if (!important && duplicateImportant) { | ||
decl.remove(); |
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.
stylistic
I prefer the form return fn();
.
ditto for l183, l108, etc
} else { | ||
removePreviousDuplicate(decls, lowerProp); | ||
} | ||
if (!important && duplicateImportant) { |
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.
minor
put !important && duplicateImportant
in a const
(being reused at l145)
|
||
if (ignoreDiffValues || ignorePrefixlessSameValues) { | ||
// fails if duplicates are not consecutive | ||
if (indexDuplicate !== decls.length - 1) { |
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.
suggestion
put indexDuplicate !== decls.length - 1
in a const foo (dunno about the name but you should)
and use !foo
at l178
perf verify that it's at least marginally equivalent |
|
if (ignorePrefixlessSameValues) { | ||
// fails if values of consecutive, unprefixed duplicates are equal | ||
if (vendor.unprefixed(value) !== vendor.unprefixed(duplicateValue)) { | ||
if (!context.fix) { |
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.
It seems like you have
if (!context.fix) {
return report({
message: messages.rejected(prop),
node: decl,
result,
ruleName,
word: prop,
});
}
if (duplicateIsMoreImportant) {
return decl.remove();
}
return duplicateDecl.remove();
twice.
What about
// false if values of consecutive, unprefixed duplicates are equal
const foo = vendor.unprefixed(value) !== vendor.unprefixed(duplicateValue;
const bar = ignorePrefixlessSameValues && foo;
if (!duplicatesAreConsecutive || bar) {
…
}
at line 107?
You are correct you can reuse
at line l113 and l151. |
} else { | ||
removePreviousDuplicate(decls, lowerProp); | ||
} | ||
if (!duplicateDecl) return; |
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.
either this one is not necessary or the one at l97 is
i.e. if we reach l123 duplicateDecl
is true
because it's a const
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.
at l97 you have
if (!duplicateDecl) {
return;
}
the l123 check is called at l133 and l157 which are after l97; since you chose to use a function declaration it's being hoisted hence it could have been called before l97.
It seems to me that duplicateDecl
cannot be undefined
at that stage because Boolean(undefined) === false
hence it would have returned early.
If it's a type check problem you can ask @ybiquitous for help.
e.g. a /** @type … */
comment may be necessary
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.
To remove duplicate if (!duplicateDecl) return;
, we need to convert function fixOrReport
to const fixOrReport
. Because using function
causes hoisting.
- function fixOrReport() {
+ const fixOrReport = () => {
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.
Thank you. LGTM 👍🏼
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.
@fpetrakov Thank you for the refactor. It reads well.
Glad to help 🙌 |
Closes #6544
No, it's self-explanatory.