-
Notifications
You must be signed in to change notification settings - Fork 167
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
refactor: retroactively eslint other cron files #1993
base: main
Are you sure you want to change the base?
Conversation
…ts log of retrieval duration
…ith sample value from secrets vault
packages/cron/src/jobs/dagcargo.js
Outdated
@@ -47,7 +49,12 @@ export async function updateDagSizes({ pg, after }) { | |||
const countRes = await pg.query(COUNT_CONTENT_WITHOUT_SIZE, [ | |||
after.toISOString(), | |||
]) | |||
const total = countRes.rows[0].count | |||
assert.ok(countRes.rows[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that node.js assert.ok is typed as a tsc type guard, this is how i chose to get type safety.
It's at risk of throwing more AssertionError errors, but at least that's a fail-fast well-before any more mysterious runtime errors we have to track down by trolling through logs.
@alanshaw lmk if you'd rather I just use a type assertion (which may be incorrect at runtime) rather than the asserts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have not typically used assert
outside of tests. It seems to add a lot of noise to the code base and (at least for me) is making it quite difficult to read the actual code. It looks like you might end up asserting on types multiple times in multiple places and I think it would be more DRY to just use a @typedef
or @type
once. There's also probably some performance overhead we're suffering by continually type checking everything.
It definitely makes sense to use assert
to validate types for inputs (such as in a REST endpoint, or user input from a CLI) at runtime (and likely in some other situations) but I wouldn't use it to obtain type safety like this in your editor or for the typescript compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update to use less runtime assert and instead use a type assertion via js comment.
I have to admit I don't really understand why all the #1945 commits appear in here. I think it's because I didn't rebase, but merged. But the rebase seemed like it would take forever and be bug prone? If it's important to have a cleaner commit log on this, I could use some advice on how to do that. (IMO it isn't too important?) |
packages/cron/src/jobs/dagcargo.js
Outdated
@@ -47,7 +49,12 @@ export async function updateDagSizes({ pg, after }) { | |||
const countRes = await pg.query(COUNT_CONTENT_WITHOUT_SIZE, [ | |||
after.toISOString(), | |||
]) | |||
const total = countRes.rows[0].count | |||
assert.ok(countRes.rows[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have not typically used assert
outside of tests. It seems to add a lot of noise to the code base and (at least for me) is making it quite difficult to read the actual code. It looks like you might end up asserting on types multiple times in multiple places and I think it would be more DRY to just use a @typedef
or @type
once. There's also probably some performance overhead we're suffering by continually type checking everything.
It definitely makes sense to use assert
to validate types for inputs (such as in a REST endpoint, or user input from a CLI) at runtime (and likely in some other situations) but I wouldn't use it to obtain type safety like this in your editor or for the typescript compiler.
All the places where the new lint rules were unhappy due to unsafety around |
body: JSON.stringify({ hashToPin: cid, ...(options || {}) }), | ||
}) | ||
) | ||
const pin = /** @type {PinataPin} */ (json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, do we need the extra json const here to please the types?
Motivation: