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

fix: deprecation warning about using / for division #1452

Merged
merged 3 commits into from
Jun 15, 2021
Merged

fix: deprecation warning about using / for division #1452

merged 3 commits into from
Jun 15, 2021

Conversation

mktcode
Copy link
Contributor

@mktcode mktcode commented Jun 8, 2021

Replaced all occurrences with math.div(x, y).

Searches I made:

  • \$[\w-]+\s?\/\s?\$[\w-]+ (e.g. $var/ $var2)
  • [\d]+\s?\/\s?[\d]+ (e.g. 1 / 12)
  • \$[\w-]+\s?\/\s?[\d]+ (e.g. $var2 / 123)
  • [\d]+\s?\/\s?\$[\w-]+ (e.g. 123/ $var2)

/cc @primer/ds-core

@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2021

🦋 Changeset detected

Latest commit: 10a8573

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/css Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mktcode mktcode marked this pull request as draft June 8, 2021 13:36
@mktcode mktcode marked this pull request as ready for review June 8, 2021 13:41
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.

@mktcode @plegner Thanks for bringing this to our attention. 🙇 Yep, seems using / for division will be removed at some point.

As for this PR, I think we use LibSass for github.com, so using math.div(x, y) won't work. Not sure if there is a plan to add it to LibSass and Ruby Sass in the future?

Maybe an alternative to using division is using multiply with a fraction as decimal. Like

  • / 2 -> * 0.5
  • / 3 -> * 0.3333333333
  • / 4 -> * 0.25
  • etc.

Well, at least for now until the other libraries add support for division.

/cc @jonrohan @vdepizzol

@mktcode
Copy link
Contributor Author

mktcode commented Jun 9, 2021

multiply with a fraction as decimal

I like that idea. But what about variables?

.Layout-main {
grid-column: 2 / span 2;
}

I also just found that both Ruby Sass and LibSass reached their end of life:
https://sass-lang.com/blog/libsass-is-deprecated
https://github.com/sass/ruby-sass#ruby-sass-has-reached-end-of-life

Oh and... Postcss also doesn't seem to like it. Error: Invalid CSS after "...r-1: round(math": expected expression (e.g. 1px, bold), was ".div($spacer, 2)) !

Should I have run the tests locally? Absolutely. Did I? Just now, yes... :D

@simurai
Copy link
Contributor

simurai commented Jun 9, 2021

But what about variables?

I think grid-column: 2 / span 2; is "vanilla" CSS, see MDN. So we should be able to keep that as is.

I also just found that both Ruby Sass and LibSass reached their end of life

Ooh.. 😱 yeah, we probably should look into replacing LibSass sooner or later.

@mktcode
Copy link
Contributor Author

mktcode commented Jun 9, 2021

I think grid-column: 2 / span 2; is "vanilla" CSS

It's still early here and I just got up.... don't know why I referenced that line. o_O
(But actually... didn't know that :D)

This is what I mean:

@return $pixels / $context * 1rem;

@@ -37,7 +37,7 @@
}

.Layout-main {
grid-column: 2 / span 2;
grid-column: math.div(2, span) 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

As @simurai pointed out, this is not a division, but a CSS grid syntax. Same with a couple of other lines below :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦🏻 now I get it....

Copy link
Contributor Author

@mktcode mktcode Jun 9, 2021

Choose a reason for hiding this comment

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

Brutally force pushed now... things never happened. :D But I still don't know how to fix the $variable situation.

Copy link
Contributor Author

@mktcode mktcode Jun 9, 2021

Choose a reason for hiding this comment

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

Ahhh gosh... today's really not my day. Don't say anything... saw it myself.

... ok now.

@@ -33,7 +33,7 @@ $spacer: 8px !default;

// Our spacing scale
$spacer-0: 0 !default; // 0
$spacer-1: round($spacer / 2) !default; // 4px
$spacer-1: round(math.div($spacer, 2)) !default; // 4px
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$spacer-1: round(math.div($spacer, 2)) !default; // 4px
$spacer-1: $spacer * 0.5 !default; // 4px

using / for division is deprecated and the math module (math.div(x,y)) not guaranteed to be available
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.

Ok, I think this looks good.

@mktcode Thanks. 🙇

@simurai simurai merged commit 8838a3a into primer:main Jun 15, 2021
@primer-css primer-css mentioned this pull request Jun 15, 2021
@mktcode
Copy link
Contributor Author

mktcode commented Jun 15, 2021

Well, won't this still be an issue?

@return $pixels / $context * 1rem;

Since the variable makes it impossible to handle it with multiplication, I assume this just has to wait?

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

Successfully merging this pull request may close these issues.

SCSS Compile Errors (replace / with math.div)
3 participants