Skip to content
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 canMerge in postcss-merge-longhand #634

Merged
merged 1 commit into from Oct 17, 2018

Conversation

jordrake
Copy link
Contributor

Increased the test coverage following the previous PR. I have done a small refactor to canMerge and canExplode to avoid duplication.

Not sure about the inclusion of 'none', I think it should be there but existing tests fail when I try to add it.

@jordrake
Copy link
Contributor Author

Actually this logic is not parity with the old one and will correct. Ignore for now!

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for helping ⭐

fixture: 'h1{box-bottom:10px;box-top:initial;box-left:20px}',
expected: 'h1{box-bottom:10px;box-top:initial;box-left:20px}',
fixture: 'h1{box-bottom:10px;box-top:initial;box-left:20px;box-right:20px}',
expected: 'h1{box-bottom:10px;box-top:initial;box-left:20px;box-right:20px}',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new tests, don't change exist, it is bad practice 👍 This can lead to regressions in unexpected places.

Copy link
Contributor Author

@jordrake jordrake Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are probably duplicates of existing tests (checking for incomplete box props) hence why they did not increase coverage in the previous PR. However I appreciate the caution and have kept them the same but renamed the message to better match the area they are touching. Hope that's OK.

EDIT: In the diff, the old tests now appear above this change.

@coveralls
Copy link

coveralls commented Oct 12, 2018

Coverage Status

Coverage increased (+0.07%) to 99.199% when pulling 3c3102a on jordrake:refactor-can-merge into 857075c on cssnano:master.

@jordrake jordrake force-pushed the refactor-can-merge branch 3 times, most recently from 7b03593 to 8c51720 Compare October 12, 2018 14:10
fixture: 'h1{box-bottom:10px;box-top:initial;box-left:20px;box-right:20px}',
expected: 'h1{box-bottom:10px;box-top:initial;box-left:20px;box-right:20px}',
}, {
message: 'should not merge box props where there is a mix of reserved properties',
Copy link
Contributor Author

@jordrake jordrake Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the initial refactor attempt, this test (would have) failed.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Thanks! Let's wait green CI.

@alexander-akait
Copy link
Member

alexander-akait commented Oct 12, 2018

/cc @jordrake Ready to merge?
/cc @andyjansson

);

test(
'should not explode border with inherit properties',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad copy and paste job!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

if (props.some(hasInherit) && !props.every(hasInherit)) {
return false;
}
function hasIncompleteReservedKeyword (props) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that this change damaged the readability of the function. It was definitely more clear what it did before.

Copy link
Contributor Author

@jordrake jordrake Oct 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Happy to revert this.


export default (prop, includeCustomProps = true) => {
if (includeCustomProps && isCustomProp(prop)) {
return false;
}

return !isInherit(prop) && !isInitial(prop);
return !isReserved(prop);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes inherit and initial "reserved"`?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is a bit vague, this is what this is referred to in other areas of this codebase. Since it's only called once I can just inline the includes and avoid naming this.

@jordrake jordrake force-pushed the refactor-can-merge branch 2 times, most recently from 562a2bc to 5b21145 Compare October 16, 2018 10:02
@alexander-akait alexander-akait merged commit c13f903 into cssnano:master Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants