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 typed lint checks and fix promise related things #1081

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ericanderson
Copy link
Member

No description provided.

"@typescript-eslint/no-redundant-type-constituents": "warn",

// ideally these would be an error because it does catch bugs
// but it also requires a lot of code change right now
Copy link
Member Author

Choose a reason for hiding this comment

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

Originally I didnt disable all of these but i had 100s of files of change and decided to start back over with a minimal set and we can do different PRs to enable these later

@@ -31,7 +31,7 @@ export async function getWebsite(

try {
const result = await fetch(url);
return result.json();
return await result.json();
Copy link
Member Author

Choose a reason for hiding this comment

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

Gives better stack traces

@@ -115,7 +115,7 @@ describe(createClient, () => {
"makeConjureContext",
);

metadataCacheClient(
void metadataCacheClient(
Copy link
Member Author

Choose a reason for hiding this comment

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

Signals to the linter that we know this returns a promise and we do not care

ontologyRid.then((ontologyRid) => {
if (!ontologyRid.startsWith("ri.")) {
// FIXME this promise is not await so this just shows up as an unhandled promise rejection
throw new Error("Invalid ontology RID");
Copy link
Member Author

Choose a reason for hiding this comment

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

@nihalbhatnagar have a follow up for you

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah just need a .catch here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you probably don't want to throw because it will just end up as an unhandled promise. Maybe we want to set ontologyRid = ontologyRid.then(... and that way when we do end up using it it will pop up through a call stack?

We could maybe add a console.error() for the first time its hit too?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you mean, this makes sense to me

latestPointPromise.then(
latestPoint => this.lastFetchedValue = latestPoint,
// eslint-disable-next-line no-console
err => void console.error(err),
Copy link
Member Author

Choose a reason for hiding this comment

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

Not handling the error case means we have an unhandled promise rejection which can be swallowed

else window.location.assign(x);
if (useHistory) {
window.history.replaceState({}, "", x);
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

Auto fixer did this when I saved a different change. I kinda like the return void window... syntax better but there are two different promise rules and that causes an issue with another one since .assign isn't returning a promise, it returns void and so the void window.history... is "redundant". But its not cause we need it for the async function. Sigh. So i left this auto fixer as is.

@@ -55,7 +55,7 @@ export async function publishPackages(
);

// need to produce the output to save for future run of create tag/release
fs.writeFile(
await fs.writeFile(
Copy link
Member Author

Choose a reason for hiding this comment

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

More races/real bug

@@ -248,7 +248,7 @@ export function FoundryWidgetVitePlugin(_options: Options = {}): Plugin {
res.statusCode = settingsResponse.status;
res.statusMessage =
`Unable to set widget settings in Foundry: ${settingsResponse.statusText}`;
settingsResponse.text().then((err) => {
await settingsResponse.text().then((err) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Prevents unhandled rejection + improves stack trace

@@ -669,6 +669,7 @@ function getPluginTransformHook(
typeof plugin.transformIndexHtml === "object"
&& "transform" in plugin.transformIndexHtml
) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return plugin.transformIndexHtml.transform;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think in general its good for it to be an error when we use deprecated types but I dont want to deep research vite plugins to understand if there is a consequence to this right now so we will save it as is.

@@ -27,7 +27,7 @@
"tsconfig.json"
],
"outputs": [],
"dependsOn": ["//#global-eslint-config", "//#dprint"]
"dependsOn": ["//#global-eslint-config", "//#dprint", "typecheck"]
},

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotta be sure we have compiled all of our dependencies

Copy link
Contributor

@nihalbhatnagar nihalbhatnagar 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 to me, the warnings at the bottom look relatively simple to fix as well when we clean up

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