Skip to content

Commit

Permalink
fix: address all lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
haworku committed Jul 14, 2020
1 parent 5f8442f commit 76fc669
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/components/forms/RangeInput/RangeInput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { render, queryByText } from '@testing-library/react'
import { render } from '@testing-library/react'

import { RangeInput } from './RangeInput'

Expand Down
27 changes: 21 additions & 6 deletions src/components/grid/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type GridLayoutProp = {
}

export const getGridClasses = (
itemProps: GridItemProps,
itemProps: GridItemProps = {},
breakpoint?: BreakpointKeys
): string => {
// This should be fine bc TypeScript
Expand All @@ -38,6 +38,7 @@ export const applyGridClasses = (gridLayout: GridProps): string => {
Object.keys(breakpoints).forEach((b) => {
const bp = b as BreakpointKeys
if (Object.prototype.hasOwnProperty.call(gridLayout, bp)) {
// eslint-disable-next-line security/detect-object-injection
const bpProps = gridLayout[bp] as GridItemProps
classes = classnames(classes, getGridClasses(bpProps, bp))
}
Expand All @@ -52,28 +53,42 @@ export const Grid = ({
...props
}: GridProps & React.HTMLAttributes<HTMLDivElement>): React.ReactElement => {
const {
// defaults
row,
col,
gap,
offset,
// breakpoint specific
mobile,
mobileLg,
tablet,
tabletLg,
desktop,
desktopLg,
widescreen,
// other
...otherProps
} = props

let classes = getGridClasses(props)
const itemProps = {
row,
col,
gap,
offset,
}

const breakpointProps = {
mobile,
mobileLg,
tablet,
tabletLg,
desktop,
desktopLg,
widescreen,
}
let classes = getGridClasses(itemProps)

Object.keys(breakpoints).forEach((b) => {
const bp = b as BreakpointKeys
if (Object.prototype.hasOwnProperty.call(props, bp)) {
if (Object.prototype.hasOwnProperty.call(breakpointProps, bp)) {
// eslint-disable-next-line security/detect-object-injection
const bpProps = props[bp] as GridItemProps
classes = classnames(classes, getGridClasses(bpProps, bp))
}
Expand Down
53 changes: 16 additions & 37 deletions src/components/header/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ const mockSubmit = (): void => {
/* mock submit fn */
}

const onToggle = (
index: number,
setIsOpen: React.Dispatch<React.SetStateAction<boolean[]>>
): void => {
setIsOpen((prevIsOpen) => {
const newIsOpen = [false, false]
// eslint-disable-next-line security/detect-object-injection
newIsOpen[index] = !prevIsOpen[index]
return newIsOpen
})
}
export const BasicHeader = (): React.ReactElement => {
const [expanded, setExpanded] = useState(false)
const onClick = (): void => setExpanded((prvExpanded) => !prvExpanded)
Expand All @@ -40,20 +51,12 @@ export const BasicHeader = (): React.ReactElement => {

const [isOpen, setIsOpen] = useState([false, false])

const onToggle = (index: number): void => {
setIsOpen((prevIsOpen) => {
const newIsOpen = Array(prevIsOpen.length).fill(false)
newIsOpen[index] = !prevIsOpen[index]
return newIsOpen
})
}

const testItemsMenu = [
<>
<NavDropDownButton
menuId="testDropDownOne"
onToggle={(): void => {
onToggle(0)
onToggle(0, setIsOpen)
}}
isOpen={isOpen[0]}
label="Nav Label"
Expand Down Expand Up @@ -139,19 +142,11 @@ export const BasicHeaderWithMegaMenu = (): React.ReactElement => {

const [isOpen, setIsOpen] = useState([false, false])

const onToggle = (index: number): void => {
setIsOpen((prevIsOpen) => {
const newIsOpen = [false, false]
newIsOpen[index] = !prevIsOpen[index]
return newIsOpen
})
}

const testItemsMegaMenu = [
<>
<NavDropDownButton
onToggle={(): void => {
onToggle(0)
onToggle(0, setIsOpen)
}}
menuId="testDropDownOne"
isOpen={isOpen[0]}
Expand All @@ -168,7 +163,7 @@ export const BasicHeaderWithMegaMenu = (): React.ReactElement => {
<>
<NavDropDownButton
onToggle={(): void => {
onToggle(1)
onToggle(1, setIsOpen)
}}
menuId="testDropDownTwo"
isOpen={isOpen[1]}
Expand Down Expand Up @@ -215,14 +210,6 @@ export const extendedHeader = (): React.ReactElement => {
const onClick = (): void => setExpanded((prvExpanded) => !prvExpanded)
const [isOpen, setIsOpen] = useState([false])

const onToggle = (index: number): void => {
setIsOpen((prevIsOpen) => {
const newIsOpen = Array(prevIsOpen.length).fill(false)
newIsOpen[index] = !prevIsOpen[index]
return newIsOpen
})
}

const testMenuItems = [
<a href="#linkOne" key="one">
Simple link one
Expand All @@ -236,7 +223,7 @@ export const extendedHeader = (): React.ReactElement => {
<>
<NavDropDownButton
onToggle={(): void => {
onToggle(0)
onToggle(0, setIsOpen)
}}
menuId="testDropDownOne"
isOpen={isOpen[0]}
Expand Down Expand Up @@ -311,19 +298,11 @@ export const extendedHeaderWithMegaMenu = (): React.ReactElement => {

const [isOpen, setIsOpen] = useState([false, false])

const onToggle = (index: number): void => {
setIsOpen((prevIsOpen) => {
const newIsOpen = Array(prevIsOpen.length).fill(false)
newIsOpen[index] = !prevIsOpen[index]
return newIsOpen
})
}

const testItemsMenu = [
<>
<NavDropDownButton
onToggle={(): void => {
onToggle(0)
onToggle(0, setIsOpen)
}}
menuId="testDropDownOne"
isOpen={isOpen[0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const defaultDropDownMenu = (): React.ReactElement => {
const onToggle = (index: number): void => {
setIsOpen((prevIsOpen) => {
const newIsOpen = [false, false]
// eslint-disable-next-line security/detect-object-injection
newIsOpen[index] = !prevIsOpen[index]
return newIsOpen
})
Expand Down
3 changes: 2 additions & 1 deletion src/deprecation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const deprecationWarning =
process.env.NODE_ENV !== 'production'
? console.warn
: () => {
: // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
() => {
// do nothing in production
}
1 change: 1 addition & 0 deletions src/stories/templates/documentation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const DocumentationPage = (): React.ReactElement => {
const handleToggleNavDropdown = (index: number): void => {
setNavDropdownOpen((prevNavDropdownOpen) => {
const newOpenState = Array(prevNavDropdownOpen.length).fill(false)
// eslint-disable-next-line security/detect-object-injection
newOpenState[index] = !prevNavDropdownOpen[index]
return newOpenState
})
Expand Down
1 change: 1 addition & 0 deletions src/stories/templates/landing.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const LandingPage = (): React.ReactElement => {
const handleToggleNavDropdown = (index: number): void => {
setNavDropdownOpen((prevNavDropdownOpen) => {
const newOpenState = Array(prevNavDropdownOpen.length).fill(false)
// eslint-disable-next-line security/detect-object-injection
newOpenState[index] = !prevNavDropdownOpen[index]
return newOpenState
})
Expand Down

0 comments on commit 76fc669

Please sign in to comment.