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

Refactor to improve types for validateTypes and whitespaceChecker #6002

Merged
merged 1 commit into from Mar 31, 2022

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Mar 31, 2022

Which issue, if any, is this issue related to?

Part of #5983

Is there anything in the PR that needs further explanation?

This refactoring does the following:

  • Move utility functions in lib/utils/whitespaceChecker.js to lib/utils/validateTypes.js
  • Add new utility functions to validateTypes.js
  • Add a unit test for validateTypes.js
  • Resolve type errors in whitespaceChecker.js via the noUncheckedIndexedAccess TypeScript compiler option

We can see the error resolution via the following commands:

$ git checkout tsconfig-noUncheckedIndexedAccess -- tsconfig.json

$ npm run lint:types

) {
return;
}

assertFunction(messageFunc);
activeArgs.err(messageFunc(activeArgs.errTarget || source[index]));
activeArgs.err(messageFunc(activeArgs.errTarget || source.charAt(index)));
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] source[index] can return undefined, while source.charAt(index) always returns a string. See the charAt() doc:

If index is out of range, charAt() returns an empty string.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt

I think it safe to use charAt() in this case to build an error message.

@ybiquitous ybiquitous marked this pull request as ready for review March 31, 2022 01:38
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Nice. LGTM, thank you!

@ybiquitous
Copy link
Member Author

@jeddy3 Thank you for the review.

@ybiquitous ybiquitous merged commit 788c3ba into main Mar 31, 2022
@ybiquitous ybiquitous deleted the refactor-validateTypes branch March 31, 2022 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants