Skip to content

Commit aad054c

Browse files
authored
Use oxlint for pre-commit lint, fix errors (#2592)
use oxlint for pre-commit lint, fix errors
1 parent d97310b commit aad054c

File tree

13 files changed

+182
-722
lines changed

13 files changed

+182
-722
lines changed

.husky/pre-commit

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
npx lint-staged
1+
# use path directly instead of npx or npm run because it's way faster
2+
node_modules/.bin/oxlint --deny-warnings

.oxlintrc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"plugins": ["react", "react-hooks", "unicorn", "typescript", "oxc"],
4+
"rules": {
5+
"react-hooks/exhaustive-deps": "error",
6+
// turning this off because it's more sensitive than eslint currently
7+
// "react-hooks/rules-of-hooks": "error",
8+
"no-unused-vars": [
9+
"error",
10+
{
11+
"argsIgnorePattern": "^_",
12+
"varsIgnorePattern": "^_",
13+
"caughtErrorsIgnorePattern": "^_"
14+
}
15+
]
16+
}
17+
}

app/components/TimeSeriesChart.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ function getTicks(data: { timestamp: number }[], n: number): number[] {
3333
const maxIdx = data.length > 10 ? Math.floor((data.length - 1) * 0.8) : data.length - 1
3434
const startOffset = Math.floor((data.length - maxIdx) * 0.6)
3535
// if there are 4 ticks, their positions are 0/3, 1/3, 2/3, 3/3 (as fractions of maxIdx)
36-
const idxs = new Array(n)
37-
.fill(0)
38-
.map((_, i) => Math.floor((maxIdx * i) / (n - 1) + startOffset))
36+
const idxs = Array.from({ length: n }).map((_, i) =>
37+
Math.floor((maxIdx * i) / (n - 1) + startOffset)
38+
)
3939
return idxs.map((i) => data[i].timestamp)
4040
}
4141

4242
function getVerticalTicks(n: number, max: number): number[] {
43-
const idxs = new Array(n).fill(0)
44-
return idxs.map((_, i) => Math.floor(((i + 1) / n) * max))
43+
return Array.from({ length: n }).map((_, i) => Math.floor(((i + 1) / n) * max))
4544
}
4645

4746
/**

app/pages/project/vpcs/VpcPage/tabs/VpcGatewaysTab.tsx

-7
This file was deleted.

app/ui/lib/Badge.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const All = () => {
1212
return (
1313
<div className="flex flex-wrap">
1414
{Object.entries(badgeColors).flatMap(([variant, colors]) => (
15-
<Section title={variant}>
15+
<Section title={variant} key={variant}>
1616
{Object.keys(colors).map((color) => (
1717
<div key={`${variant}-${color}`}>
1818
<Badge variant={variant as BadgeVariant} color={color as BadgeColor}>

app/ui/lib/Button.stories.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*
66
* Copyright Oxide Computer Company
77
*/
8+
import React from 'react'
9+
810
import { Section } from '../util/story-section'
911
import { Button, variants } from './Button'
1012

@@ -21,14 +23,14 @@ export const All = () => {
2123
<Section key={state} title={state}>
2224
<div className="mb-2 flex flex-row space-x-2">
2325
{variants.map((variant) => (
24-
<>
26+
<React.Fragment key={variant}>
2527
<Button key={variant} variant={variant} className={`:${state}`}>
2628
{variant}
2729
</Button>
2830
<Button key={variant} variant={variant} className={`:${state}`} loading>
2931
{variant}
3032
</Button>
31-
</>
33+
</React.Fragment>
3234
))}
3335
</div>
3436
</Section>

app/ui/lib/CalendarGrid.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function CalendarGrid({ state, ...props }: CalendarGridProps) {
3636
</tr>
3737
</thead>
3838
<tbody>
39-
{[...new Array(weeksInMonth).keys()].map((weekIndex) => (
39+
{[...Array.from({ length: weeksInMonth }).keys()].map((weekIndex) => (
4040
<tr key={weekIndex}>
4141
{state
4242
.getDatesInWeek(weekIndex)

mock-api/disk.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export const disks: Json<Disk>[] = [
147147
block_size: 2048,
148148
},
149149
// put a ton of disks in project 2 so we can use it to test comboboxes
150-
...new Array(1010).fill(0).map((_, i) => {
150+
...Array.from({ length: 1010 }).map((_, i) => {
151151
const numStr = (i + 1).toString().padStart(4, '0')
152152
return {
153153
id: '9747d936-795d-4d76-8ee0-15561f4cbb' + numStr,

mock-api/msw/handlers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const handlers = makeHandlers({
174174

175175
return {
176176
items: genCumulativeI64Data(
177-
new Array(1000).fill(0).map((_x, i) => Math.floor(Math.tanh(i / 500) * 3000)),
177+
Array.from({ length: 1000 }).map((_x, i) => Math.floor(Math.tanh(i / 500) * 3000)),
178178
startTime,
179179
endTime
180180
),

mock-api/msw/util.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('paginated', () => {
2121
})
2222

2323
it('should return the first 100 items with no limit passed', () => {
24-
const items = new Array(200).fill(0).map((_, i) => ({ id: 'i' + i }))
24+
const items = Array.from({ length: 200 }).map((_, i) => ({ id: 'i' + i }))
2525
const page = paginated({}, items)
2626
expect(page.items.length).toBe(100)
2727
expect(page.items).toEqual(items.slice(0, 100))

mock-api/msw/util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const paginated = <P extends PaginateOptions, I extends { id: string }>(
7272
// make a bunch of copies of an object with different names and IDs. useful for
7373
// testing pagination
7474
export const repeat = <T extends { id: string; name: string }>(obj: T, n: number): T[] =>
75-
new Array(n).fill(0).map((_, i) => ({ ...obj, id: obj.id + i, name: obj.name + i }))
75+
Array.from({ length: n }).map((_, i) => ({ ...obj, id: obj.id + i, name: obj.name + i }))
7676

7777
export function getStartAndEndTime(params: { startTime?: Date; endTime?: Date }) {
7878
// if no start time or end time, give the last 24 hours. in this case the
@@ -209,7 +209,7 @@ export function generateUtilization(
209209

210210
// Pick a reasonable start value
211211
const startVal = 500
212-
const values = new Array<number>(dataCount)
212+
const values = Array.from<number>({ length: dataCount })
213213
values[0] = startVal
214214

215215
let x = 0

0 commit comments

Comments
 (0)