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

Add autofix to media-feature-range-operator-space-before #3618

Merged

Conversation

ota-meshi
Copy link
Member

Which issue, if any, is this issue related to?

closes #3580

Is there anything in the PR that needs further explanation?

if use the --fix option, to remove whitespace at the end of each line.

ex.

  • option: always

    code:

    @media (width<600px) {}

    fixed:

    @media (width <600px) {}
  • option: never

    code:

    @media (width < 600px) {}

    fixed:

    @media (width< 600px) {}

result,
ruleName
if (fixOperatorIndices.length) {
let params = atRule.raws.params
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see there is no params in raws: http://api.postcss.org/Node.html#raws

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any difference between getting / setting node.params and node.raws.params.raw?
If there is no difference I think it'd be better to use documented parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

node.raws.params.raw to be create if comments get in. In this case, node.params will not contain comment data.
I tried finding but I do not know the existence of the document yet. . .

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Thank you!

? atRule.raws.params.raw
: atRule.params;
fixOperatorIndices
.sort((a, b) => a - b)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd replace .sort((a, b) => a - b).reverse() with .sort((a, b) => b - a).

@@ -26,26 +26,54 @@ const rule = function(expectation) {
}

root.walkAtRules(/^media$/i, atRule => {
const fixOperatorIndices = [];
findMediaOperator(atRule, checkBeforeOperator);
Copy link
Contributor

Choose a reason for hiding this comment

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

The whole process is not very obvious. You declare array -> call findMediaOperator with callback that could be executed several times and that mutates array of indices.
Maybe instead of this you can create a new function that will fix spacing. And you will run this function from checkBeforeOperator.
What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that is good. I will fix it the next time I can work.

@ota-meshi
Copy link
Member Author

@boccob
I changed the content pointed by your review.

@jeddy3 jeddy3 merged commit 9c133b2 into master Sep 6, 2018
@jeddy3 jeddy3 deleted the add-autofix/media-feature-range-operator-space-before branch September 6, 2018 12:54
@jeddy3
Copy link
Member

jeddy3 commented Sep 6, 2018

  • Added: media-feature-range-operator-space-before autofix (#3618).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add autofix to media-feature-range-operator-space-before
4 participants