Skip to content

Commit 1bf2dc0

Browse files
authored
chore: add explicit-length-check eslint rule (coder#4147)
* chore: add eslint rule explicit-length-check * fix: add explicit-length-check
1 parent 5698b9d commit 1bf2dc0

File tree

13 files changed

+74
-10
lines changed

13 files changed

+74
-10
lines changed

site/.eslintrc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ plugins:
3030
- react-hooks
3131
- jest
3232
- no-storage
33+
- unicorn
3334
root: true
3435
rules:
3536
"@typescript-eslint/brace-style":
@@ -119,6 +120,7 @@ rules:
119120
react/jsx-key: error
120121
react/jsx-uses-react: "off"
121122
react/react-in-jsx-scope: "off"
123+
"unicorn/explicit-length-check": "error"
122124
settings:
123125
react:
124126
version: detect

site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"eslint-plugin-no-storage": "1.0.2",
111111
"eslint-plugin-react": "7.31.1",
112112
"eslint-plugin-react-hooks": "4.6.0",
113+
"eslint-plugin-unicorn": "^43.0.2",
113114
"html-webpack-plugin": "5.5.0",
114115
"jest": "27.5.1",
115116
"jest-canvas-mock": "2.4.0",

site/src/components/CodeBlock/CodeBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const CodeBlock: FC<React.PropsWithChildren<CodeBlockProps>> = ({
2525
</div>
2626
))}
2727
</div>
28-
{ctas && ctas.length && (
28+
{ctas && ctas.length > 0 && (
2929
<div className={styles.ctaBar}>
3030
{ctas.map((cta, i) => {
3131
return <Fragment key={i}>{cta}</Fragment>

site/src/components/LicenseBanner/LicenseBanner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const LicenseBanner: React.FC = () => {
1313
entitlementsSend("GET_ENTITLEMENTS")
1414
}, [entitlementsSend])
1515

16-
if (warnings.length) {
16+
if (warnings.length > 0) {
1717
return <LicenseBannerView warnings={warnings} />
1818
} else {
1919
return null

site/src/components/SearchBarWithFilter/SearchBarWithFilter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const SearchBarWithFilter: React.FC<React.PropsWithChildren<SearchBarWith
112112
/>
113113
</div>
114114

115-
{presetFilters && presetFilters.length ? (
115+
{presetFilters && presetFilters.length > 0 ? (
116116
<Menu
117117
id="filter-menu"
118118
anchorEl={anchorEl}

site/src/components/UsersTable/UsersTableBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const UsersTableBody: FC<React.PropsWithChildren<UsersTableBodyProps>> =
5353
return <TableLoader />
5454
}
5555

56-
if (!users || !users.length) {
56+
if (!users || users.length === 0) {
5757
return (
5858
<TableRow>
5959
<TableCell colSpan={999}>

site/src/components/WorkspacesTable/WorkspacesTableBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const WorkspacesTableBody: FC<React.PropsWithChildren<TableBodyProps>> =
3333
return <TableLoader />
3434
}
3535

36-
if (!workspaceRefs || !workspaceRefs.length) {
36+
if (!workspaceRefs || workspaceRefs.length === 0) {
3737
return (
3838
<>
3939
{filter === workspaceFilterQuery.me || filter === workspaceFilterQuery.all ? (

site/src/pages/TerminalPage/TerminalPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const renderTerminal = () => {
3838
const expectTerminalText = (container: HTMLElement, text: string) => {
3939
return waitFor(() => {
4040
const elements = container.getElementsByClassName("xterm-rows")
41-
if (elements.length < 1) {
41+
if (elements.length === 0) {
4242
throw new Error("no xterm-rows")
4343
}
4444
const row = elements[0] as HTMLDivElement

site/src/util/combineClasses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ export const combineClasses = (
3838
}
3939
}
4040

41-
return result.length ? result : undefined
41+
return result.length > 0 ? result : undefined
4242
}

site/src/util/schedule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const stripTimezone = (raw: string): string => {
4242
export const extractTimezone = (raw: string, defaultTZ = DEFAULT_TIMEZONE): string => {
4343
const matches = raw.match(/CRON_TZ=\S*\s/g)
4444

45-
if (matches && matches.length) {
45+
if (matches && matches.length > 0) {
4646
return matches[0].replace(/CRON_TZ=/, "").trim()
4747
} else {
4848
return defaultTZ

0 commit comments

Comments
 (0)