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

style(v2): reduce number of ESLint warnings #4993

Merged
merged 16 commits into from Jun 24, 2021
Merged

Conversation

@Josh-Cena
Copy link
Contributor

@Josh-Cena Josh-Cena commented Jun 17, 2021

Motivation

When I'm working on the project I was constantly overwhelmed (exaggeration here; there aren't so many) by ESLint warnings. Although they aren't serious issues, I decide it's better that we address these issues, since this is what we have the linter for.

There are some warnings that I probably need help with, especially regarding any types. (I realize how intractable typing objects can become.) I don't want to easily resort to eslint-disable comments.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

These are mostly style changes that don't really impact functionality to any degree.

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@Josh-Cena Josh-Cena requested review from lex111 and slorber as code owners Jun 17, 2021
@Josh-Cena Josh-Cena marked this pull request as draft Jun 17, 2021
@netlify
Copy link

@netlify netlify bot commented Jun 17, 2021

@github-actions
Copy link

@github-actions github-actions bot commented Jun 17, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 82
🟢 Accessibility 96
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4993--docusaurus-2.netlify.app/

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Copy link
Collaborator

@slorber slorber left a comment

thanks, not agreeing with everything but overwall happy to reduce eslint warnings

I personally like TS function return type inference but it seems to be a best practice to type return types explicitly so why not

@@ -127,7 +127,10 @@ function assertIsCategory(
);
}
// "collapsed" is an optional property
if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') {
if (
Object.prototype.hasOwnProperty.call(item, 'collapsed') &&

This comment has been minimized.

@slorber

slorber Jun 18, 2021
Collaborator

too much ceremony, I'd just replace by typeof item.collapsed !== "undefined" ?

This comment has been minimized.

@Josh-Cena

Josh-Cena Jun 18, 2021
Author Contributor

There is actually a consideration about collapsed existing on the prototype chain of item. Is it safe to assume here that typeof item.collapsed !== "undefined" works the same?

This comment has been minimized.

@slorber

slorber Jun 18, 2021
Collaborator

yes it looks to me as the sidebar is a regular object

This comment has been minimized.

@slorber

slorber Jun 24, 2021
Collaborator

can you replace with typeof item.collapsed !== "undefined" ? it has not been done here

Josh-Cena and others added 2 commits Jun 18, 2021
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
…x.tsx

Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
@Josh-Cena
Copy link
Contributor Author

@Josh-Cena Josh-Cena commented Jun 18, 2021

@slorber If I'm delving into typing (the any types), this PR is likely to shift its focus away from some simple style improvements. Should I do it here or should I open a new PR?

Josh-Cena added 2 commits Jun 18, 2021
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@slorber
Copy link
Collaborator

@slorber slorber commented Jun 18, 2021

@slorber If I'm delving into typing (the any types), this PR is likely to shift its focus away from some simple style improvements. Should I do it here or should I open a new PR?

smaller PRs are always easier to review/merge, so splitting the work is not a bad idea.

Josh-Cena added 4 commits Jun 18, 2021
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@Josh-Cena
Copy link
Contributor Author

@Josh-Cena Josh-Cena commented Jun 18, 2021

@slorber I think I'm mostly done—reduced warning count by >50. The rest of them (33) contain:

  • iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations

// async process made sequential on purpose! order matters
for (const doc of docs) {
// eslint-disable-next-line no-await-in-loop
await handleDocItem(doc);
}

Need some help here... Airbnb is complaining about for...of loops being too heavy. Would this be transformed to a reduce loop like this? I'm not so confident with async functions.

await docs.reduce(
  (p, doc) => p.then(() => handleDocItem(doc)),
  Promise.resolve(),
);
  • Visible, non-interactive elements with click handlers must have at least one keyboard listener

<div
className="react-toggle-track"
role="button"
tabIndex={-1}
onClick={() => inputRef.current?.click()}>

I see that we are planning to add hotkey binding maps. This warning will remind us of this feature :P

  • Lots of Unexpected any. Specify a different type errors. Need substantial typing improvements
Josh-Cena added 3 commits Jun 20, 2021
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@Josh-Cena Josh-Cena force-pushed the Josh-Cena:eslint-warn branch from 2f7ae4a to 1e8b06d Jun 21, 2021
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@Josh-Cena Josh-Cena marked this pull request as ready for review Jun 21, 2021
@Josh-Cena Josh-Cena requested a review from slorber Jun 21, 2021
@slorber
Copy link
Collaborator

@slorber slorber commented Jun 24, 2021

Need some help here... Airbnb is complaining about for...of loops being too heavy. Would this be transformed to a reduce loop like this? I'm not so confident with async functions.

Honestly don't like Airbnb preset, it's way too opinionated with weird rules, but it's the current docu preset so let's just disable what is annoying. This rule can also be disabled, it's not really applicable for NodeJS code IMHO.

I'll merge this PR as is, any further improvements are welcome

Copy link
Collaborator

@slorber slorber left a comment

finally, asking for a few changes 🤪

// eslint-disable-next-line no-await-in-loop
await handleDocItem(doc);
}
await docs.reduce(

This comment has been minimized.

@slorber

slorber Jun 24, 2021
Collaborator

actually I'd prefer to revert this change

This comment has been minimized.

@Josh-Cena

Josh-Cena Jun 24, 2021
Author Contributor

Although I reverted this, I'm pretty confident that the new code works correctly😂 Just that it is less readable

This comment has been minimized.

@slorber

slorber Jun 24, 2021
Collaborator

yes definitively works with reduce but much more complicated :)

@@ -127,7 +127,10 @@ function assertIsCategory(
);
}
// "collapsed" is an optional property
if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') {
if (
Object.prototype.hasOwnProperty.call(item, 'collapsed') &&

This comment has been minimized.

@slorber

slorber Jun 24, 2021
Collaborator

can you replace with typeof item.collapsed !== "undefined" ? it has not been done here

packages/docusaurus/src/server/configValidation.ts Outdated Show resolved Hide resolved
@Josh-Cena
Copy link
Contributor Author

@Josh-Cena Josh-Cena commented Jun 24, 2021

Okay cool. Lemme address those...

Josh-Cena added 2 commits Jun 24, 2021
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
@slorber
Copy link
Collaborator

@slorber slorber commented Jun 24, 2021

thanks 👍

@slorber slorber merged commit 462b1cf into facebook:master Jun 24, 2021
14 checks passed
14 checks passed
@github-actions
lint
Details
@github-actions
build
Details
@github-actions
build
Details
@github-actions
build
Details
@github-actions
build
Details
@github-actions
test (12)
Details
@github-actions
yarn-v1 (12)
Details
@github-actions
build (12)
Details
@github-actions
test (14)
Details
@github-actions
yarn-v1 (14)
Details
@github-actions
build (14)
Details
@github-actions
yarn-v2 (14)
Details
@facebook-github-tools
Facebook CLA Check Contributor License Agreement is valid!
Details
@netlify
deploy/netlify Deploy Preview ready!
Details
@Josh-Cena Josh-Cena deleted the Josh-Cena:eslint-warn branch Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants