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

Stylelint update #968

Merged
merged 37 commits into from
Nov 4, 2019
Merged

Stylelint update #968

merged 37 commits into from
Nov 4, 2019

Conversation

shawnbot
Copy link
Contributor

@shawnbot shawnbot commented Oct 31, 2019

Our new and improved stylelint config introduces some new rules, and these rules demand fealty! Here's my workflow for rectifying the new linting errors, one rule at a time:

  1. Enable the rule in stylelint.config.js.
  2. Run npx stylelint-only <rule> -- --fix src to autofix as many values as possible
  3. Run npx stylelint-disable <rule> -- src to add stylelint-disable-next-line comments above offending declarations.
  4. Run npx stylelint-only <rule> -- src to see if there are any remaining violations, and fix those manually. (Most of these were because of extra lines being added after comments by stylelint-disable).
  5. Run git add -p, skip any changes that are undesirable (such as color: $tooltip-text-color outside of tooltips), then git checkout -- src to throw out the changes we don't want.

I've added stylelint-only and stylelint-disable as dev dependencies so that we can use them more readily for focused linting and/or refactors.

The other thing I've done here is added some new "functional" variables to cover common patterns:

  • $bg-white: $white "fixes" 32 instances of `background-color: $white'
  • $text-white: $white fixes 24 instances of color: $white
  • $text-black: $black fixes a handful of instances of color: $black
  • $border-white: $white fixes a handful of border colors with $white
  • $border-color-button: rgba($black, 0.2) replaces a bunch of static instances of button border colors.

I've also added TODO deprecation comments (per #946) that state our intent to deprecate those variables in #925 (v14.0.0). I suppose we should add a new field to our deprecations data for variables too, huh?

@vercel
Copy link

vercel bot commented Oct 31, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/primer/primer-css/pc0873qne
🌍 Preview: https://primer-css-git-stylelint-update.primer.now.sh

@shawnbot shawnbot changed the base branch from master to release-14.0.0 October 31, 2019 19:23
@shawnbot shawnbot requested a review from simurai October 31, 2019 20:46
@shawnbot shawnbot marked this pull request as ready for review October 31, 2019 20:49
@@ -87,7 +95,9 @@
// FIXME deprecate this
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be a good candidate for a TODO@14.0.0 comment (see: #946).

src/base/normalize.scss Outdated Show resolved Hide resolved
@@ -15,7 +17,9 @@
background-repeat: repeat-x;
background-position: -1px -1px;
background-size: 110% 110%;
border: 1px solid transparentize($black, 0.8);
// stylelint-disable-next-line primer/borders
border: $border-width $border-style transparentize($black, 0.8);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For consistency, I think we should use rgba() here rather than transparentize() (which decreases the alpha channel by the provided amount):

Suggested change
border: $border-width $border-style transparentize($black, 0.8);
border: $border-width $border-style rgba($black, 0.2);

Of course, at that point we might as well switch over to using $border-black-fade / $black-fade-15, which has an alpha of 15%? 🤔 Here are 15%, 20%, and 30% for comparison:

RGBA SCSS Image
$border-black-fade rgba(27,31,35,0.15) image
rgba($black, .2) (current) rgba(27,31,35,0.20) image
$black-fade-30 rgba(27,31,35,0.30) image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI @simurai I found all our transparent $black values and dropped them in our spreadsheet to look at later. At the very least, I think we should standardize on using rgba($color, $alpha) rather than transparentize($color, $alpha-offset).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've introduced a variable, $border-color-button: rgba($black, 0.2) in 7fd97bf and replaced all of the (equivalent) instances in c5c4f15.

Copy link
Contributor

Choose a reason for hiding this comment

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

At the very least, I think we should standardize on using rgba($color, $alpha) rather than transparentize($color, $alpha-offset).

Yeah, I find rgba($black, 0.2) much easier to read. Maybe because transparentize($black, 0.8) requires you to do some math first. I guess the only time we would need transparentize() is when we want to make a color that already is semi-transparent a little more transparent. But that's maybe a rare case we don't have to worry about.

syntax: 'scss',
rules: {
'scss/dollar-variable-default': [true, {ignore: 'local'}],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This rule enforces the inclusion of !default in all of our global variables.

@shawnbot
Copy link
Contributor Author

Here is a list of new tasks for #925 when we're ready to merge this:

PRIMER_VERSION=14.0.0 npx stylelint src --quiet

src/marketing/support/variables.scss
 42:1  ✖  Unresolved TODO comment: "remove $marketingSpacers (unused)" (expected to be resolved in "14.0.0")   primer-css/TODO
 44:1  ✖  Unresolved TODO comment: "remove $allSpacers (unused)" (expected to be resolved in "14.0.0")         primer-css/TODO

src/support/variables/colors.scss
  5:1  ✖  Unresolved TODO comment: "remove $status-pending (unused)" (expected to be resolved in "14.0.0")          primer-css/TODO
 10:1  ✖  Unresolved TODO comment: "remove $repo-private-text, $repo-private-bg, and $repo-private-icon" (expected  primer-css/TODO
          to be resolved in "14.0.0")                                                                                              
 16:1  ✖  Unresolved TODO comment: "remove $highlight-yellow (unused)" (expected to be resolved in "14.0.0")        primer-css/TODO

src/support/variables/misc.scss
 29:1  ✖  Unresolved TODO comment: "move $exploregrid-item-border-radius to github/github" (expected to be          primer-css/TODO
          resolved in "14.0.0")                                                                                                    
 32:1  ✖  Unresolved TODO comment: "remove $stats-switcher-py (unused)" (expected to be resolved in "14.0.0")       primer-css/TODO
 37:1  ✖  Unresolved TODO comment: "remove $stats-viewport-height (unused)" (expected to be resolved in "14.0.0")   primer-css/TODO
 40:1  ✖  Unresolved TODO comment: "move $min_tab_size, $max_tab_size to github/github" (expected to be resolved    primer-css/TODO
          in "14.0.0")

Copy link
Contributor

@simurai simurai left a comment

Choose a reason for hiding this comment

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

Looks good. 👍

Since this touches a lot of files... do you wanna go ahead and already merge it into release-14.0.0? Then when making new changes we can branch off from release-14.0.0 instead of master to avoid merge conflicts.

src/base/normalize.scss Outdated Show resolved Hide resolved
Copy link
Contributor

@simurai simurai left a comment

Choose a reason for hiding this comment

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

🚢

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.

2 participants