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 stylelint #11767

Closed
wants to merge 5 commits into from
Closed

Add stylelint #11767

wants to merge 5 commits into from

Conversation

simison
Copy link
Member

@simison simison commented Mar 29, 2019

Adds linting for SCSS files, using WordPress core ruleset.

TODO in follow up PRs:

  • Add this linter to pre-commit-hook
  • Actually fix the errors. yarn reformat-files handles a lot of them,
  • Fail on CI lint task on errors

Changes proposed in this Pull Request:

  • Adds Stylelint setup and a couple package.json scripts to use it.

Testing instructions:

  • yarn lint:scss / yarn lint
  • yarn reformat-files:scss / yarn reformat-files

Proposed changelog entry for your changes:

@simison simison requested a review from a team March 29, 2019 16:22
@ockham
Copy link
Contributor

ockham commented Mar 29, 2019

Hmm, yarn lint:css doesn't complain about the undefined var in jetpack-plugin-sidebar.scss though (which was kinda the point of this, wasn't it? (see pMz3w-9H7-p2#comment-69629)

Also, let's ideally include Calypso's .stylelintrc in the @automattic/calypso-build package instead of copy-pasting it here 😬

@jetpackbot
Copy link
Collaborator

jetpackbot commented Mar 29, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: April 2, 2019.
Scheduled code freeze: March 26, 2019

Generated by 🚫 dangerJS against f6eaeb5

@simison
Copy link
Member Author

simison commented Mar 29, 2019

Also, let's ideally include Calypso's .stylelintrc in the @automattic/calypso-build package instead of copy-pasting it here 😬

I was thinking it should be a separate package just like for eslint?

Here I copypasted it just for the proof of concept.

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello simison! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D27105-code before merging this PR. Thank you!

@jetpackbot
Copy link
Collaborator

jetpackbot commented Apr 18, 2019

Warnings
⚠️ The Privacy section is missing for this PR. Please specify whether this PR includes any changes to data or privacy.

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against 523a342

@simison
Copy link
Member Author

simison commented Apr 18, 2019

@Automattic/jetpack-crew a question: which ruleset should Jetpack follow for linting scss files — stylelint-config-wordpress or the one from Calypso?

You can see the difference roughly by first running yarn reformat-files:css with current setup, and then do the same after you copy Calypso stylelint file to .stylelintrc.json.

I didn't dig deep yet to differences but brackets spacing seems different at least:

  • darken($alert-green, 14%); WordPress
  • darken( $alert-green, 14% ); Calypso

There's no big difference in maintenance from Jetpack point of view — both would be external configs Jetpack would just consume and use. I think it's also possible to layer them by using WordPress as a base and Calypso on top of it.

@simison simison added the Build label Apr 18, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello simison! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D33725-code before merging this PR. Thank you!

@simison simison added [Status] Needs Review This PR is ready for review. and removed DO NOT MERGE don't merge it! [Status] In Progress labels Oct 8, 2019
@simison
Copy link
Member Author

simison commented Oct 8, 2019

@jeherve @kraftbj do you have an opinion which Stylelint config to use for Jetpack? I would suggest sticking to the core one.

See #11767 (comment)

@simison simison added this to the 7.9 milestone Oct 8, 2019
@matticbot
Copy link
Contributor

simison, Your synced wpcom patch D33725-code has been updated.

1 similar comment
@matticbot
Copy link
Contributor

simison, Your synced wpcom patch D33725-code has been updated.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

Sorry, somehow I missed this PR before. I like it!

I would suggest sticking to the core one.

I would vote for sticking to the Core one too.

package.json Outdated
@@ -192,13 +196,16 @@
"mockery": "2.1.0",
"nock": "10.0.6",
"node-wp-i18n": "1.2.3",
"npm-run-all": "4.1.5",
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to introduce a new dependency here, instead of just chaining the different actions?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can totally just chain them but it should be faster to run in CI in parallel. How much faster — I'd have to check. :-)

I wonder if it would make sense to add php:lint script to the same run? (That would be good for another PR anyway)

Copy link
Member

@jeherve jeherve Oct 9, 2019

Choose a reason for hiding this comment

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

Yeah, if it is faster we should probably start using it everywhere we can :)
But we can do that in another PR indeed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'd like to see some exploration adding parallelism to build steps for instance.

Copy link
Member

Choose a reason for hiding this comment

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

Noting that we started using concurrently for some of our tasks; maybe we could use it here too?

Copy link
Member Author

@simison simison Jan 15, 2021

Choose a reason for hiding this comment

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

Oh ye, totes agreed! Feel free to change unless I get to it first.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jeherve switched to concurrently

@matticbot
Copy link
Contributor

simison, Your synced wpcom patch D33725-code has been updated.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This works for me. Tests are failing right now though:
https://travis-ci.org/Automattic/jetpack/jobs/596002607

@simison
Copy link
Member Author

simison commented Oct 10, 2019

Yeah, that's a weird one. I don't understand why and I was suspecting it was because of how React version got resolved from [email protected] (hence #13705) but I'm not sure anymore.

Full error:

ERROR in Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
    1. You might have mismatching versions of React and the renderer (such as React DOM)
    2. You might be breaking the Rules of Hooks
    3. You might have more than one copy of React in the same app
    See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
        at invariant (webpack:///./node_modules/@wordpress/data/node_modules/react/cjs/react.development.js?:88:15)
        at resolveDispatcher (webpack:///./node_modules/@wordpress/data/node_modules/react/cjs/react.development.js?:1436:28)
        at useContext (webpack:///./node_modules/@wordpress/data/node_modules/react/cjs/react.development.js?:1441:20)
        at useRegistry (webpack:///./node_modules/@wordpress/data/build-module/components/registry-provider/use-registry.js?:55:79)
        at useDispatchWithMap (webpack:///./node_modules/@wordpress/data/build-module/components/use-dispatch/use-dispatch-with-map.js?:50:97)
        at eval (webpack:///./node_modules/@wordpress/data/build-module/components/with-dispatch/index.js?:105:99)
        at processChild (webpack:///./node_modules/react-dom/cjs/react-dom-server.browser.development.js?:2887:14)
        at resolve (webpack:///./node_modules/react-dom/cjs/react-dom-server.browser.development.js?:2811:5)
        at ReactDOMServerRenderer.render (webpack:///./node_modules/react-dom/cjs/react-dom-server.browser.development.js?:3201:22)
        at ReactDOMServerRenderer.read (webpack:///./node_modules/react-dom/cjs/react-dom-server.browser.development.js?:3160:29)
    Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js??ref--5-1!node_modules/postcss-loader/src/index.js??ref--5-2!node_modules/@automattic/calypso-build/node_modules/sass-loader/lib/loader.js??ref--5-3!extensions/shared/components/block-nudge/style.scss:
        Entrypoint mini-css-extract-plugin = *
           2 modules
    Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js??ref--5-1!node_modules/postcss-loader/src/index.js??ref--5-2!node_modules/@automattic/calypso-build/node_modules/sass-loader/lib/loader.js??ref--5-3!extensions/shared/components/style.scss:
        Entrypoint mini-css-extract-plugin = *
           2 modules
    Child mini-css-extract-plugin node_modules/css-loader/dist/cjs.js??ref--5-1!node_modules/postcss-loader/src/index.js??ref--5-2!node_modules/@automattic/calypso-build/node_modules/sass-loader/lib/loader.js??ref--5-3!extensions/shared/components/upgrade-nudge/style.scss:
        Entrypoint mini-css-extract-plugin = *
           2 modules

@kraftbj
Copy link
Contributor

kraftbj commented Oct 12, 2019

Late to the party, but agreed with sticking with Core.

@stale
Copy link

stale bot commented Aug 24, 2020

This PR has been marked as stale. This happened because:

  • It has been inactive in the past 3 months.
  • It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.

No further action is needed. But it's worth checking if this PR has clear testing instructions, is it up to date with master, and it is still valid. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

@stale stale bot added the [Status] Stale label Aug 24, 2020
@stale stale bot removed the [Status] Stale label Jan 15, 2021
@simison simison added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Jan 15, 2021
@simison
Copy link
Member Author

simison commented Jan 15, 2021

@jeherve looks like this didn't get merged last time it was ready — I rebased it to new folder structure and switched to new core package.

Ready to go on my behalf! :-)

@jeherve jeherve added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it and removed [Status] Needs Review This PR is ready for review. labels Jan 15, 2021
@simison simison added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jan 27, 2021
@simison
Copy link
Member Author

simison commented Jan 27, 2021

@jeherve rebased. I've switched to concurrently earlier: #11767 (comment)

Let's get this long timer in? :-)

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Seems ok as far as it goes. A few nitpicks inline.

But if we're going to add this, we should fully add it. There's not a whole lot of point in adding linting if no one pays any attention to it.

  • The pre-commit hook (tools/git-hooks/pre-commit-hook.js) should probably run it like it does phpcs and eslint.
  • CI should run it too.
  • And both of the above would likely want a tool like our eslint-changed and logic like our excludelists so as to not bomb everyone with 10281 warnings all the time. Or else someone needs to fix the 10281 warnings it currently reports 😉.

Is that on anyone's radar?

"reformat-files": "yarn prettier --ignore-path .eslintignore --write \"**/*.{js,jsx,json}\"",
"reformat-files": "yarn concurrently 'yarn:reformat-files:*'",
"reformat-files:js": "yarn prettier --ignore-path .eslintignore --write \"**/*.{js,jsx,json}\"",
"reformat-files:scss": "yarn lint:scss --fix",
Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like a --fix is going to do more than just reformat...

Copy link
Member Author

Choose a reason for hiding this comment

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

Neither Prettier nor Stylelint changes actual functionality so I think it's exactly reformatting, but I'm no native speaker. :-)

The command was to follow existing convention from Calypso repo.

Not a biggie to use something else here, tho!

@@ -59,14 +59,18 @@
"docker:update-core-unit-tests": "yarn docker:compose exec wordpress svn up /tmp/wordpress-develop/tests/phpunit/data/ /tmp/wordpress-develop/tests/phpunit/includes",
"docker:wp": "yarn docker:compose exec wordpress wp --allow-root --path=/var/www/html/",
"install-if-deps-outdated": "yarn install --check-files --production=false --frozen-lockfile",
"lint": "yarn lint-file .",
"lint": "yarn concurrently 'yarn:lint:*'",
Copy link
Contributor

Choose a reason for hiding this comment

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

The resulting output isn't very human-friendly. In a few places it even has lines from the different linters interleaved.

@kraftbj kraftbj added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Jan 27, 2021
@simison
Copy link
Member Author

simison commented Dec 19, 2022

This is pretty old and Jetpack structure is way different these days. I'll close and anyone feel free to re-open/pick code and continue.

@simison simison closed this Dec 19, 2022
@simison simison deleted the add/stylelint branch December 19, 2022 09:37
@github-actions github-actions bot removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants