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

Improve frontend lint settings #969

Merged

Conversation

DaoDaoNoCode
Copy link
Member

@DaoDaoNoCode DaoDaoNoCode commented Feb 21, 2023

Description

closes frontend part of #469

Frontend:

  1. Use ~/... instead of relative path
  2. Use return as needed (get rid of the return statement when there is only the return in the function body)
  3. Require to use curly for all the statements (if, while, etc...)
  4. Encourage to name variables in camelCase
  5. Prevent else return and absolute import from the src folder like services/**, pages/**, etc...
  6. Require to read all the methods in the ~/api folder not to use the specific file path
  7. Add no-console rule
  8. Add order rules for imports

How Has This Been Tested?

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress This PR is in WIP state label Feb 21, 2023
@DaoDaoNoCode DaoDaoNoCode changed the title [WIP] Improve lint settings Improve frontend lint settings Feb 23, 2023
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Feb 23, 2023
Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

@DaoDaoNoCode is there a reason we are not excluding from 'directory/file' now that we have ~? Eg frontend/src/services/notebookService.ts has import { RecursivePartial } from 'typeHelpers'; and you passed the linter.

export const allSettledPromises = <T, E extends unknown = undefined>(
export const allSettledPromises = <T, E = undefined>(
Copy link
Member

Choose a reason for hiding this comment

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

Interesting... not sure why I did that originally.

@DaoDaoNoCode
Copy link
Member Author

@andrewballantyne I thought of that, and at first, I tried to create a glob pattern matching like */**, but it will filter the imported from packages like react-dom/client. There are actually two ways, and I don't know which one is better.

  1. block all the path like */** and create an allowlist for the paths like ~/**, ./** and node packages we are using
  2. create a blocklist for the paths like services/**, types, pages/**, and don't block any other paths

Which option do you think is better?

@andrewballantyne
Copy link
Member

@andrewballantyne I thought of that, and at first, I tried to create a glob pattern matching like */**, but it will filter the imported from packages like react-dom/client. There are actually two ways, and I don't know which one is better.

  1. block all the path like */** and create an allowlist for the paths like ~/**, ./** and node packages we are using
  2. create a blocklist for the paths like services/**, types, pages/**, and don't block any other paths

Which option do you think is better?

Hmmmm -- are you sure there is no way to just block non npm dependencies? Surely there is a webpack setting or something; I swear I recall this being a thing 🤔 I'd be shocked if there was no way to stop root-level imports like from 'directory' because it should say "that's not an npm import", just thinking about it.

@Gkrumbach07
Copy link
Member

Gkrumbach07 commented Feb 27, 2023

Is there a reason to use the tilde ~/.... We can get the same effect of accessing root level folders by just omitting ~/

Example - these have the same outcome assuming folder structure has folder at the root level.

import { ... } from "folder"
import { ... } from "~/folder"

@openshift-merge-robot openshift-merge-robot added the needs-rebase PR needs to be rebased label Feb 27, 2023
@andrewballantyne
Copy link
Member

Is there a reason to use the tilde ~/.... We can get the same effect of accessing root level folders by just omitting ~/

Example - these have the same outcome assuming folder structure has folder at the root level.

import { ... } from "folder"
import { ... } from "~/folder"

Yuppers -- because import { ... } from 'thing' is an npm import. Overloading that has no value. Putting ~ prefix indicates that it is not an npm package.

Will we conflict with a folder and a npm package? Probably not... but it is the same as "why use ; at the end of every line". There are things we do for ease of use, common acceptance for new comers, and in general just a style we choose. I don't see any value in compounding concepts for ease of use.

Is there a reason you're against it @Gkrumbach07 ?

@openshift-merge-robot openshift-merge-robot removed the needs-rebase PR needs to be rebased label Feb 27, 2023
@Gkrumbach07
Copy link
Member

Is there a reason you're against it @Gkrumbach07 ?

Nope, it just seemed like extra chars at first glance. But the reasons to use it make sense

Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

Approving and merging to avoid the expected conflicts that will happen when ever single PR merges before this -- easier for them to adjust than for you to adjust.

One note I found with no-console... definitely can be a follow up though.

@@ -39,6 +40,7 @@ const useTimeBasedRefresh = (): SetTime => {
`We should have refreshed but it appears the last time we auto-refreshed was less than an hour ago. '${KEY_NAME}' session storage setting can be cleared for this to refresh again within the hour from the last refresh.`,
);
}
/* eslint-enable no-console */
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm... wonder if we can disable block disable/enables -- seems easy to abuse.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 28, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 1d27a18 into opendatahub-io:main Feb 28, 2023
@andrewballantyne andrewballantyne linked an issue Feb 28, 2023 that may be closed by this pull request
bartoszmajsak pushed a commit to maistra/odh-dashboard that referenced this pull request Mar 30, 2023
* update config of eslint, webpack, ts, jest and dependencies

* run lint fix command to get rid of most linting errors

* manually get rid of all the warnings and errors that cannot be auto fixed

* manually add ~ alias to all previous absolute imports in frontend

* add rule to prevent else return and absolute import from src folder

* another round of lint --fix

* move mock files and change imports

* add no-console rule and disable console as needed in code

* add restriction to import from api and change the rules of using absolute path. add no-param-reassign

* add order rule and run lint fix command

* remove baseUrl from tsconfig and make corresponding changes to eslintrc

---------

Co-authored-by: Andrew Ballantyne <8126518+andrewballantyne@users.noreply.github.com>
strangiato pushed a commit to strangiato/odh-dashboard that referenced this pull request Oct 18, 2023
* update config of eslint, webpack, ts, jest and dependencies

* run lint fix command to get rid of most linting errors

* manually get rid of all the warnings and errors that cannot be auto fixed

* manually add ~ alias to all previous absolute imports in frontend

* add rule to prevent else return and absolute import from src folder

* another round of lint --fix

* move mock files and change imports

* add no-console rule and disable console as needed in code

* add restriction to import from api and change the rules of using absolute path. add no-param-reassign

* add order rule and run lint fix command

* remove baseUrl from tsconfig and make corresponding changes to eslintrc

---------

Co-authored-by: Andrew Ballantyne <8126518+andrewballantyne@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Conversation]: Improve Linter Settings
4 participants