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: several lint error fix #274

Merged
merged 4 commits into from
Jul 26, 2024

Conversation

MaikoTan
Copy link
Collaborator

@MaikoTan MaikoTan commented Jul 24, 2024

Reported in #271

Some are not actually fixed, but leave a FIXME comment whenever someone are willing to fix it.

@cactbotbot
Copy link
Collaborator

cactbotbot commented Jul 24, 2024

@MaikoTan Thanks for your contribution! 🌵🚀

@github-actions github-actions bot added resources /resources raidboss /ui/raidboss module config ui/config, ui/[module]/config util /util needs-review Awaiting review pullcounter /ui/pullcounter module labels Jul 24, 2024
@MaikoTan MaikoTan changed the title chore: several lint error fix lint: several lint error fix Jul 24, 2024
@MaikoTan MaikoTan requested a review from valarnin July 25, 2024 01:27
util/logtools/generate_triggers.ts Outdated Show resolved Hide resolved
console.error(`unknown output type: ${value.toString()}`);
console.error(`unknown output type: ${JSON.stringify(value)}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The linked PR doesn't mention the exact lint errors. What's the error that's being fixed with this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

\cactbot-workspace\cactbot\ui\raidboss\raidboss_config.ts
   530:43  error  'value' may evaluate to '[object Object]' when stringified     @typescript-eslint/no-base-to-string
   765:26  error  'trigFunc' may evaluate to '[object Object]' when stringified  @typescript-eslint/no-base-to-string
  1349:27  error  'result' may evaluate to '[object Object]' when stringified    @typescript-eslint/no-base-to-string

I am not sure, but ESLint keep complaining that you cannot just .toString() it since the value is possibly an object?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright, I see the issue here. I think this would benefit from a TODO or a FIXME comment, but otherwise the change to JSON.stringify makes sense.

Either this setter func can receive a nested object type as defined by the typedef for SavedConfigEntry, at which point it should handle that nested type properly, or it can't receive a nested type and the typedef for setOptionsFromOutputValue and the underlying type ConfigEntry should have its setterFunc fixed at some point in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I will add a FIXME comment here and then back to fix it in the future PR.

str += fieldValue;
str += fieldValue?.toString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The linked PR doesn't mention the exact lint errors. What's the error that's being fixed with this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

\cactbot\resources\regexes.ts
  324:16  error  Invalid operand for a '+' operation. Operands must each be a number or string, allowing a string + any of: `any`, `boolean`, `null`, `RegExp`, `undefined`. Got `readonly string[]`                                                                                                                  
                                                 @typescript-eslint/restrict-plus-operands
  324:16  error  Invalid operand for a '+' operation. Operands must each be a number or string, allowing a string + any of: `any`, `boolean`, `null`, `RegExp`, `undefined`. Got `RepeatingFieldsMap<T extends "CombatantMemory" ? T : never, (T extends "CombatantMemory" ? T : never) extends "CombatantMemory" ? T extends "CombatantMemory" ? T : never : never>`  @typescript-eslint/restrict-plus-operands

Same as above, but a different error reported.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the logic here in its entirety, can fieldName ever be undefined to fall through to this else case? The fieldName local maps to ParseHelperField's field property, which maps back to the fields property in netlog_defs.ts. which doesn't allow undefined as a key.

Could we just drop the entire if/else logic and change it to something like the following (included surrounding lines for context)?

    } else if (fields[keyStr]?.repeating) {
      // If this is a repeating field but the actual value is empty or otherwise invalid,
      // don't process further. We can't use `continue` in the above block because that
      // would skip the early-out break at the end of the loop.
    } else {
      str += Regexes.maybeCapture(
        // more accurate type instead of `as` cast
        // maybe this function needs a refactoring
        capture,
        fieldName,
        fieldValue,
        defaultFieldValue,
      );
    }

    // Stop if we're not capturing and don't care about future fields.
    if (key >= maxKey)
      break;

I haven't pulled the TS 5 upgrade PR down to test it locally yet, but TS 4 doesn't complain about this:

      const testFieldName: string = fieldName;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmmm, in this lint fixing PR I don't want to touch too much of the logic, maybe I can open a new PR for adjusting this logic and then back to this PR for the linting error fixing.

And yes, TS 5.0 improved a lot of inference of control flow, it is more sensitive about type errors in if-else blocks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you don't want to adjust logic in this PR that's fine, just add a comment with a TODO or FIXME for this one too? Feel free to link back to this comment thread, if you can't summarize the type narrowing logic in a single line comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I'll do so.

@github-actions github-actions bot removed the needs-review Awaiting review label Jul 25, 2024
@github-actions github-actions bot added the needs-review Awaiting review label Jul 26, 2024
Copy link
Collaborator

@valarnin valarnin left a comment

Choose a reason for hiding this comment

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

Pre-approving, pending comments below.

str += fieldValue;
str += fieldValue?.toString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the logic here in its entirety, can fieldName ever be undefined to fall through to this else case? The fieldName local maps to ParseHelperField's field property, which maps back to the fields property in netlog_defs.ts. which doesn't allow undefined as a key.

Could we just drop the entire if/else logic and change it to something like the following (included surrounding lines for context)?

    } else if (fields[keyStr]?.repeating) {
      // If this is a repeating field but the actual value is empty or otherwise invalid,
      // don't process further. We can't use `continue` in the above block because that
      // would skip the early-out break at the end of the loop.
    } else {
      str += Regexes.maybeCapture(
        // more accurate type instead of `as` cast
        // maybe this function needs a refactoring
        capture,
        fieldName,
        fieldValue,
        defaultFieldValue,
      );
    }

    // Stop if we're not capturing and don't care about future fields.
    if (key >= maxKey)
      break;

I haven't pulled the TS 5 upgrade PR down to test it locally yet, but TS 4 doesn't complain about this:

      const testFieldName: string = fieldName;

console.error(`unknown output type: ${value.toString()}`);
console.error(`unknown output type: ${JSON.stringify(value)}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright, I see the issue here. I think this would benefit from a TODO or a FIXME comment, but otherwise the change to JSON.stringify makes sense.

Either this setter func can receive a nested object type as defined by the typedef for SavedConfigEntry, at which point it should handle that nested type properly, or it can't receive a nested type and the typedef for setOptionsFromOutputValue and the underlying type ConfigEntry should have its setterFunc fixed at some point in the future.

@github-actions github-actions bot removed the needs-review Awaiting review label Jul 26, 2024
@MaikoTan MaikoTan merged commit f0085c8 into OverlayPlugin:main Jul 26, 2024
10 checks passed
@MaikoTan MaikoTan deleted the some-lint-error-fix branch July 26, 2024 07:08
github-actions bot pushed a commit that referenced this pull request Jul 26, 2024
Reported in #271

Some are not actually fixed, but leave a FIXME comment whenever someone
are willing to fix it. f0085c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config ui/config, ui/[module]/config pullcounter /ui/pullcounter module raidboss /ui/raidboss module resources /resources util /util
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants