-
Notifications
You must be signed in to change notification settings - Fork 117
Add basic eslint recommendations to core/
#3077
base: main
Are you sure you want to change the base?
Conversation
}, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", |
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.
Notice here that I'm using @typescript-eslint/eslint-recommended
instead of @typescript-eslint/recommended
. This extension only makes sure that typescript plays nicely with eslint:recommended
but does not enable the typescript recommended rules. Currently, there are a gargantuan number of problems with core
so doing it all once is a herculean effort. At the very least we're getting base safety.
globals: { | ||
fetch: true, // For isomorphic-fetch | ||
}, | ||
ignorePatterns: ["__tests__", "dist", "public"], |
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.
Lots of problems in __tests__
to fix, so it's being ignored for this PR.
} catch { | ||
// Ignore error | ||
} |
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.
In the recommendations we get the no-empty rule that discourages empty blocks. The easiest way to fix it is to put a comment.
@@ -74,7 +74,7 @@ export namespace CloudCLI { | |||
); | |||
|
|||
let lastState: string; | |||
while (true) { | |||
for (;;) { |
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.
Fix for no-constant-condition
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.
Do you think we should disable that rule? We could rewrite this function to not need an infinite loop but I'm not it's worth the refactor time.
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.
Nice!
these look to me mostly stylistic changes… did you see any logical problems?
@@ -20,7 +20,7 @@ export async function loadSchedule( | |||
): Promise<IdsByClass> { | |||
let isNew = false; | |||
|
|||
if (configObject.hasOwnProperty("confirmProfiles")) { | |||
if (Object.prototype.hasOwnProperty.call(configObject, "confirmProfiles")) { |
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.
@@ -260,6 +258,7 @@ export namespace RecordOps { | |||
recordProperties: { | |||
[key: string]: (string | number | boolean | Date)[] | any; | |||
}[], | |||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |||
toLock = true, |
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.
This argument is not really being used right now, so I'm not sure whether to remove it and update all the instances that use it or leave it.
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.
If there's enough of these I'd say icebox a ticket to remove.
} catch (error) { | ||
throw error; |
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.
Unnecessary catches because they only rethrow the error
@@ -28,6 +28,7 @@ export namespace Reset { | |||
* * clears the redis cache | |||
* * clears resque | |||
*/ | |||
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
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 left these here because the test is definitely passing a callerId. But callerId is not used in any of these functions. I could update the usage of these so that callerId is no longer used and leave it for some future use.
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.
🤷 Probably not worth removing
@@ -81,6 +81,7 @@ export class StatusTask extends CLSTask { | |||
if (!toStop) return false; | |||
|
|||
// do not await so the promise can end so the server can shut down | |||
// eslint-disable-next-line no-async-promise-executor |
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.
It really does not like returning a promise with an async call. Looks like this is intentional but could be dangerous otherwise. Doc explains why:
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.
The proimise isn't returned. Does:
await api.process.stop();
process.nextTick(() => process.exit(0));
Even need to be wrapped?
I feel like maybe the entire block could be api.process.stop().then(() => process.nextTick(() => process.exit(0)));
@evantahler Thoughts?
@evantahler The style issues are always easy to fix. I highlighted a few areas in the comments that point out potential logic issues. |
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 expect some merge conflicts with my just-merged code.
}, | ||
overrides: [ | ||
{ | ||
files: ["*.ts", "*.tsx"], |
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 think you could just add *.js
to ignorePatterns and you shouldn't need this?
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.
This gets added by @typescript:recommended
but not @typescript:eslint-recommended
So I need to manually add this override otherwise I have to run eslint with eslint . --ext ts,tsx
@@ -74,7 +74,7 @@ export namespace CloudCLI { | |||
); | |||
|
|||
let lastState: string; | |||
while (true) { | |||
for (;;) { |
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.
Do you think we should disable that rule? We could rewrite this function to not need an infinite loop but I'm not it's worth the refactor time.
} catch (e) { | ||
throw e; | ||
this.accessToken = token; | ||
this.expirationDate = Date.now() + expirationSeconds * 1000; |
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.
Unwrapped 👍
@@ -81,6 +81,7 @@ export class StatusTask extends CLSTask { | |||
if (!toStop) return false; | |||
|
|||
// do not await so the promise can end so the server can shut down | |||
// eslint-disable-next-line no-async-promise-executor |
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.
The proimise isn't returned. Does:
await api.process.stop();
process.nextTick(() => process.exit(0));
Even need to be wrapped?
I feel like maybe the entire block could be api.process.stop().then(() => process.nextTick(() => process.exit(0)));
@evantahler Thoughts?
@@ -528,7 +527,7 @@ function mergeMetrics(metrics: StatusMetric[]) { | |||
mergedMetrics.push(item); | |||
} else if (idx !== null) { | |||
for (const k in Object.keys(item)) { | |||
if (item.hasOwnProperty(k)) { | |||
if (Object.prototype.hasOwnProperty.call(item, k)) { |
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.
Don't love this rule
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.
Yeah, good discussion point. Should we allow it? Should we not use hasOwnProperty
?
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.
Looks like hasOwn exists and we should maybe just use that instead?
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.
hasOwn is super new. It looks like we'll have to upgrade to target es2022, we're still targeting es2019.
https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/#target-es2022
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 don't object :P
@@ -28,6 +28,7 @@ export namespace Reset { | |||
* * clears the redis cache | |||
* * clears resque | |||
*/ | |||
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
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.
🤷 Probably not worth removing
@@ -260,6 +258,7 @@ export namespace RecordOps { | |||
recordProperties: { | |||
[key: string]: (string | number | boolean | Date)[] | any; | |||
}[], | |||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |||
toLock = true, |
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.
If there's enough of these I'd say icebox a ticket to remove.
ff4630e
to
a90add8
Compare
Change description
Based on the issue in #3070 that could have been prevented with linting, this adds the most basic eslint rules to
core
and fixes a number of existing issues. The rules are not as strict as our plan because there's currently a lot to fix, and the plan is to incrementally enable rules and fix issues as we find the time to do it.Checklists
Development
Impact
Please explain any security, performance, migration, or other impacts if relevant:
Code review