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

Lint fixes #7272

Merged
merged 7 commits into from
Sep 26, 2024
Merged

Lint fixes #7272

merged 7 commits into from
Sep 26, 2024

Conversation

ljowen
Copy link
Contributor

@ljowen ljowen commented Sep 17, 2024

What this PR does

Fixes 215 remaining lint warnings, mostly unused params, functions and constants.

  • Add eslint-disable comments for:

Test me

  • Verify tests pass and app working as expected
  • yarn gulp lint should return 0 warnings

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

@@ -33,10 +33,10 @@ const transitionEnd = (element: Element | null) =>
});

const animationTimeout = (
timeoutID: ReturnType<typeof setTimeout> | undefined
_timeoutID: ReturnType<typeof setTimeout> | undefined
Copy link
Contributor Author

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)

Copy link
Contributor

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",
Copy link
Contributor

@zoran995 zoran995 Sep 17, 2024

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.

Copy link
Contributor Author

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

.eslintrc Show resolved Hide resolved
@@ -920,6 +920,6 @@ function toNumber(value: string): number | null {
return null;
}

function nullFunction(rowIndex: number) {
function nullFunction() {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

@pjonsson
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

@ljowen ljowen Sep 24, 2024

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?

Copy link
Collaborator

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 () {
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will update

@@ -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 =
Copy link
Contributor

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?

Copy link
Contributor

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) => {
Copy link
Contributor

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.

Copy link
Contributor Author

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

@@ -49,7 +49,7 @@ describe("NewStuff", function () {
);
});

autorun((dispose) => {
autorun((_dispose) => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted

@CLAassistant
Copy link

CLAassistant commented Sep 24, 2024

CLA assistant check
All committers have signed the CLA.

ljowen and others added 7 commits September 24, 2024 13:58
- 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
Copy link
Contributor

@pjonsson pjonsson left a 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.

@ljowen ljowen requested a review from na9da September 25, 2024 01:43
Copy link
Collaborator

@na9da na9da left a comment

Choose a reason for hiding this comment

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

@ljowen looks good to me. Just the one comment on removing the _previousTarget = model lines. I also concur with @pjonsson and @zoran995 on not turning off the lint rules so that future code is checked. Please update the PR description to reflect that change.

@ljowen ljowen merged commit 268d1d4 into main Sep 26, 2024
9 checks passed
@ljowen ljowen deleted the lint-fixes branch September 26, 2024 05:00
@pjonsson pjonsson mentioned this pull request Sep 27, 2024
4 tasks
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.

5 participants