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 "no-implicit-coercion" #15

Merged
merged 3 commits into from
Apr 26, 2022
Merged

Add "no-implicit-coercion" #15

merged 3 commits into from
Apr 26, 2022

Conversation

juliangruber
Copy link
Contributor

https://eslint.org/docs/rules/no-implicit-coercion

I find this rule useful as it prevents shorthand syntax that can be either difficult to read or understand.

To me it's always better to write

new Date().getTime()

instead of

+new Date()

or

String(foo)

instead of

`${foo}`

There are more characters on screen yes, but the intend is clearer and reading the code requires less understanding of JavaScript internals.

I know that @kvz and @tim-kos like using these syntax tricks a lot, so I don't expect this to go very easy.

@juliangruber juliangruber self-assigned this Apr 22, 2022
@lekevbot lekevbot added the satellite Miscellanous related projects label Apr 22, 2022
@tim-kos
Copy link
Member

tim-kos commented Apr 24, 2022 via email

Copy link
Collaborator

@mifi mifi left a comment

Choose a reason for hiding this comment

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

I usually use !!val, but I can live with having to write Boolean(). I think some of these shorthands are very cryptic so it makes sense to not allow them.

Copy link
Member

@kvz kvz left a comment

Choose a reason for hiding this comment

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

Probably not one I would have proposed myself no, but also not one I am religious about to keep out of our standard, so I am fine personally with merging this.

I do think the Uppy team should weigh in first tho. And also I think this will add yet another thousand warnings to our big repos. At one point we should make a push to also fix a few of those. Maybe a few heavy hitters can be addressed with jscodemods?

@juliangruber
Copy link
Contributor Author

Maybe a few heavy hitters can be addressed with jscodemods?

I'm assuming we can take care of 99% of cases using string search/replace, or even eslint --fix if that covers it.

@aduh95
Copy link
Contributor

aduh95 commented Apr 25, 2022

To me it's always better to write

new Date().getTime()

instead of

+new Date()

FWIW, it's always better (performance-wise, and imho in general) to write Date.now() 😉

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Same as Kev. More consistency in the code we write and review is ultimately a good thing imo

@juliangruber
Copy link
Contributor Author

FWIW, it's always better (performance-wise, and imho in general) to write Date.now() 😉

I agree about performance, but not maintainability. When you're not in a hot code path then a Date object is more useful as it allows access to the timestamp and all the other date functions too.

@Murderlon
Copy link
Member

Don't have a strong opinion on this. But we already have 2000+ warnings in the Uppy repo and ideally we get it down rather than up, because we are just getting too used to seeing warnings.

@aduh95
Copy link
Contributor

aduh95 commented Apr 25, 2022

Don't have a strong opinion on this. But we already have 2000+ warnings in the Uppy repo and ideally we get it down rather than up, because we are just getting too used to seeing warnings.

FWIW the goal is to get as close as 0 warnings when doing the ESM transition, and then change ESLint settings from warning to error on all rules.

Copy link

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

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

@kvz consider my peace held 😇

@@ -135,5 +135,12 @@ module.exports = {
'react/jsx-one-expression-per-line': ['off'], // <-- This one is a bit annoying
'no-await-in-loop': ['off'], // <-- Let's disable it and see if it bites us
'no-underscore-dangle': ['off'], // We use _ in almost all repos. See discussion here: https://github.com/transloadit/botty/pull/41#discussion_r738022104

'no-implicit-coercion': [
'error',
Copy link
Member

@kvz kvz Apr 25, 2022

Choose a reason for hiding this comment

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

We'll need to trial this as a warning to give projects the chance to upgrade, and once there are no more warnings, then we promote to error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sgtm

Copy link
Contributor

Choose a reason for hiding this comment

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

Counter proposal: I think we should keep it as an error, projects should override that rule to be a warning instead until they've fixed all the occurrences. (please no more warnings 🥺)

@arturi
Copy link

arturi commented Apr 26, 2022

I am all for readability, !!var makes my brain go crazy for 5 minutes at least, and I have not seen +new Date() before this PR. Green light.

@kvz kvz merged commit fe25e95 into main Apr 26, 2022
@kvz kvz deleted the add/no-implicit-coercion branch April 26, 2022 15:48
@juliangruber
Copy link
Contributor Author

Thank you everyone for your input!

@kvz what are the next steps?

@kvz
Copy link
Member

kvz commented Apr 26, 2022

  1. collecting more ideas for v3 (if no more linting changes, upgrading eslint & friends is always a good idea)
  2. push out v3.0.0-0
  3. trial it in uppy & api to see if we run into any unforeseen warning/error/autofix, and if tests pass and so on
  4. if we are happy, push out v3.0.0
  5. upgrade all consuming repos (for inspiration see Roll out v2.0.0-0 across main js repos #13, also the hint at the bottom of the description there for helping rolling out big linting upgrades)

@juliangruber
Copy link
Contributor Author

  1. collecting more ideas for v3 (if no more linting changes, upgrading eslint & friends is always a good idea)

To me the smaller the change the better, as it will be easier to upgrade. Upgrading dependencies sounds great 👍

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

Successfully merging this pull request may close these issues.

9 participants