-
Notifications
You must be signed in to change notification settings - Fork 364
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
Lint fixes #7272
Lint fixes #7272
Conversation
@@ -33,10 +33,10 @@ const transitionEnd = (element: Element | null) => | |||
}); | |||
|
|||
const animationTimeout = ( | |||
timeoutID: ReturnType<typeof setTimeout> | undefined | |||
_timeoutID: ReturnType<typeof setTimeout> | undefined |
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.
There's a lot of unused params across the codebase, we could instead just turn off the rule for unused params, open to suggestions (I prefer having to be explicit)
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.
As someone who isn't intimately familiar with the code base, it's a one time cost to prepend a "_" to (at most) 215 places, and that prevents future unused leftovers that will confuse me.
.eslintrc
Outdated
"@typescript-eslint/no-unsafe-declaration-merging": "warn", | ||
"react-hooks/exhaustive-deps": "warn", | ||
"@typescript-eslint/no-unsafe-declaration-merging": "off", | ||
"react-hooks/exhaustive-deps": "off", |
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 would vote for leaving this turned on, don't how much of them is there but definitely better would be to suppress them using eslint-disable
comments. If I recall correctly there isn't much of hook usages.
p.s. Yeah it is bad practice to suppress the warning or error but would always choose that instead of disabling the rule for all future code.
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.
My thinking was just having a smaller diff (and I'd like to resolve the exhaustive-deps
eventually) but you're right better to use disable comments to prevent further instances. Will update
lib/Table/TableColumn.ts
Outdated
@@ -920,6 +920,6 @@ function toNumber(value: string): number | null { | |||
return null; | |||
} | |||
|
|||
function nullFunction(rowIndex: number) { | |||
function nullFunction() { |
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 function is returned from scaledValueFunctionForType
, doesn't callers of that function expect the returned function to accept one parameter?
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.
They do but it doesn't look like typescript minds: example . Happy to change it to (_rowIndex: number)
if you think that's clearer
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 had a second look, and wrote something that roughly equals "the type signature states the returned function should take a number and return a number, so I suspect removing the parameter will cause problems in some future upgrade of TypeScript".
As a side note, the return type of nullFunction
is null
rather than number
, so the type is already wrong in the current code base. The function body is just return null
, so TypeScript must be able to infer that return type as well.
I feel this behavior of a type checker is really strange, so I had a third look. The function getScaledValueFunctionForType
was added in #3594 and had a caller in TableMixin.ts
, but that caller no longer seems to be present. Could getScaledValueFunctionForType
(and its helper functions) be removed 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.
Nice find thanks I'll remove it
If you are focusing on lint-related things in the near future, it might be worth considering #7150 after this PR has been merged (I'll fix the conflicts after this is merged). |
@@ -121,7 +121,7 @@ export default class ThreddsItemReference extends UrlMixin( | |||
); | |||
if (model === undefined) return; | |||
this.setThreddsStrata(model); | |||
previousTarget = model; | |||
_previousTarget = model; |
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.
What do these assignments do, is previousTarget
some kind of return-value type so the caller gets a hold of a reference to the model?
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.
That's my understanding, it's updating the reference. Although looking where it's call in ReferenceMixin
that reference doesn't appear to be further used. @na9da do you have insight into 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.
I think that line has no effect and can be removed. There's couple more of these.
@@ -24,7 +24,7 @@ export default function LoadableStratum< | |||
get: function () { | |||
return undefined; | |||
}, | |||
set: function (value: any) { | |||
set: function () { |
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.
Same comment for this as the nullFunction below: I suspect removing the parameter will cause problems in some future TypeScript upgrade (and a setter without parameter is strange).
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.
Good point, will update
lib/Models/Leaflet.ts
Outdated
@@ -63,7 +63,7 @@ import Terria from "./Terria"; | |||
// We want TS to look at the type declared in lib/ThirdParty/terriajs-cesium-extra/index.d.ts | |||
// and import doesn't allows us to do that, so instead we use require + type casting to ensure | |||
// we still maintain the type checking, without TS screaming with errors | |||
const FeatureDetection: FeatureDetection = | |||
const _FeatureDetection: FeatureDetection = |
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 looks like something special that isn't just an unused parameter, can @ts-expect-error
be used here so this variable doesn't get lost among the noise of unused parameters?
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.
Scratch my previous remark, the comment in the source code is 4+ years old. In #6944, the FeatureDetection variable is removed from CorsProxy.ts since the FeatureDetection is not used in that file any longer, so this line corresponds to an unused import as far as I understand. I'm guessing the variable and the comment can be removed?
@@ -148,7 +148,7 @@ describe("WebProcessingServiceCatalogFunction", function () { | |||
let dispose: any; | |||
job = (await wps.submitJob()) as WebProcessingServiceCatalogFunctionJob; | |||
|
|||
await new Promise<void>((resolve, reject) => { | |||
await new Promise<void>((resolve, _reject) => { |
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 change in YDYRCatalogFunctionSpec above just removes the parameter. If this isn't somehow different from that, I think it's better to either choose to always keep the unused reject with an underscore or always remove 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.
I'll remove the unused rejects since it's not communicating anything extra
test/Models/Experiment.ts
Outdated
@@ -49,7 +49,7 @@ describe("NewStuff", function () { | |||
); | |||
}); | |||
|
|||
autorun((dispose) => { | |||
autorun((_dispose) => { |
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.
Did you intend to remove the console.log in the next line too?
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 whole file isn't actually asserting anything and hasn't been touched since 2021, I'll check with the team about removing it completely.
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.
Deleted
- remove unneeded console.logs
Turn off exhaustive-deps as fixing these are likely to have side effects
…oks/exhaustive-deps": "error", Disable existing usages via comment
- Delete Experiment.ts
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 had a look again and while I don't speak TypeScript fluently, from what I can see this looks like a solid improvement.
Not having 200+ lint warnings to sift through for every commit will make development easier going forward, so I definitely want this (or some alternative) merged as soon as possible.
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.
Spotted in TerriaJS#7272 where it was suggested to remove these, so remove them.
What this PR does
Fixes 215 remaining lint warnings, mostly unused params, functions and constants.
UrlTraits.ts
for example)Test me
yarn gulp lint
should return 0 warningsChecklist
doc/
.