fix eslint vs. prettier

This commit is contained in:
Samuel Colvin
2023-11-12 19:25:07 +00:00
parent 8730d637a2
commit 759a8e36ad
9 changed files with 21 additions and 20 deletions

View File

@@ -6,8 +6,9 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'prettier',
],
ignorePatterns: ['dist', '.eslintrc.cjs', 'vite.config.ts'],
ignorePatterns: ['dist', '.eslintrc.cjs', 'demo/vite.config.ts'],
parser: '@typescript-eslint/parser',
plugins: ['react', '@typescript-eslint', 'react-refresh', 'simple-import-sort'],
rules: {

View File

@@ -15,7 +15,7 @@ export const HeadingComp: FC<HeadingProps> = (props) => {
return <HeadingComponent text={text} className={useClassNameGenerator(className, props)} />
}
function getComponent (level: 1 | 2 | 3 | 4 | 5 | 6): FC<{ text: string; className: string }> {
function getComponent(level: 1 | 2 | 3 | 4 | 5 | 6): FC<{ text: string; className: string }> {
switch (level) {
case 1:
return ({ text, className }) => <h1 className={className}>{text}</h1>

View File

@@ -81,7 +81,7 @@ interface WithChildren {
children: FastProps[]
}
function renderWithChildren<T extends WithChildren> (Component: FC<T>, props: T) {
function renderWithChildren<T extends WithChildren>(Component: FC<T>, props: T) {
const { children, ...rest } = props
// TODO is there a way to make this type safe?
return <Component {...(rest as any)}>{children}</Component>

View File

@@ -68,7 +68,7 @@ const request = async ({ url, method, headers, body }: Request): Promise<FastPro
return data as FastProps
}
export function FastUIController ({ rootUrl, pathSendMode, loading }: Props) {
export function FastUIController({ rootUrl, pathSendMode, loading }: Props) {
const [componentProps, setComponentProps] = useState<FastProps | null>(null)
const { fullPath } = useContext(LocationContext)

View File

@@ -14,7 +14,7 @@ export const ClassNameContext = createContext<ClassNameGenerator | null>(null)
* @param props The full props object sent from the backend, this is passed to the class name generator.
* @param dft default className to use if the class name generator is not set or returns undefined.
*/
export function useClassNameGenerator (classNameProp: ClassName, props: FastProps, dft?: ClassName): string {
export function useClassNameGenerator(classNameProp: ClassName, props: FastProps, dft?: ClassName): string {
const classNameGenerator = useContext(ClassNameContext)
if (combineClassNameProp(classNameProp)) {
if (!dft && classNameGenerator) {
@@ -33,7 +33,7 @@ export function useClassNameGenerator (classNameProp: ClassName, props: FastProp
* then we generate the default className and append the user's className to it.
* @param classNameProp
*/
function combineClassNameProp (classNameProp: ClassName): boolean {
function combineClassNameProp(classNameProp: ClassName): boolean {
if (Array.isArray(classNameProp)) {
// classNameProp is an array, check if it contains `+`
return classNameProp.some((c) => c === '+')
@@ -49,7 +49,7 @@ function combineClassNameProp (classNameProp: ClassName): boolean {
}
}
function combine (cn1: ClassName, cn2: ClassName): string {
function combine(cn1: ClassName, cn2: ClassName): string {
if (!cn1) {
return renderClassName(cn2)
} else if (!cn2) {
@@ -63,7 +63,7 @@ function combine (cn1: ClassName, cn2: ClassName): string {
* Renders the className to a string, removing plus signs.
* @param className
*/
export function renderClassName (className: ClassName): string {
export function renderClassName(className: ClassName): string {
if (typeof className === 'string') {
return className.replace(/^\+ /, '')
} else if (Array.isArray(className)) {

View File

@@ -30,7 +30,7 @@ const DefaultErrorDisplay: ErrorDisplayType = ({ title, description, children })
export const ErrorContext = createContext<ErrorContextType>({
error: null,
setError: () => null,
DisplayError: DefaultErrorDisplay
DisplayError: DefaultErrorDisplay,
})
const MaybeError: FC<{ children: ReactNode }> = ({ children }) => {
@@ -55,7 +55,7 @@ export const ErrorContextProvider: FC<Props> = ({ DisplayError, children }) => {
console.warn('setting error:', error)
setErrorState(error)
},
[setErrorState]
[setErrorState],
)
const contextValue: ErrorContextType = { error, setError, DisplayError: DisplayError ?? DefaultErrorDisplay }

View File

@@ -12,14 +12,14 @@ export interface GoToEvent {
url: string
}
function pageEventType (event: PageEvent): string {
function pageEventType(event: PageEvent): string {
return `fastui:${event.name}`
}
export function useFireEvent (): { fireEvent: (event?: PageEvent | GoToEvent) => void } {
export function useFireEvent(): { fireEvent: (event?: PageEvent | GoToEvent) => void } {
const location = useContext(LocationContext)
function fireEvent (event?: PageEvent | GoToEvent) {
function fireEvent(event?: PageEvent | GoToEvent) {
if (!event) {
return
}
@@ -38,7 +38,7 @@ export function useFireEvent (): { fireEvent: (event?: PageEvent | GoToEvent) =>
return { fireEvent }
}
export function useEventListenerToggle (event?: PageEvent, initialState = false): [boolean, () => void] {
export function useEventListenerToggle(event?: PageEvent, initialState = false): [boolean, () => void] {
const [state, setState] = useState(initialState)
const toggle = useCallback(() => setState((state) => !state), [])

View File

@@ -2,7 +2,7 @@ import { createContext, ReactNode, useEffect, useState, useCallback, useContext
import { ErrorContext } from './error'
function parseLocation (): string {
function parseLocation(): string {
const { href, origin } = window.location
// remove origin from the beginning of href
return href.slice(origin.length)
@@ -17,12 +17,12 @@ const initialPath = parseLocation()
const initialState = {
fullPath: initialPath,
goto: () => null
goto: () => null,
}
export const LocationContext = createContext<LocationState>(initialState)
export function LocationProvider ({ children }: { children: ReactNode }) {
export function LocationProvider({ children }: { children: ReactNode }) {
const [fullPath, setFullPath] = useState(initialPath)
const { setError } = useContext(ErrorContext)
@@ -66,8 +66,8 @@ export function LocationProvider ({ children }: { children: ReactNode }) {
setError(null)
setFullPath(newPath)
},
[setError]
)
[setError],
),
}
return <LocationContext.Provider value={value}>{children}</LocationContext.Provider>

View File

@@ -20,7 +20,7 @@ export interface FastUIProps {
customRender?: CustomRender
}
export function FastUI (props: FastUIProps) {
export function FastUI(props: FastUIProps) {
const { classNameGenerator, DisplayError, customRender, ...rest } = props
return (
<div className="fastui">