Skip to content

Commit 18af942

Browse files
authored
chore: add no implicit coercion eslint rule (coder#3909)
* chore: add no-implicit-coercion ESLint rule This adds a new ESLint rule to prevent us from using implicit coercion in the codebase. See https://eslint.org/docs/latest/rules/no-implicit-coercion * chore: fix implicit coercion errors * fixup: formatting
1 parent bb0e79e commit 18af942

File tree

14 files changed

+20
-18
lines changed

14 files changed

+20
-18
lines changed

site/.eslintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ rules:
7878
- info
7979
- debug
8080
no-dupe-class-members: "off"
81+
no-implicit-coercion: "error"
8182
no-restricted-imports:
8283
- error
8384
- paths:

site/src/AppRouter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const AppRouter: FC = () => {
145145
<AuthAndFrame>
146146
<RequirePermission
147147
isFeatureVisible={
148-
featureVisibility[FeatureNames.AuditLog] && !!permissions?.viewAuditLog
148+
featureVisibility[FeatureNames.AuditLog] && Boolean(permissions?.viewAuditLog)
149149
}
150150
>
151151
<AuditPage />

site/src/components/ErrorSummary/ErrorSummary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const ErrorSummary: FC<React.PropsWithChildren<ErrorSummaryProps>> = ({
4949
<Stack direction="row" alignItems="center" className={styles.messageBox}>
5050
<Stack direction="row" spacing={0}>
5151
<span className={styles.errorMessage}>{message}</span>
52-
{!!detail && <Expander expanded={showDetails} setExpanded={setShowDetails} />}
52+
{Boolean(detail) && <Expander expanded={showDetails} setExpanded={setShowDetails} />}
5353
</Stack>
5454
{dismissible && (
5555
<IconButton onClick={closeError} className={styles.iconButton}>

site/src/components/LoadingButton/LoadingButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const LoadingButton: FC<React.PropsWithChildren<LoadingButtonProps>> = ({
2323
children,
2424
...rest
2525
}) => {
26-
const styles = useStyles({ hasLoadingLabel: !!loadingLabel })
26+
const styles = useStyles({ hasLoadingLabel: Boolean(loadingLabel) })
2727
const hidden = loading ? { opacity: 0 } : undefined
2828

2929
return (
@@ -34,7 +34,7 @@ export const LoadingButton: FC<React.PropsWithChildren<LoadingButtonProps>> = ({
3434
<CircularProgress size={18} className={styles.spinner} />
3535
</div>
3636
)}
37-
{!!loadingLabel && loadingLabel}
37+
{Boolean(loadingLabel) && loadingLabel}
3838
</Button>
3939
)
4040
}

site/src/components/Navbar/Navbar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export const Navbar: React.FC = () => {
1414
selectFeatureVisibility,
1515
shallowEqual,
1616
)
17-
const canViewAuditLog = featureVisibility[FeatureNames.AuditLog] && !!permissions?.viewAuditLog
17+
const canViewAuditLog =
18+
featureVisibility[FeatureNames.AuditLog] && Boolean(permissions?.viewAuditLog)
1819
const onSignOut = () => authSend("SIGN_OUT")
1920

2021
return <NavbarView user={me} onSignOut={onSignOut} canViewAuditLog={canViewAuditLog} />

site/src/components/SearchBarWithFilter/SearchBarWithFilter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const SearchBarWithFilter: React.FC<React.PropsWithChildren<SearchBarWith
4242
presetFilters,
4343
error,
4444
}) => {
45-
const styles = useStyles({ error: !!error })
45+
const styles = useStyles({ error: Boolean(error) })
4646

4747
const form = useFormik<FilterFormValues>({
4848
enableReinitialize: true,
@@ -108,7 +108,7 @@ export const SearchBarWithFilter: React.FC<React.PropsWithChildren<SearchBarWith
108108
id="query"
109109
name="query"
110110
value={form.values.query}
111-
error={!!error}
111+
error={Boolean(error)}
112112
className={styles.inputStyles}
113113
onChange={form.handleChange}
114114
startAdornment={

site/src/components/Tooltips/HelpTooltip/HelpTooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const HelpTooltip: React.FC<React.PropsWithChildren<HelpTooltipProps>> =
4040
}) => {
4141
const styles = useStyles({ size })
4242
const anchorRef = useRef<HTMLButtonElement>(null)
43-
const [isOpen, setIsOpen] = useState(!!open)
43+
const [isOpen, setIsOpen] = useState(Boolean(open))
4444
const id = isOpen ? "help-popover" : undefined
4545

4646
const onClose = () => {

site/src/components/UserDropdown/UsersDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const UserDropdown: React.FC<React.PropsWithChildren<UserDropdownProps>>
5151
<BorderedMenu
5252
anchorEl={anchorEl}
5353
getContentAnchorEl={null}
54-
open={!!anchorEl}
54+
open={Boolean(anchorEl)}
5555
anchorOrigin={{
5656
vertical: "bottom",
5757
horizontal: "right",

site/src/components/Workspace/Workspace.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
131131

132132
<WorkspaceStats workspace={workspace} handleUpdate={handleUpdate} />
133133

134-
{!!resources && !!resources.length && (
134+
{typeof resources !== "undefined" && resources.length > 0 && (
135135
<Resources
136136
resources={resources}
137137
getResourcesError={workspaceErrors[WorkspaceErrors.GET_RESOURCES_ERROR]}

site/src/components/WorkspaceActionButton/WorkspaceActionButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const WorkspaceActionButton: FC<React.PropsWithChildren<WorkspaceActionBu
1818
}) => {
1919
return (
2020
<Button className={className} startIcon={icon} onClick={onClick} aria-label={ariaLabel}>
21-
{!!label && label}
21+
{Boolean(label) && label}
2222
</Button>
2323
)
2424
}

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export const validationSchema = Yup.object({
164164
.test("positive-if-auto-stop", Language.errorNoStop, function (value) {
165165
const parent = this.parent as WorkspaceScheduleFormValues
166166
if (parent.autoStopEnabled) {
167-
return !!value
167+
return Boolean(value)
168168
} else {
169169
return true
170170
}

site/src/pages/TemplateSettingsPage/TemplateSettingsPageView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const TemplateSettingsPageView: FC<TemplateSettingsPageViewProps> = ({
3333

3434
return (
3535
<FullPageForm title={Language.title} onCancel={onCancel}>
36-
{!!errors.getTemplateError && <ErrorSummary error={errors.getTemplateError} />}
36+
{Boolean(errors.getTemplateError) && <ErrorSummary error={errors.getTemplateError} />}
3737
{isLoading && <Loader />}
3838
{template && (
3939
<TemplateSettingsForm

site/src/pages/WorkspacePage/WorkspacePage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const WorkspacePage: FC = () => {
4848
cancellationError,
4949
} = workspaceState.context
5050

51-
const canUpdateWorkspace = !!permissions?.updateWorkspace
51+
const canUpdateWorkspace = Boolean(permissions?.updateWorkspace)
5252

5353
const [bannerState, bannerSend] = useMachine(workspaceScheduleBannerMachine)
5454
const [buildInfoState] = useActor(xServices.buildInfoXService)
@@ -66,9 +66,9 @@ export const WorkspacePage: FC = () => {
6666
if (workspaceState.matches("error")) {
6767
return (
6868
<div className={styles.error}>
69-
{!!getWorkspaceError && <ErrorSummary error={getWorkspaceError} />}
70-
{!!refreshTemplateError && <ErrorSummary error={refreshTemplateError} />}
71-
{!!checkPermissionsError && <ErrorSummary error={checkPermissionsError} />}
69+
{Boolean(getWorkspaceError) && <ErrorSummary error={getWorkspaceError} />}
70+
{Boolean(refreshTemplateError) && <ErrorSummary error={refreshTemplateError} />}
71+
{Boolean(checkPermissionsError) && <ErrorSummary error={checkPermissionsError} />}
7272
</div>
7373
)
7474
} else if (!workspace || !permissions) {

site/src/util/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ export type AnnotatedEventListener<E extends Event> = (event: E) => void
4545
export const isCustomEvent = <D = unknown>(
4646
event: CustomEvent<D> | Event,
4747
): event is CustomEvent<D> => {
48-
return !!(event as CustomEvent).detail
48+
return Boolean((event as CustomEvent).detail)
4949
}

0 commit comments

Comments
 (0)