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

feat(lint): add prettier formatter to assert LESS files whitespaces #2611

Merged
merged 16 commits into from Dec 21, 2022

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented Dec 15, 2022

Compared to Stylelint, Prettier is very simple tool and I am quite supprised Stylelint is deprecating the whitespace rules in favor of Prettier. For LESS it seems ok, for JS, we should never enable Prettier as formatting is part of a code and improves readability.

As Prettier is an opinionated formatter instead of an linter, we need to satisfy it everywhere without exceptions.

When I was crafting this PR, I found several Prettier issues and proposed changes to Prettier:

In this PR, these changes are contained and Prettier is patched before it is run. Once the changes are merged in prettier and stable release is made, they can be removed.

This PR fixes minor whitespaces unfixed/undetected in GH-2610.

And also asserts:

Prettier has no built in support to dump the diff - prettier/prettier#6885 - so we dump it in the CI using git.

@mvorisek mvorisek changed the title Add Prettier linter to assert LESS files whitespaces Add Prettier formatter to assert LESS files whitespaces Dec 15, 2022
@mvorisek mvorisek force-pushed the ci_less_ws_using_prettier branch 2 times, most recently from d47a5c4 to d368a93 Compare December 15, 2022 22:52
src/semantic.less Outdated Show resolved Hide resolved
@mvorisek mvorisek force-pushed the ci_less_ws_using_prettier branch 13 times, most recently from 342bde2 to d302347 Compare December 18, 2022 15:17
@mvorisek mvorisek marked this pull request as ready for review December 18, 2022 15:25
@mvorisek
Copy link
Contributor Author

PR is done, Prettier fixes with patches looks reasonable. Compiled semantic.min.css is binary the same as before this PR.

@lubber-de
Copy link
Member

Please resolve conflicts

@lubber-de
Copy link
Member

In this PR, these changes are contained and Prettier is patched before it is run. Once the changes are merged in prettier and stable release is made, they can be removed.

Seriously? This is really hacky. You want to use a tool, which does not do what we need... Why not fork prettier.io instead and use that?

@lubber-de
Copy link
Member

So please fork the Prettier under fomantic GH org and apply there all 4 patches.

I sent you an invite for Admin access to https://github.com/fomantic/prettier, so you can freely maintain it 🙂

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@mvorisek mvorisek force-pushed the ci_less_ws_using_prettier branch 2 times, most recently from 7fb93b0 to c63b74d Compare December 21, 2022 17:56
.github/workflows/ci.yml Outdated Show resolved Hide resolved
Copy link
Member

@lubber-de lubber-de left a comment

Choose a reason for hiding this comment

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

Finally LGTM 👍🏼

I would like to thank you very much for this and especially for your patience and understanding for all the (critical) feedback i gave 😉

@lubber-de lubber-de changed the title Add Prettier formatter to assert LESS files whitespaces feat(lint): add prettier formatter to assert LESS files whitespaces Dec 21, 2022
@lubber-de lubber-de merged commit b3dc749 into fomantic:develop Dec 21, 2022
@lubber-de lubber-de added lang/css Anything involving CSS type/ci Anything related to CI/CD type/lint eslint / stylelint related changes only and removed state/on-hold Issues and pull requests which are on hold for any reason labels Dec 21, 2022
@lubber-de lubber-de added this to the 2.9.1 milestone Dec 21, 2022
@mvorisek mvorisek deleted the ci_less_ws_using_prettier branch December 21, 2022 21:59
@lubber-de
Copy link
Member

@mvorisek It seems prettier has merged all of your PRs 🙂
They havent published a new version yet, but once they do, is everything covered what we need so we can switch back to the original prettier repo and remove the fork again?

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 6, 2023

@lubber-de all except the one which adds new lines when comma is present - fomantic/prettier@d9c5a04 and fomantic/prettier@ca814b7

I can try to propose it to Prettier as well, but I am not sure if it will be accepted

@lubber-de
Copy link
Member

I can try to propose it to Prettier as well, but I am not sure if it will be accepted

Yes, please 😊 they seem to trust you

@mvorisek
Copy link
Contributor Author

mvorisek commented Jan 6, 2023

I have about 1500 contributions / year in GH. But it is not only about personal credit, the previous PRs were bugfixes, this one is feature request about styling. AFAK such FR should not be accepted, I will do my best to stress the importance of increased readability with a an example, but I cannot promise anything.

@mvorisek
Copy link
Contributor Author

@lubber-de I have crafter 14208 prettier PR. Currently we enforce NL based on the original presence - fomantic/prettier@edb343f - but such behaviour is not possible in prettier offcially (it rebuilds AST into one stable format).

So the 14208 prettier PR is designed to enforce line break in all CSS values when comma is present. See https://github.com/mvorisek/prettier/commit/da28053ff997aa259ee41046a7377bcfc35a7ee9 . Is such format ok with you or do you have any idea of better prettier formatting?

@lubber-de
Copy link
Member

lubber-de commented Jan 20, 2023

TBH, no, or, "depends". Forcing a NL always will bloat the view for example in site.variables where the unicode ranges for the Lato font is given. -> comma list in one line is ok
In situations like multiple box shadows a NL is nicer for the designer to compare -> NL is ok

There still exists "prettier-ignore", but i fear we would make use of that too often in all the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang/css Anything involving CSS type/ci Anything related to CI/CD type/lint eslint / stylelint related changes only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants