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

Gm/update-base-and-readme #32

Merged
merged 2 commits into from
Sep 30, 2024
Merged

Gm/update-base-and-readme #32

merged 2 commits into from
Sep 30, 2024

Conversation

mckelveygreg
Copy link
Collaborator

I have applied this to all our ts.

I found a few errors in the readme example, and I added some new rules to the base config that I found helpful in all the other repos

@@ -34,6 +34,32 @@ export default tsEslint.config(
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/use-unknown-in-catch-callback-variable": "off",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Things I think are true:

  • errors should be unknown
  • your tsconfig settings should be strict

Things I want to be true:

  • that ts setting works in then().catch() (it does not yet)
  • I don't have to fix it myself (apparently you can override the global, but i don't want to do that.

Therefore, I don't think this rule is important enough (and i don't feel like making that many code changes to support it 😬 )

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't say I've encountered this but your answer seems reasonable to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TS made the unknown thing a default a bit ago, and I got wrecked with a refactor of tons of tiny changes from any to unknown. But apparently, that was only for try/catch, not then().catch()

So we wait on...

Comment on lines +38 to +47
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allowAny: true,
allowBoolean: true,
allowNullish: false,
allowNumber: true,
allowRegExp: true,
},
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This rule I catches some nice little bugz that happen inside template literals, like [object] [object] and encourages you to provide fallbacks for nullish values.

Template literals will call the .toString() method on everything you put there, so with that understanding, I think it is fine to allow the above values, as toString() was not adding any value having that enforced.
However, it did make me consider numbers, as most numbers can be handled fine by toString(), big numbers in UI should be displayed with .toLocaleString(), and any floating point math should be dealt with before you end up with ugly 3.0000000000000001.

I kept the allowNullish: false however. The more time that goes by, the more I'm bothered by my logs that end up with: "error with item id:" where the item didn't exist or something. This rule would ask the developer to provide some feedback, like

`error with item id: ${item?.id ?? "<item not found>"}`

https://typescript-eslint.io/rules/restrict-template-expressions/

Comment on lines +48 to +54
"@typescript-eslint/no-confusing-void-expression": [
"error",
{
ignoreArrowShorthand: true,
ignoreVoidOperator: true,
},
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I started my journey here without the overrides. And then like 50 files in... it started to feel a bit overboard...

The core of this rule supports lots of good patterns, but for these 2 overrides, i feel like I'm comfortable not going all the way.

This means, we can still:

<button onClick={() => console.log("🎉")} />

https://typescript-eslint.io/rules/no-confusing-void-expression/

Comment on lines +55 to +62
"@typescript-eslint/no-unused-expressions": [
"error",
{
allowShortCircuit: true,
allowTernary: true,
enforceForJSX: true,
},
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, this one was a bit funky. Essentially it is trying to protect you from misunderstanding function calls, but it went a little far. They provided the above overrides, which maintained our current coding style, while adding som protection when you actually do something wrong.

https://eslint.org/docs/latest/rules/no-unused-expressions#options

Copy link
Contributor

@hiddenist hiddenist left a comment

Choose a reason for hiding this comment

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

Thanks for the comments explaining the different rules. This looks totally reasonable to me.

Do we need to bump a version number? I forget how we do releases in this repo.

@mckelveygreg mckelveygreg merged commit b1bf847 into main Sep 30, 2024
@mckelveygreg mckelveygreg deleted the gm/update-base-and-readme branch September 30, 2024 22:26
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.

2 participants