Problem/Motivation
Stylelint updated to 15 #3344087: Update Stylelint and Prettier for Drupal 10.1 and use Prettier for formatting PostCSS
But seems we ignore its `Significant changes`:
https://stylelint.io/migration-guide/to-15#significant-changes
Now stylelint only cares about `Code-quality rules` and never cares about `Formatting rules`
That formatting rules removed from our base config
`Removed: 64 rules deprecated in stylelint@15.0.0. For details, see the migration guide.`
https://github.com/stylelint/stylelint-config-standard/blob/main/CHANGEL...
More info: https://prettier.io/docs/en/comparison
Steps to reproduce
Put any bad formatted postcss into any core pipeline and it pass all checkings
Or open claro/css/components/tables.pcss.css and just save file

Proposed resolution
Use https://github.com/prettier/stylelint-prettier
3 MRs here
1. `proof-of-failures ` explains that after upgrade we don't have formatting errors reported. I downgraded stylelint and stylelintconfig and got pipeline reports about formatting errors which younger than 14-15 stylelint upgrade (UPD + new max-line-length recently removed)
2. `success-on-anything` explains why this ticket is major. Right now any unformatted postcss can appears in core without pipeline reports
3. `3409048-postcss-file-formatting` Fix MR. With stylelint-prettier.
One commit for review config fixes. And other to check what formatter errors it fixes.
Criteria for adding dependencies
1. Maintainership of the package:
Well maintained https://github.com/prettier/stylelint-prettier/activity by existing in core prettier https://github.com/prettier
2. Security policies of the package:
stylelint-prettier has not any reported security issues to date. The library is well documented.
3. Expected release and support cycles:
Looks like 6 month between 2 latest versions.
4. Code quality:
The codebase of stylelint-prettier is well written, well documented.
5. Other dependencies it would add:
stylelint-prettier has one dependency from same maintainer https://github.com/prettier/prettier-linter-helpers and it is already presented in our yarn.lock
| Comment | File | Size | Author |
|---|
Issue fork drupal-3409048
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
finnsky commentedAdded just prettier command
And runned it.
Got lot of formatting errors
About
https://www.npmjs.com/package/stylelint-prettier
It seems not easy to configure fast. Also version 4 should be used.
Comment #4
andypostComment #5
andypostActionable title
Comment #6
bnjmnmThis is reported as a regression caused by updating Stylelint to 15, which was committed on July 17, 2023.
I spot-checked the first three files in the merge request, and they are change code that was in place prior to the Stylelint changes on July 17, 2023, so it looks like this MR is making changes and enforcing rules that were enforced by any Stylelint config in core. Some of these changes look nice, but they'd need to be proposed as changes to the configured standard, as they do not appear to be regressions.
Also worth noting, in Stylelint's "Significant changes" page for version 15 it points out
. So while it is true these rules are deprecated and we should prepare for their removal, they should currently work as they did in earlier versions.
Comment #7
finnsky commentedThank you for review. I marked it as major because any bad formatting can get into core without pipeline report
Comment #8
finnsky commentedComment #9
longwavePrettier is definitely more strict and opinionated than Stylelint. As #6 says the bad formatting was previously there in many cases and Stylelint did not consider it a problem. While we now use Prettier for formatting PostCSS output, I don't think we ever applied the Prettier rules to unprocessed module CSS or the source *.pcss.css files.
Comment #10
longwaveIf we *are* going to do this we should change the Prettier command in package.json:
to
(there is also module CSS that is never run through PostCSS, as well as *.pcss.css files)
Comment #11
longwavePreparation for Stylelint 16 is happening in #3407211: [PP-upstream] Update stylelint(-config-standard) to latest versions (major bump)
Comment #12
longwaveThere is also ongoing work to update the CSS coding standards and perhaps an option is to adopt Prettier for opinionated formatting?
Comment #14
finnsky commentedAdded proof of regressions MR
It shows that stylelint 15 doesn't check formatting anymore.
Stylelint pipeline task fails with formatting errors
we got 15 stylelint here:
https://www.drupal.org/project/drupal/issues/3344087#comment-15028211
and all that pipeline failures younger
Comment #15
finnsky commentedAnd the funniest thing here that 2 of 9 formatting errors committed by me :)
Comment #16
finnsky commentedComment #18
finnsky commentedAnd one more merge requests about any formatting errors can get into core
Seems it fails. but obviously not in place where we expect it.
Comment #19
finnsky commentedComment #20
finnsky commentedUpdated first MR 3409048-postcss-file-formatting with https://github.com/prettier/stylelint-prettier
Now it reports formatting errors.
It catched all that new 14-15 update formatting problems.
Ans some new. But thats fair imo. Code looks better.
Comment #21
finnsky commentedI think we may move with `3409048-postcss-file-formatting` MR with lint fixed
It is in fact does same work and postcss compilation prettier:
Comment #22
finnsky commentedComment #23
finnsky commentedComment #24
finnsky commentedComment #25
finnsky commentedComment #26
finnsky commentedRebased it. Mostly sure that results will be same.
Comment #27
finnsky commentedOn proof-of-failures MR we got new `max-line-length`, it was recently removed:
https://git.drupalcode.org/project/drupal/-/commit/fafc0e753deb811afb113...
but other reports are actual
Comment #28
finnsky commentedComment #29
finnsky commentedReverted max-line-length in proof of failures. To display only actual errors.
Comment #30
smustgrave commentedGuess this needs frontend manager to pick which proposal
Comment #31
finnsky commentedI rebased and pushed formatted css in new commit:
So config fix:
https://git.drupalcode.org/project/drupal/-/merge_requests/5827/diffs?co...
Formatter fixes:
https://git.drupalcode.org/project/drupal/-/merge_requests/5827/diffs?co...
They look fair. Please review.
Comment #32
finnsky commentedComment #33
longwaveOverall I think we should just do this as it is only whitespace and quoting fixes, and makes all our CSS more consistent - if our compiled CSS uses prettier then why shouldn't our base CSS use it too?
However I think we can improve some comment placements, so added some feedback.
Comment #34
finnsky commentedThank you for review.
This was result of automated fix.
OK. Let's add some manual formatting
Comment #35
finnsky commentedFixed feedbacks. Please review!
Comment #36
bnjmnmSpotted a few things in the MR I'd like updated, but hopefully nothing major. Overall this looks like a good addition by adding CSS support to the prettier functionality we're already accustomed to with our JS files, and the formatting changes are not too jarring.
Comment #37
finnsky commentedComment #38
finnsky commentedComment #39
finnsky commentedSpellcheck issue happened because of https://www.drupal.org/project/drupal/issues/3401988
Now all fine, review still needed.
Comment #40
andypostBlocker resolved, follow up to reuse
.prettierrcComment #43
bnjmnmAdded feedback to the MR. It is all trivial other than one thing, and even the non-trivial one shouldn't be too demanding. Overall looks good and looking forward to rtbcing.
Comment #44
finnsky commentedI’ve fixed common .prettierrc for both compile and lint.
But about comments in media queries i think they are out of scope requests in current bugfix ticket.
I’ve added approach when we will not have blank lines and which will work fine with postcss-custom-media
https://git.drupalcode.org/project/drupal/-/merge_requests/5827/diffs?co...
if it is acceptable i can manage it globally. otherwise move it to follow up. thank you
Comment #45
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #46
finnsky commentedThis bot too fast ;)
It still needs review. One branch here for failures example.
Comment #47
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #48
finnsky commentedComment #49
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #50
longwaveComment #51
finnsky commentedThank you! This robot was stronger than me ;)
Comment #52
smustgrave commentedAppears to be some open threads if they can closed or marked complete.
Can the follow up mentioned in #40 be added also
MR appears to need a rebases.
Moving to NW for those 3 items.
Been using that config standard on most of my projects and will say like it a lot :)
Comment #53
finnsky commentedre #52
#40 fixed already.
Comment #56
finnsky commentedI think we need to leave the current MR. In which all the main problems are solved and autofix is launched.
Positioning comments in each individual weird CSS is clearly outside of this task.
The problem with this task is the lost config for the css format.
So we should add this as is to https://git.drupalcode.org/project/drupal/-/merge_requests/7024/diffs
And if necessary, add subsequent tasks.
Comment #57
finnsky commentedComment #58
finnsky commentedRebased after yarn update. Please review.
Comment #59
smustgrave commentedIt's a +1 for me but will leave in review for @bnjmnm as the frontend framework manager.
Comment #60
bnjmnmRe the media query comments #56
I think it belongs in the scope of this issue as the formatting changes implemented by this issue changes the position of these comments. I think having them on the same line or above a media query is similarly useful, having them underneath the MQ declaration makes them less so. If there are any specific ones that are particularly difficult to reposition, removing is also OK.
So for > me < to provide FEFM signoff, I want to see those media query PX comments positioned above. That said, if another FEFM is fine with it I will not protest that decision. I'm not comfortable approving as-is, but if one of my peers is that's fine by me.
Comment #61
finnsky commented@bnjmnm what about follow up issue?
Because here we are fixing a bug.
Right now, unformatted css is getting into the core.
And with the current rate of reviews, this is becoming almost impossible to fix. Because this commit is completely rebase unfriendly
Comment #62
finnsky commentedI've rebased. I think we need to fix this formatting bug.
Comment #63
finnsky commented59 problems (59 errors, 0 warnings)From new navigation module. Before i used force push in one commit. Here i gonna add it as example.
https://git.drupalcode.org/project/drupal/-/merge_requests/7024/diffs?co...
Comment #64
nod_about #60 given that this is an automated MR, I'd be reluctant to introduce manual changes on top of it. I did it for the once() replace patch and don't recommend it because of the difficulty to reroll. IMO The comments were placed awkwardly to begin with, so it make sense that an automated fix would place them not where we want.
Given that this is an automated patch, I'm fine with the comments in this issue but a follow-up needs to be created to move them either above or before the opening bracket.
Since we'll use prettier for css, we might want to enable css file rewrites in the prettier command of our package.json. Ok with a follow-up for that since we'll need to exclude a bunch of files/directories from this auto-formatting and it'd make all this longer.
Comment #65
nod_I'm committing a bunch of issues with css changes to make the RTBC queue go down, so we'll have to reroll that just before commit.
Comment #67
alexpottI think we should address #10 from @longwave in a follow-up as the command
yarn prettiercurrently makes changes even if we are on HEAD. Opened #3444587: Add CSS to prettier command and fix core/misc/jquery.form.js to be ignoredComment #68
alexpottCommitted 1fbf9f5 and pushed to 11.x. Thanks!
Needs backport to 10.4.x and probably 10.3.x too.
Comment #73
alexpottCreated an MR against 10.4.x and ran the fixer...
Comment #75
smustgrave commentedDidn't know we had a 10.4 branch going now. But rerun for it seems fine
btw is a follow up still needed mentioned in #30 or framework manager approval since it was committed to 11.x already?
Comment #76
alexpott@smustgrave - @nod_, a frontend framework manager rtbc'd this issue in #65
Committed and pushed 5c9cc42046 to 10.4.x and 306ab17ec7 to 10.3.x. Thanks!
Backported to 10.3.x as major bug fix.