-
Notifications
You must be signed in to change notification settings - Fork 87
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
frontend: add eslint rule restrict-template-expressions #2325
frontend: add eslint rule restrict-template-expressions #2325
Conversation
15 problems 🎉
|
So that we do not accidentally pass undefined, null, booleans or just any type in tempalte literals, see: `all these should error ${false} ${undefined} ${[]} ${null}` This is a eslint rule, so only make weblint will check.
cd023a2
to
f8bccf4
Compare
Last commit introduced restrict-template-expressions, with this all reported problems should be fixed.
There seem to be no major edge cases using numbers in template literals and allowing them seems reasonable.
In c6ee6e0 the large prop on the SwissMadeOpenSource component was removed as it did not work since a long time and was for BitBox01 only, this commit removes the unused CSS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
partly pre-reviewd 😇
showQRCode: boolean; | ||
type State = { | ||
channel: string | null; | ||
status: string | false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed boolean
-> false
as it is initialized with false.
export const BitBoxSwissInverted = (props: GenericProps) => <img {...props} draggable={false} src={BitBoxSwissInvertedLogo} alt="BitBox" className={style.logo} />; | ||
export const Shift = (props: GenericProps) => <img {...props} draggable={false} src={ShiftLogo} alt="Shift Crypto" className={style.logo} />; | ||
export const SwissMadeOpenSource = ({ large: boolean, className, ...props }: GenericProps) => <img {...props} draggable={false} src={SwissOpenSourceLight} alt="Swiss Made Open Source" className={`${style.swissOpenSource} ${props.large ? style.large : ''} ${className ? className : ''}`} />; | ||
export const SwissMadeOpenSourceDark = ({ large: boolean, className, ...props }: GenericProps) => <img {...props} draggable={false} src={SwissOpenSourceDark} alt="Swiss Made Open Source" className={`${style.swissOpenSource} ${props.large ? style.large : ''} ${className ? className : ''}`} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed large
as this didn't work and props.large
was always undefined:
({ large, ...props }) => props.large // props.large is always undefined
@@ -56,23 +56,22 @@ import PAXG_GREY from './assets/paxg-white.svg'; | |||
import ShiftLogo from './assets/shift-cryptosecurity-logo.svg'; | |||
import style from './logo.module.css'; | |||
|
|||
interface GenericProps { | |||
[property: string]: any; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed and replaced by type ImgProps = JSX.IntrinsicElements['img'];
as we already do in icons.tsx
navigate(`/account/${code}/receive`); | ||
if (code) { | ||
navigate(`/account/${code}/receive`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit weird and could be cleaned up by refatoring AddBuyReceiveOnEmptyBalances and BuyReceiveCTA component.
I.e. balanceList is probably not really needed in BuyReceiveCTA and something like a boolean prop.isOnAccount
or similar may be enough
alertUser(this.props.t(`backup.restore.error.e${code}`, { | ||
defaultValue: errorMessage, | ||
})); | ||
if (typeof code === 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some un-typed BitBox01 backups specific api call.
We usually know what type when we use the src/api
backend calls, but here we call apiPost directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks a lot
@@ -41,7 +41,7 @@ export const Select = ({ | |||
<select id={id} {...props}> | |||
{options.map(({ value, text, disabled = false }) => ( | |||
<option | |||
key={`${value}`} | |||
key={String(value)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? I guess best practice, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without converting to string somehow i.e. String()
this will error with:
Type 'string | number | readonly string[] | undefined' is not assignable to type 'Key | null | undefined'.
Type 'readonly string[]' is not assignable to type 'Key | null | undefined'.ts(2322)
index.d.ts(261, 9): The expected type comes from property 'key' which is declared here on type 'DetailedHTMLProps<OptionHTMLAttributes<HTMLOptionElement>, HTMLOptionElement>'
(property) Attributes.key?: Key | null | undefined
We use the intrinsic element option (prob shouldn't :) ) this has the type value?: string | readonly string[] | number | undefined;
interface OptionHTMLAttributes<T> extends HTMLAttributes<T> {
disabled?: boolean | undefined;
label?: string | undefined;
selected?: boolean | undefined;
value?: string | readonly string[] | number | undefined;
}
So that we do not accidentally pass undefined, null, booleans or just any type in tempalte literals, see:
This is a eslint rule, so only make weblint will check.