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

Lint: use @wordpress/stylelint-config preset #66909

Merged
merged 9 commits into from
Sep 1, 2022

Conversation

manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented Aug 24, 2022

Proposed Changes

This PR updates .stylelintrc to use @wordpress/stylelint-config preset and removes certain rules that are already provided by @wordpress/stylelint-config.

Testing Instructions

It is assumed that you use VS Code for testing

  • Ensure that you have the official Stylelint extension installed and active.
  • Checkout this PR
  • Ensure that you have these settings in settings.json (Cmd + Shift + P > Preferences: Open Settings (JSON))
	"stylelint.validate": ["css", "scss", "sass"],
	"[css][scss][sass]": {
		"editor.formatOnSave": false,
		"editor.defaultFormatter": "stylelint.vscode-stylelint"
	},
	"editor.codeActionsOnSave": {
		"source.fixAll.stylelint": true
		// other actions
	},
  • Reload VS Code: Cmd + Shift + P > Developer: Reload Window
  • Open a SCSS file e.g. client/me/security-2fa-initial-setup/style.scss
  • Mess up the formatting e.g. add empty lines, use spaces for indentation, etc.
  • Open problems view (Cmd + Shift + P > Problems: Focus on Problems View)
  • Confirm that you see the problems reported by Stylelint.
  • Save Changes (Cmd + S)
  • Confirm that the file is formatted as expected.

Pre-merge Checklist

Related to #39568

Screenshot 2022-08-24 at 4 40 22 PM

@manzoorwanijk manzoorwanijk added the [Type] Tooling Related to tools, scripts, automation, DevX, etc. label Aug 24, 2022
@manzoorwanijk manzoorwanijk self-assigned this Aug 24, 2022
@manzoorwanijk manzoorwanijk requested a review from a team August 24, 2022 11:01
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 24, 2022
@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

Nice, thanks for looking at this! I think we might need to tweak the rules a bit more. I think we should add these:

"rule-empty-line-before": [ "always", { "ignore": [ "after-comment", "first-nested" ] } ],
"at-rule-empty-line-before": [ "always", { "ignore": [ "after-comment", "first-nested" ] } ],

If you look at a file like apps/editing-toolkit/editing-toolkit-plugin/common/index.scss, you'll see some weird errors until you add the above. (I don't think the above rules conflict with the WordPress style guidelines either, afaik.)

Open to other ideas too

@manzoorwanijk
Copy link
Member Author

I think we might need to tweak the rules a bit more. I think we should add these:

"rule-empty-line-before": [ "always", { "ignore": [ "after-comment", "first-nested" ] } ],
"at-rule-empty-line-before": [ "always", { "ignore": [ "after-comment", "first-nested" ] } ],

I did notice that behavior. I thought maybe we want those empty lines. But yeah, I agree that we should try to minimize the number of lints for now.

I have made the changes. Thank you.

@manzoorwanijk manzoorwanijk requested review from noahtallen and a team August 25, 2022 04:59
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

I'm getting this error when trying to use the yarn run lint:css command:

Error: The "syntax" option is no longer available. You should install an appropriate syntax, e.g. postcss-scss, and use the "customSyntax" option
    at getPostcssResult (/Users/marin/Projects/calypso/node_modules/stylelint/lib/getPostcssResult.js:37:25)
    at lintSource (/Users/marin/Projects/calypso/node_modules/stylelint/lib/lintSource.js:79:20)
    at async /Users/marin/Projects/calypso/node_modules/stylelint/lib/standalone.js:228:27
    at async Promise.all (index 4)
    at async standalone (/Users/marin/Projects/calypso/node_modules/stylelint/lib/standalone.js:267:22)

@manzoorwanijk
Copy link
Member Author

I'm getting this error when trying to use the yarn run lint:css command:

@tyxla Thank you for catching that. It was due to a migration needed after upgrading stylelint to v14. I have added the required config change and it's good now.

@tyxla
Copy link
Member

tyxla commented Aug 26, 2022

Thanks for fixing that @manzoorwanijk! However, there's this warning when running yarn install now:

➤ YN0002: │ stylelint-config-recommended-scss@npm:7.0.0 [676fa] doesn't provide postcss (pdadd3), requested by postcss-scss

and the Unit Tests check appears to be failing because of that as well.

@noahtallen
Copy link
Member

@manzoorwanijk I pushed a commit fixing the peer dependency issues -- these often happen when updating WordPress dependencies and can be a bit tricky to resolve. (Especially since the WordPress dependencies are so inter-dependent, we may have to add multiple peer dependency rules to match the different dependency versions when we don't update them all at the same time.)

@manzoorwanijk
Copy link
Member Author

I pushed a commit fixing the peer dependency issues

Thank you for that @noahtallen

@noahtallen
Copy link
Member

Looking through a few more files, I think we could make some more rule changes. For example, in packages/help-center/src/styles.scss, I see these issues:

  • Indentation is converted to spaces instead of tabs
  • The @import statements at the top get newlines put between them
  • there are some rules about specificity and kebab-case we should double check

I just want to make sure we don't introduce any weird patterns once people start using this and turn auto-fixing on :)

@manzoorwanijk
Copy link
Member Author

Looking through a few more files, I think we could make some more rule changes. For example, in packages/help-center/src/styles.scss, I see these issues:

  • Indentation is converted to spaces instead of tabs
  • The @import statements at the top get newlines put between them
  • there are some rules about specificity and kebab-case we should double check

I just want to make sure we don't introduce any weird patterns once people start using this and turn auto-fixing on :)

@noahtallen the issue was the order of extended configs in extends with subsequent ones overriding the previous ones.

Fixed that along with empty lines issue in imports.

Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

Cool, I think this is good to merge. Thanks for working on it!

@manzoorwanijk manzoorwanijk merged commit 020c342 into trunk Sep 1, 2022
@manzoorwanijk manzoorwanijk deleted the update/stylelint-config branch September 1, 2022 05:02
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Sep 1, 2022
eoigal pushed a commit that referenced this pull request Sep 5, 2022
* Add/update dependencies

* Extend @wordpress/stylelint-config/scss in stylelint config

* yarn dedupe

* Disable empty lines rules

* Fix stylelint CLI usage

* Fix deps

* Resolve peer dependency warnings

* Fix precedence of extended configs

* Fix empty lines rule for imports

Co-authored-by: Noah Allen <noahtallen@gmail.com>
@noahtallen
Copy link
Member

@manzoorwanijk Why did we need to extend "stylelint-config-standard-scss"?

@manzoorwanijk
Copy link
Member Author

Why did we need to extend "stylelint-config-standard-scss"?

Because in v14, stylelint removed the built-in support for custom syntaxes and only supports CSS by default. Now, in order to use SCSS, we need specific config which is provided by "stylelint-config-standard-scss".

More details here https://stylelint.io/migration-guide/to-14/

@simison
Copy link
Member

simison commented Sep 7, 2022

@manzoorwanijk could that be something done/changed in upstream package so that Calypso doesn't need to take that into account when re-using the upstream confirg?

@manzoorwanijk
Copy link
Member Author

could that be something done/changed in upstream package so that Calypso doesn't need to take that into account when re-using the upstream confirg?

I think I didn't realize that @wordpress/stylelint-config extends stylelint-config-recommended-scss which in turn does everything that stylelint-config-standard-scss does. So, it looks like we can simply remove extending stylelint-config-standard-scss.

CC: @noahtallen

@simison
Copy link
Member

simison commented Sep 7, 2022

A good next steps to sort out all the new linting failures would be:

  • Ensure Prettier autoformatting works with the new setup
  • Add easy-to-repeat autoformatter script, feel free to take over Add reformat-files:css script #32351
  • Run and commit fixes, either one big PR or many smaller ones
  • Turn on CI failure on linting errors once we're 0 errors, or if we can't get to it easily, fail CI if the number increases.

Thanks for everyone's work on this! Great to see this taken care finally.

@manzoorwanijk
Copy link
Member Author

A good next steps to sort out all the new linting failures would be:

  • Ensure Prettier autoformatting works with the new setup
  • Add easy-to-repeat autoformatter script, feel free to take over Add reformat-files:css script #32351
  • Run and commit fixes, either one big PR or many smaller ones
  • Turn on CI failure on linting errors once we're 0 errors, or if we can't get to it easily, fail CI if the number increases.

Thanks for everyone's work on this! Great to see this taken care finally.

I think @noahtallen has already started working on it in #67468 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Tooling Related to tools, scripts, automation, DevX, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants