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

Issue fork drupal-3409048

Command icon 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

finnsky created an issue. See original summary.

finnsky’s picture

Status: Active » Needs work

Added 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.

andypost’s picture

andypost’s picture

Title: PostCSS file formatting » Fix broken PostCSS file formatting after stylelint upgrade

Actionable title

bnjmnm’s picture

This 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

The deprecated rules will still work in this release (with a deprecation warning). In preparation for the next major release, when we'll remove the rules from Stylelint, we suggest:

. 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.

finnsky’s picture

Thank you for review. I marked it as major because any bad formatting can get into core without pipeline report

finnsky’s picture

Title: Fix broken PostCSS file formatting after stylelint upgrade » Configure postcss formatting after stylelint update
longwave’s picture

Prettier 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.

longwave’s picture

If we *are* going to do this we should change the Prettier command in package.json:

    "prettier": "prettier --write \"./**/*.js\"",

to

    "prettier": "prettier --write \"./**/*.css\" \"./**/*.js\"",

(there is also module CSS that is never run through PostCSS, as well as *.pcss.css files)

longwave’s picture

longwave’s picture

There is also ongoing work to update the CSS coding standards and perhaps an option is to adopt Prettier for opinionated formatting?

finnsky’s picture

Added 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

finnsky’s picture

And the funniest thing here that 2 of 9 formatting errors committed by me :)

finnsky’s picture

Assigned: finnsky » Unassigned

finnsky’s picture

And one more merge requests about any formatting errors can get into core

Seems it fails. but obviously not in place where we expect it.

finnsky’s picture

Issue summary: View changes
finnsky’s picture

Status: Needs work » Needs review

Updated 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.

finnsky’s picture

Issue summary: View changes
StatusFileSize
new427.27 KB

I think we may move with `3409048-postcss-file-formatting` MR with lint fixed

It is in fact does same work and postcss compilation prettier:

finnsky’s picture

Issue summary: View changes
finnsky’s picture

Issue summary: View changes
finnsky’s picture

Title: Configure postcss formatting after stylelint update » Configure postcss formatting after stylelint and stylelint-config-standard update
finnsky’s picture

Issue summary: View changes
finnsky’s picture

Rebased it. Mostly sure that results will be same.

finnsky’s picture

On 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

finnsky’s picture

Issue summary: View changes
finnsky’s picture

Reverted max-line-length in proof of failures. To display only actual errors.

smustgrave’s picture

Guess this needs frontend manager to pick which proposal

finnsky’s picture

I 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.

finnsky’s picture

Issue summary: View changes
longwave’s picture

Status: Needs review » Needs work

Overall 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.

finnsky’s picture

Thank you for review.
This was result of automated fix.
OK. Let's add some manual formatting

finnsky’s picture

Status: Needs work » Needs review

Fixed feedbacks. Please review!

bnjmnm’s picture

Status: Needs review » Needs work

Spotted 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.

finnsky’s picture

Issue summary: View changes
finnsky’s picture

Status: Needs work » Needs review
finnsky’s picture

Spellcheck issue happened because of https://www.drupal.org/project/drupal/issues/3401988

Now all fine, review still needed.

andypost’s picture

Blocker resolved, follow up to reuse .prettierrc

finnsky changed the visibility of the branch 11.x to hidden.

finnsky changed the visibility of the branch 11.x to hidden.

bnjmnm’s picture

Status: Needs review » Needs work

Added 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.

finnsky’s picture

Status: Needs work » Needs review

I’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

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new59.43 KB

The 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.

finnsky’s picture

Status: Needs work » Needs review

This bot too fast ;)

It still needs review. One branch here for failures example.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new59.43 KB

The 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.

finnsky’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new59.43 KB

The 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.

longwave’s picture

Status: Needs work » Needs review
Issue tags: +no-needs-review-bot
finnsky’s picture

Thank you! This robot was stronger than me ;)

smustgrave’s picture

Status: Needs review » Needs work

Appears 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 :)

finnsky’s picture

re #52

#40 fixed already.

finnsky changed the visibility of the branch 3409048-postcss-file-formatting to hidden.

finnsky’s picture

Status: Needs work » Needs review

I 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.

finnsky’s picture

Issue summary: View changes
StatusFileSize
new256.3 KB
finnsky’s picture

Rebased after yarn update. Please review.

smustgrave’s picture

It's a +1 for me but will leave in review for @bnjmnm as the frontend framework manager.

bnjmnm’s picture

Re the media query comments #56

Positioning comments in each individual weird CSS is clearly outside of this task.

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.

finnsky’s picture

@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

finnsky’s picture

I've rebased. I think we need to fix this formatting bug.

finnsky’s picture

59 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...

nod_’s picture

Status: Needs review » Reviewed & tested by the community

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.

nod_’s picture

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.

alexpott made their first commit to this issue’s fork.

alexpott’s picture

I think we should address #10 from @longwave in a follow-up as the command yarn prettier currently makes changes even if we are on HEAD. Opened #3444587: Add CSS to prettier command and fix core/misc/jquery.form.js to be ignored

alexpott’s picture

Version: 11.x-dev » 10.4.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 1fbf9f5 and pushed to 11.x. Thanks!

Needs backport to 10.4.x and probably 10.3.x too.

  • alexpott committed 1fbf9f5d on 11.x
    Issue #3409048 by finnsky, alexpott, longwave, bnjmnm, andypost, nod_:...

alexpott changed the visibility of the branch 3409048-config-and-autofix to hidden.

alexpott changed the visibility of the branch proof-of-failures to hidden.

alexpott changed the visibility of the branch success-on-anything to hidden.

alexpott’s picture

Status: Patch (to be ported) » Needs review

Created an MR against 10.4.x and ran the fixer...

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Didn'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?

alexpott’s picture

Version: 10.4.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs frontend framework manager review

@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.

  • alexpott committed 306ab17e on 10.3.x
    Issue #3409048 by finnsky, alexpott, longwave, bnjmnm, andypost, nod_:...

  • alexpott committed 5c9cc420 on 10.4.x
    Issue #3409048 by finnsky, alexpott, longwave, bnjmnm, andypost, nod_:...

  • alexpott committed 1fbf9f5d on 11.0.x
    Issue #3409048 by finnsky, alexpott, longwave, bnjmnm, andypost, nod_:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.