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

[tech debt] Lint Emotion CSS-in-JS #6839

Merged
merged 17 commits into from
Jun 14, 2023
Merged

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Jun 13, 2023

Summary

closes #6477

I strongly recommend following along by commit, but here's the TL;DR:

  • Upgrades stylelint to v15
    • Required to fix a block-no-empty false positive that was otherwise cropping up frequently
    • Also super helpful because v15 removes a bunch of opinionated newline/whitespace rules that Prettier was already handling for us
  • Installs postcss-styled-syntax, a stylelint custom syntax required for parsing CSS-in-JS
  • Sets up our stylelint config with two sets of rules, 1 for our outgoing Sass files, and one specifically for our CSS-in-JS files
  • Fixes multiple lint issues in our various *.style.ts etc files now caught by our linter
    • ⚠️ NOTE: The most impactful one is that we can no longer use // comments in CSS-in-JS - we must use CSS-allowed /* */ comments only. The parser will error otherwise

QA

  • yarn lint passes
  • Open a random *.styles.ts file and break linting on purpose (e.g. add a semicolon to the end of a ${logicalCSS()}; line)
  • Run yarn lint-css-in-js and confirm it flags the new error
  • Run yarn lint-fix and confirm it auto-fixes the error

General checklist

  • CI/all tests pass
  • [ ] A changelog entry exists and is marked appropriately N/A, should be dev-only / not have any user-facing changes

- see https://github.com/stylelint/stylelint/blob/main/docs/migration-guide/to-15.md  - this removal of Prettier conflicts will save us a lot of setup for CSS-in-JS
- to Sass overrides only - we'll need a separate set of rules for CSS-in-JS later

- see https://github.com/stylelint/stylelint/blob/main/docs/user-guide/rules.md#deprecated
- @see https://github.com/hudochenkov/postcss-styled-syntax

+ set up rule overrides as necessary to handle JS-specific issues
- in favor of simply typing `--fix` manually, or calling `yarn llint-fix`

- remove lint-sass-fix entirely since we're moving away from sass
- use `mathWithUnits` and border width var instead
- use obj keys so that Emotion correctly generates the expected classNames

- use conditionals in array, not in CSS generation

- use separate fn for SR styles that take a custom arg
Our various JS utils generally include trailing `;`s and don't need extra `;`s after them

+ lint a few extra trailing `}`s which stylelint also catches
- new stylelint default in v15 uses commas (complex) instead of chained `:not()`s

- disable for Sass - wasn't previously linted
- valid usage in this case, but in general we should lint for it
- `except` isn't handling JS interpolation well, so change it to `ignore` instead
- Sass will be going away soon and is irrelevant

- CSS-in-JS has one deprecation warning (extra semicolons), but it's pretty dang useful, so I think we should not warn on it
@cee-chen
Copy link
Member Author

@elastic/eui-team Would super appreciate a review on this whenever any of y'all have a sec! It's a lot of lines but most of it is either just yarn.lock or repetitive linting stuff, so it goes by a bit quicker following the commits.

I'll be doing more Emotion work this week after this so being able to auto-lint that work would be 💯

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6839/

@cee-chen cee-chen requested a review from 1Copenut June 14, 2023 04:27
Copy link
Contributor

@1Copenut 1Copenut left a comment

Choose a reason for hiding this comment

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

👍 I was able to run all the commands locally, intentionally broke a file, fixed it as expected. Looked through the commits as suggested. Very helpful!

- I'm sure this will come up in the future otherwise
@cee-chen
Copy link
Member Author

Thanks Trevor! I realized that the // comment thing would likely trip up a few people during Emotion conversions, so I updated our wiki/FAQ with it. Going to go ahead and admin merge this in (I made the mistake of merging in main and CI is currently borked)

@cee-chen cee-chen merged commit b2836fe into elastic:main Jun 14, 2023
4 of 5 checks passed
@cee-chen cee-chen deleted the lint-css-in-js branch June 14, 2023 20:31
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6839/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tech debt] Linting Emotion/CSS-in-JS
3 participants