Skip to content
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

chore(lint): make eslint run, fix errors #9361

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions design-system/packages/core/src/components/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ function useRadii (
{ rounding, roundingTop, roundingRight, roundingBottom, roundingLeft }: RadiiProps,
{ radii }: Theme
) {
let borderBottomLeftRadius = roundingBottom || roundingLeft || rounding
let borderBottomRightRadius = roundingBottom || roundingRight || rounding
let borderTopLeftRadius = roundingTop || roundingLeft || rounding
let borderTopRightRadius = roundingTop || roundingRight || rounding
const borderBottomLeftRadius = roundingBottom || roundingLeft || rounding
const borderBottomRightRadius = roundingBottom || roundingRight || rounding
const borderTopLeftRadius = roundingTop || roundingLeft || rounding
const borderTopRightRadius = roundingTop || roundingRight || rounding

return {
borderBottomLeftRadius:
Expand All @@ -208,10 +208,10 @@ function usePadding (
}: PaddingProps,
{ spacing }: Theme
) {
let pb = paddingBottom || paddingY || padding
let pt = paddingTop || paddingY || padding
let pl = paddingLeft || paddingX || padding
let pr = paddingRight || paddingX || padding
const pb = paddingBottom || paddingY || padding
const pt = paddingTop || paddingY || padding
const pl = paddingLeft || paddingX || padding
const pr = paddingRight || paddingX || padding

return {
paddingBottom: pb && mapResponsiveProp(pb, spacing),
Expand All @@ -225,10 +225,10 @@ function useMargin (
{ margin, marginTop, marginRight, marginBottom, marginLeft, marginY, marginX }: MarginProps,
{ spacing }: Theme
) {
let mb = marginBottom || marginY || margin
let mt = marginTop || marginY || margin
let ml = marginLeft || marginX || margin
let mr = marginRight || marginX || margin
const mb = marginBottom || marginY || margin
const mt = marginTop || marginY || margin
const ml = marginLeft || marginX || margin
const mr = marginRight || marginX || margin

return {
marginBottom: mb && mapResponsiveProp(mb, spacing),
Expand Down
2 changes: 1 addition & 1 deletion design-system/packages/core/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { jsx } from '../emotion'
import { useTheme } from '../theme'
import { forwardRefWithAs } from '../utils'

export const Link = forwardRefWithAs<'a', {}>(({ as: Tag = 'a', ...props }, ref) => {
export const Link = forwardRefWithAs<'a', unknown>(({ as: Tag = 'a', ...props }, ref) => {
const { typography, colors } = useTheme()

const styles = {
Expand Down
2 changes: 1 addition & 1 deletion design-system/packages/fields/src/FieldContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/** @jsx jsx */
import { jsx, forwardRefWithAs } from '@keystone-ui/core'

export const FieldContainer = forwardRefWithAs<'div', {}>(({ as: Tag = 'div', ...props }, ref) => {
export const FieldContainer = forwardRefWithAs<'div', unknown>(({ as: Tag = 'div', ...props }, ref) => {
return <Tag ref={ref} {...props} />
})
10 changes: 5 additions & 5 deletions design-system/packages/fields/src/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type SwitchControlProps = {

export const SwitchControl = forwardRef<HTMLButtonElement, SwitchControlProps>(
({ a11yLabels = { on: 'On', off: 'Off' }, checked = false, onChange, ...props }, ref) => {
let onClick = () => {
const onClick = () => {
if (onChange) {
onChange(!checked)
}
Expand All @@ -64,10 +64,10 @@ export const SwitchControl = forwardRef<HTMLButtonElement, SwitchControlProps>(
const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
const { animation, fields, sizing } = useTheme()

let gutter = 3
let trackHeight = sizing.xsmall + gutter
let trackWidth = trackHeight * 2 - 2 * gutter
let handleSize = trackHeight - gutter * 2
const gutter = 3
const trackHeight = sizing.xsmall + gutter
const trackWidth = trackHeight * 2 - 2 * gutter
const handleSize = trackHeight - gutter * 2

return (
<button
Expand Down
2 changes: 1 addition & 1 deletion design-system/packages/icons/src/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const sizeMap = {
}

export const createIcon = (children: ReactNode, name: string) => {
let Icon = forwardRef<SVGSVGElement, IconProps>(
const Icon = forwardRef<SVGSVGElement, IconProps>(
({ size = 'medium', color, ...props }: IconProps, ref: any) => {
const resolvedSize = typeof size === 'number' ? size : mapResponsiveProp(size, sizeMap)

Expand Down
8 changes: 4 additions & 4 deletions design-system/packages/modals/src/DrawerBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const DrawerBase = ({
const uniqueKey = makeId('drawer', id)

// sync drawer state
let drawerDepth = useDrawerManager(uniqueKey)
const drawerDepth = useDrawerManager(uniqueKey)

const onKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && !event.defaultPrevented) {
Expand All @@ -71,7 +71,7 @@ export const DrawerBase = ({
let Tag: 'div' | 'form' = 'div'
if (onSubmit) {
Tag = 'form'
let oldOnSubmit = onSubmit
const oldOnSubmit = onSubmit
// @ts-expect-error
onSubmit = (event: any) => {
if (!event.defaultPrevented) {
Expand Down Expand Up @@ -134,8 +134,8 @@ export const DrawerBase = ({
// ------------------------------

function getDialogTransition (depth: number) {
let scaleInc = 0.05
let transformValue = `scale(${1 - scaleInc * depth}) translateX(-${depth * 40}px)`
const scaleInc = 0.05
const transformValue = `scale(${1 - scaleInc * depth}) translateX(-${depth * 40}px)`

return {
entering: { transform: 'translateX(100%)' },
Expand Down
2 changes: 1 addition & 1 deletion design-system/packages/modals/src/DrawerController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DrawerControllerContext = React.createContext<null | TransitionState>(null
export const DrawerControllerContextProvider = DrawerControllerContext.Provider

export const useDrawerControllerContext = () => {
let context = useContext(DrawerControllerContext)
const context = useContext(DrawerControllerContext)
if (!context) {
throw new Error(
'Drawers must be wrapped in a <DrawerController>. You should generally do this outside of the component that renders the <Drawer> or <TabbedDrawer>.'
Expand Down
6 changes: 3 additions & 3 deletions design-system/packages/modals/src/drawer-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export type ModalState = {
const ModalContext = React.createContext<ModalState | null>(null)

export const DrawerProvider = ({ children }: { children: ReactNode }) => {
let [drawerStack, setDrawerStack] = useState<string[]>([])
const [drawerStack, setDrawerStack] = useState<string[]>([])

const pushToDrawerStack = useCallback((key: string) => {
setDrawerStack(stack => [...stack, key])
}, [])
const popFromDrawerStack = useCallback(() => {
setDrawerStack(stack => {
let less = stack.slice(0, -1)
const less = stack.slice(0, -1)
return less
})
}, [])
Expand Down Expand Up @@ -50,7 +50,7 @@ export const useDrawerManager = (uniqueKey: string) => {
}, [])
// the last key in the array is the "top" modal visually, so the depth is the inverse index
// be careful not to mutate the stack
let depth = modalState.drawerStack.slice().reverse().indexOf(uniqueKey)
const depth = modalState.drawerStack.slice().reverse().indexOf(uniqueKey)
// if it's not in the stack already,
// we know that it should be the last drawer in the stack but the effect hasn't happened yet
// so we need to make the depth 0 so the depth is correct even though the effect hasn't happened yet
Expand Down
8 changes: 4 additions & 4 deletions design-system/packages/popover/src/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ type UseClickOutsideProps = {
const useClickOutside = ({ handler, elements, listenWhen }: UseClickOutsideProps) => {
useEffect(() => {
if (listenWhen) {
let handleMouseDown = (event: MouseEvent) => {
const handleMouseDown = (event: MouseEvent) => {
// bail on mouse down "inside" any of the provided elements
if (elements.some(el => el && el.contains(event.target as Node))) {
return
Expand Down Expand Up @@ -300,8 +300,8 @@ const useKeyPress = ({

// add event listeners
useEffect(() => {
let target = targetElement || document.body
let onDown = (event: KeyboardEvent) => {
const target = targetElement || document.body
const onDown = (event: KeyboardEvent) => {
if (event.key === targetKey) {
setKeyPressed(true)

Expand All @@ -310,7 +310,7 @@ const useKeyPress = ({
}
}
}
let onUp = (event: KeyboardEvent) => {
const onUp = (event: KeyboardEvent) => {
if (event.key === targetKey) {
setKeyPressed(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export const SegmentedControl = ({
// Animate the selected segment indicator
useEffect(() => {
if (animate && rootRef.current instanceof HTMLElement) {
let nodes = Array.from(rootRef.current.children)
let selected = selectedIndex !== undefined && nodes[selectedIndex]
const nodes = Array.from(rootRef.current.children)
const selected = selectedIndex !== undefined && nodes[selectedIndex]
let rootRect
let nodeRect = { height: 0, width: 0, left: 0, top: 0 }
let offsetLeft
Expand Down
4 changes: 2 additions & 2 deletions design-system/packages/toast/src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function ToastProvider ({ children }: { children: ReactNode }) {
}

// populate defaults and update state
let toast = populateDefaults(options)
const toast = populateDefaults(options)
return [...currentStack, toast]
})
},
Expand Down Expand Up @@ -68,7 +68,7 @@ export function ToastProvider ({ children }: { children: ReactNode }) {
// ------------------------------

let idCount = -1
let genId = () => ++idCount
const genId = () => ++idCount
function populateDefaults (props: ToastProps): ToastPropsExact {
return {
title: props.title,
Expand Down
2 changes: 1 addition & 1 deletion design-system/website/pages/components/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const StatefulSwitch = ({ children, ...props }: ComponentProps<typeof Switch>) =
}

const BasicDatePicker = () => {
let [value, setValue] = useState<DateType>('')
const [value, setValue] = useState<DateType>('')
return (
<Stack gap="small">
<pre>{value || 'no value'}</pre>
Expand Down
6 changes: 3 additions & 3 deletions design-system/website/pages/components/modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { Drawer, DrawerController, AlertDialog } from '@keystone-ui/modals'
import { Page } from '../../components/Page'

export default function ModalsPage () {
let [isNarrowOpen, setIsNarrowOpen] = useState(false)
let [isWideOpen, setIsWideOpen] = useState(false)
let [isAlertDialogOpen, setIsAlertDialogOpen] = useState(false)
const [isNarrowOpen, setIsNarrowOpen] = useState(false)
const [isWideOpen, setIsWideOpen] = useState(false)
const [isAlertDialogOpen, setIsAlertDialogOpen] = useState(false)

return (
<Page>
Expand Down
2 changes: 1 addition & 1 deletion design-system/website/pages/components/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const props: ComponentProps<typeof CheckMark>[] = [
]

export default function OptionsPage () {
let [value, setValue] = useState<undefined | { label: string, value: string }>()
const [value, setValue] = useState<undefined | { label: string, value: string }>()
return (
<Page>
<h1>Options</h1>
Expand Down
7 changes: 3 additions & 4 deletions docs/components/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { Field } from './primitives/Field'
import { Stack } from './primitives/Stack'
import { Type } from './primitives/Type'

const validEmail = (email: string) =>
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(
email
)
function validEmail (email: string) {
return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(email)
}

const enquiryUrl = 'https://endpoints.thinkmill.com.au/enquiry'

Expand Down
4 changes: 2 additions & 2 deletions docs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export function Header () {
useEffect(() => {
document.body.style.overflow = 'auto'
// search - init field
let searchAttempt = 0
const searchAttempt = 0
// @ts-expect-error
document.getElementById('search-field').disabled = true
const loadSearch = (searchAttempt: number) => {
Expand Down Expand Up @@ -308,7 +308,7 @@ export function Header () {
// yoo hooo
loadSearch(searchAttempt)
// search - keyboard shortcut
let keysPressed: { [key: KeyboardEvent['key']]: boolean } = {}
const keysPressed: { [key: KeyboardEvent['key']]: boolean } = {}
document.body.addEventListener('keydown', (event) => {
// If we're typing in an input, don't ever focus the search input
if (
Expand Down
2 changes: 1 addition & 1 deletion docs/components/docs/DocumentEditorDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function objToShorthand<
Obj extends Record<string, undefined | true | readonly any[] | Record<string, any>>
> (obj: Obj): Obj | true | undefined {
const values = Object.values(obj)
let state: (typeof values)[number] = values[0]!
const state: (typeof values)[number] = values[0]!
for (const val of values) {
if (val !== state || (val !== undefined && val !== true)) {
return obj
Expand Down
10 changes: 5 additions & 5 deletions docs/components/docs/TableOfContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export function TableOfContents ({
container: React.RefObject<HTMLElement | null>
headings: Heading[]
}) {
let [visibleIds, setVisibleIds] = useState<Array<string | null>>([])
let [lastVisibleId, setLastVisbleId] = useState<string | null>(null)
const [visibleIds, setVisibleIds] = useState<Array<string | null>>([])
const [lastVisibleId, setLastVisbleId] = useState<string | null>(null)

const mq = useMediaQuery()

// observe relevant headings

useEffect(() => {
if (container.current) {
let allIds = headings.map(h => h.id)
const allIds = headings.map(h => h.id)
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
const targetId: string | null = entry.target.getAttribute('id')
Expand All @@ -62,7 +62,7 @@ export function TableOfContents ({
}, [container, headings])

// catch if we're in a long gap between headings and resolve to the last available.
let activeId = visibleIds[0] || lastVisibleId
const activeId = visibleIds[0] || lastVisibleId

return (
<div id="toc">
Expand All @@ -87,7 +87,7 @@ export function TableOfContents ({
</Type>
<ul css={{ listStyle: 'none', margin: 0, padding: 0 }}>
{headings.map((h: Heading, i: number) => {
let isActive = activeId === h.id
const isActive = activeId === h.id
const slug = `#${h.id}`
return (
<li
Expand Down
18 changes: 9 additions & 9 deletions docs/components/primitives/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type Range = { start: number, end: number }
type CollapseRange = Range & { isCollapsed: boolean }

const getRanges = (lines: string): Range[] => {
let ranges: Range[] = []
const ranges: Range[] = []

lines.split(',').forEach((lineRange) => {
if (lineRange.length) {
const [range1, range2] = lineRange.split('-')

let parsedRange1 = parseInt(range1)
let parsedRange2 = parseInt(range2)
const parsedRange2 = parseInt(range2)

if (isNaN(parsedRange1)) {
throw new Error(`When trying to do highlighting, error in {${lines}}`)
Expand All @@ -41,24 +41,24 @@ const getRanges = (lines: string): Range[] => {
const parseClassName = (
className?: string
): { highlightRanges: Range[], collapseRanges: CollapseRange[], language: string } => {
let trimmedLanguage = (className || '').replace(/language-/, '')
const trimmedLanguage = (className || '').replace(/language-/, '')
let language, highlights, collapses

if (
!trimmedLanguage.includes('[') ||
trimmedLanguage.indexOf('{') < trimmedLanguage.indexOf('[')
) {
let [scopedLanguage, modifiers = ''] = trimmedLanguage.split('{')
const [scopedLanguage, modifiers = ''] = trimmedLanguage.split('{')

let [scopedHighlights, scopedCollapses] = modifiers.split('[')
const [scopedHighlights, scopedCollapses] = modifiers.split('[')

language = scopedLanguage
highlights = scopedHighlights
collapses = scopedCollapses
} else {
let [scopedLanguage, modifiers = ''] = trimmedLanguage.split('[')
const [scopedLanguage, modifiers = ''] = trimmedLanguage.split('[')

let [scopedCollapses, scopedHighlights] = modifiers.split('{')
const [scopedCollapses, scopedHighlights] = modifiers.split('{')

language = scopedLanguage
highlights = scopedHighlights
Expand Down Expand Up @@ -92,7 +92,7 @@ export function CodeBlock (props: { children: string, className?: string }) {
}

export function Code ({ children, className }: { children: string, className?: string }) {
let { language, highlightRanges, collapseRanges } = useMemo(
const { language, highlightRanges, collapseRanges } = useMemo(
() => parseClassName(className),
[className]
)
Expand Down Expand Up @@ -120,7 +120,7 @@ export function Code ({ children, className }: { children: string, className?: s
<button
key={i}
onClick={() => {
let updated = collapseState.map((item) =>
const updated = collapseState.map((item) =>
item.start === i ? { ...item, isCollapsed: false } : item
)

Expand Down
Loading
Loading