Skip to content

Commit 8c30305

Browse files
authored
Disallow default exports with linter, get rid of existing ones (#2050)
disallow default exports with linter. named exports are a best practice
1 parent 53709d2 commit 8c30305

31 files changed

+932
-454
lines changed

.eslintrc.cjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ module.exports = {
1515
'plugin:react/recommended',
1616
'prettier',
1717
'plugin:react-hook-form/recommended',
18+
'plugin:import/recommended',
19+
],
20+
plugins: [
21+
'@typescript-eslint',
22+
'react-hooks',
23+
'prettier',
24+
'jsx-a11y',
25+
'react-hook-form',
26+
'import',
1827
],
19-
plugins: ['@typescript-eslint', 'react-hooks', 'prettier', 'jsx-a11y', 'react-hook-form'],
2028
settings: {
2129
react: {
2230
version: 'detect',
@@ -35,6 +43,8 @@ module.exports = {
3543
'@typescript-eslint/no-non-null-assertion': 'off',
3644
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
3745
eqeqeq: ['error', 'always', { null: 'ignore' }],
46+
'import/no-default-export': 'error',
47+
'import/no-unresolved': 'off', // plugin doesn't know anything
3848
'jsx-a11y/label-has-associated-control': [2, { controlComponents: ['button'] }],
3949
'no-param-reassign': 'error',
4050
'no-restricted-imports': [
@@ -64,6 +74,11 @@ module.exports = {
6474
},
6575
ignorePatterns: ['dist/'],
6676
overrides: [
77+
{
78+
// default export is needed in config files
79+
files: ['*.config.ts'],
80+
rules: { 'import/no-default-export': 'off' },
81+
},
6782
{
6883
files: ['*.js'],
6984
rules: {

app/components/EquivalentCliCommand.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Success12Icon } from '@oxide/design-system/icons/react'
1111

1212
import { Button } from '~/ui/lib/Button'
1313
import { Modal } from '~/ui/lib/Modal'
14-
import useTimeout from '~/ui/lib/use-timeout'
14+
import { useTimeout } from '~/ui/lib/use-timeout'
1515

1616
export function EquivalentCliCommand({ command }: { command: string }) {
1717
const [isOpen, setIsOpen] = useState(false)

app/components/RefetchIntervalPicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Refresh16Icon, Time16Icon } from '@oxide/design-system/icons/react'
1313

1414
import { Listbox, type ListboxItem } from '~/ui/lib/Listbox'
1515
import { SpinnerLoader } from '~/ui/lib/Spinner'
16-
import useInterval from '~/ui/lib/use-interval'
16+
import { useInterval } from '~/ui/lib/use-interval'
1717

1818
const intervalPresets = {
1919
Off: undefined,

app/components/RoundedSector.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useEffect, useMemo, useState } from 'react'
99

1010
import { useReducedMotion } from '~/hooks'
1111

12-
const RoundedSector = ({
12+
export function RoundedSector({
1313
angle,
1414
size,
1515
thickness,
@@ -19,7 +19,7 @@ const RoundedSector = ({
1919
size: number
2020
thickness: number
2121
cornerRadius?: number
22-
}) => {
22+
}) {
2323
const prefersReducedMotion = useReducedMotion()
2424
const [interpolatedAngle, setInterpolatedAngle] = useState(0)
2525

@@ -290,5 +290,3 @@ const polarToCartesian = (cx: number, cy: number, radius: number, angle: number)
290290
x: cx + Math.cos((-Math.PI / 180) * angle) * radius,
291291
y: cy + Math.sin((-Math.PI / 180) * angle) * radius,
292292
})
293-
294-
export default RoundedSector

app/components/Terminal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ interface TerminalProps {
6161
ws: WebSocket
6262
}
6363

64-
export const Terminal = ({ ws }: TerminalProps) => {
64+
// default export is most convenient for dynamic import
65+
// eslint-disable-next-line import/no-default-export
66+
export default function Terminal({ ws }: TerminalProps) {
6567
const [term, setTerm] = useState<XTerm | null>(null)
6668
const terminalRef = useRef<HTMLDivElement>(null)
6769

@@ -114,5 +116,3 @@ export const Terminal = ({ ws }: TerminalProps) => {
114116
</>
115117
)
116118
}
117-
118-
export default Terminal

app/components/TimeSeriesChart.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function roundUpToDivBy(value: number, divisor: number) {
120120
return Math.ceil(value / divisor) * divisor
121121
}
122122

123+
// default export is most convenient for dynamic import
124+
// eslint-disable-next-line import/no-default-export
123125
export default function TimeSeriesChart({
124126
className,
125127
data: rawData,

app/components/form/fields/DisksTableField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useController, type Control } from 'react-hook-form'
1111
import type { DiskCreate } from '@oxide/api'
1212
import { Error16Icon } from '@oxide/design-system/icons/react'
1313

14-
import AttachDiskSideModalForm from '~/forms/disk-attach'
14+
import { AttachDiskSideModalForm } from '~/forms/disk-attach'
1515
import { CreateDiskSideModalForm } from '~/forms/disk-create'
1616
import type { InstanceCreateInput } from '~/forms/instance-create'
1717
import { Badge } from '~/ui/lib/Badge'

app/components/form/fields/NetworkInterfaceField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
import { Error16Icon } from '@oxide/design-system/icons/react'
1616

1717
import type { InstanceCreateInput } from '~/forms/instance-create'
18-
import CreateNetworkInterfaceForm from '~/forms/network-interface-create'
18+
import { CreateNetworkInterfaceForm } from '~/forms/network-interface-create'
1919
import { Button } from '~/ui/lib/Button'
2020
import { FieldLabel } from '~/ui/lib/FieldLabel'
2121
import * as MiniTable from '~/ui/lib/MiniTable'

app/forms/disk-attach.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,3 @@ export function AttachDiskSideModalForm({
6464
</SideModalForm>
6565
)
6666
}
67-
68-
export default AttachDiskSideModalForm

app/forms/network-interface-create.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type CreateNetworkInterfaceFormProps = {
3737
* Can be used with either a `setState` or a real mutation as `onSubmit`, hence
3838
* the optional `loading` and `submitError`
3939
*/
40-
export default function CreateNetworkInterfaceForm({
40+
export function CreateNetworkInterfaceForm({
4141
onSubmit,
4242
onDismiss,
4343
loading,

0 commit comments

Comments
 (0)