-
Notifications
You must be signed in to change notification settings - Fork 31
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
Prefer nullish coalescing and optional chaining #6715
Conversation
f9c1f27
to
39153a8
Compare
Size Change: -4.1 kB (0%) Total Size: 2.31 MB
ℹ️ View Unchanged
|
⚡️ Lighthouse report for the changes in this PRLighthouse tested 2 URLs Report for Article
Report for Front
|
dfdbd9d
to
f6a9c35
Compare
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 pointers below
@@ -11,7 +11,7 @@ const captionStyle = css` | |||
padding-top: 10px; | |||
${textSans.xxsmall()}; | |||
word-wrap: break-word; | |||
color: ${text.supporting}; | |||
color: ${neutral[46]}; |
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.
Pass-by refactor…
{formField.options.map((option, index) => ( | ||
<option key={index} value={option.value}> | ||
{option.value} | ||
</option> | ||
))} |
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.
The compiler thinks this is always defined
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- window.guardian may be missing? | ||
if (window?.guardian) { |
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.
Not sure about that one, but I assumed it was added for a reason
const isPaidContent = !!tags.find( | ||
({ id }) => id === 'tone/advertisement-features', | ||
); |
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.
Seems like we use this in several places…
@@ -78,7 +78,7 @@ type Props = { | |||
* @see https://github.com/guardian/dotcom-rendering/blob/main/dotcom-rendering/src/web/browser/debug/README.md | |||
*/ | |||
containerName?: string; | |||
/** Fronts containers can have their styling overidden using a `containerPalette` */ | |||
/** Fronts containers can have their styling overridden using a `containerPalette` */ |
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.
Pass-by refactor
typeof CAPIArticle.starRating === | ||
'number' |
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 is actually what we want, as star rating could be 0
const fileAsBase64 = reader.result | ||
?.toString() | ||
.split(';base64,')[1]; |
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.
The compiler thinks reader is always defined
f6a9c35
to
6cae568
Compare
@@ -6,10 +6,12 @@ export const findPillar: ( | |||
tags?: TagType[], | |||
) => ArticleTheme | undefined = (name, tags?) => { | |||
// Flag paid content for Labs pillar (for styling purposes) | |||
const isPaidContent = (tag: TagType) => | |||
tag.type === 'Tone' && tag.id === 'tone/advertisement-features'; | |||
const hasPaidContent = !!tags?.some( |
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.
doesn't this coerce tags
into a boolean? can you call some
on that?
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.
TypeScript thinks it’s fine, as per the precedence table
6cae568
to
3b2cf5a
Compare
587a609
to
9d72165
Compare
"This PR is stale because it has been open 30 days with no activity. Unless a comment is added or the “stale” label removed, this will be closed in 3 days" |
// This is not safe to remove whilst we have noUncheckedIndexedAccess | ||
'@typescript-eslint/no-unnecessary-condition': 'warn', |
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.
Can this change now then?
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.
Waiting on your PR 😉
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 :) Nice tidy!
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.
Love it!
9d72165
to
2d22f28
Compare
The following rules are now reported as errors: - nullish coalescing - optional chaining This aligns us closer to the Guardian’s house rules
2d22f28
to
605a5f6
Compare
What does this change?
Enforce nullish coalescing and optional chaining linting rules.
Why?
They are the default in the
@guardian/eslint-config-typescript
and convey the intent of the logic better.Part of #4935 and #5863