Skip to content

Commit

Permalink
polish: format all files by ESLint Stylistic
Browse files Browse the repository at this point in the history
  • Loading branch information
zthxxx committed Dec 4, 2024
1 parent 52e28d4 commit d7f4974
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 89 deletions.
15 changes: 8 additions & 7 deletions docs/components/features/features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ export function Feature({
{...props}
>
{children}
{href
? (
<Link className={styles.link} href={href} target='_blank'>
<ArrowRightIcon width='1.5em' />
</Link>
)
: null
{
href
? (
<Link className={styles.link} href={href} target='_blank'>
<ArrowRightIcon width='1.5em' />
</Link>
)
: null
}
</motion.div>
)
Expand Down
3 changes: 2 additions & 1 deletion docs/components/marquee/marquee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const Marquee: FC<PropsWithChildren<MarqueeOptions>> = ({
delay = '0s',
iteration = 'infinite',
}) => {
if (!Children.count(children)) return null
if (!Children.count(children))
return null

return (
<div
Expand Down
3 changes: 2 additions & 1 deletion docs/components/stack-blitz/stack-blitz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const StackBlitz = ({
hideExplorer?: boolean;
showDevtools?: boolean;
}) => {
if (isDev) return null
if (isDev)
return null

// https://developer.stackblitz.com/guides/integration/embedding#embed-url-options
const params: Record<string, string | number | undefined> = {
Expand Down
2 changes: 1 addition & 1 deletion examples/umi4/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import 'umi/typings';
import 'umi/typings'
3 changes: 1 addition & 2 deletions packages/babel-plugin/src/tests/babel-plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path'
import { transformSync } from '@babel/core'
import type { TransformOptions } from '@babel/core'
import { transformSync, type TransformOptions } from '@babel/core'
import globby from 'globby'
import pluginTester from 'babel-plugin-tester'
import InspectorBabelPlugin, { type InspectorPluginOptions } from '..'
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-plugin/src/tests/fixtures/layouts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import { Global } from '@emotion/react'
import { Inspector } from 'react-dev-inspector'
import type { InspectParams } from 'react-dev-inspector'
import { Inspector, type InspectParams } from 'react-dev-inspector'
import { Title } from './components/Title'
import { Slogan } from './components/Slogan'
import { KeyPad, Keypress } from './components/Keypress'
Expand All @@ -17,7 +16,8 @@ export const HomePage = () => {
disableLaunchEditor={!isDev}
onClickElement={(inspect: InspectParams) => {
console.debug(inspect)
if (isDev || !inspect.codeInfo?.relativePath) return
if (isDev || !inspect.codeInfo?.relativePath)
return

const {
relativePath,
Expand Down
16 changes: 10 additions & 6 deletions packages/babel-plugin/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export const createVisitor = ({ cwd = process.cwd(), excludes }: {
JSXOpeningElement: {
enter(path, state: PluginPass) {
const filePath = state?.file?.opts?.filename
if (!filePath) return
if (isExclude(filePath)) return
if (!filePath)
return
if (isExclude(filePath))
return

const relativePath = pathRelative(filePath)

Expand All @@ -57,7 +59,8 @@ export const createVisitor = ({ cwd = process.cwd(), excludes }: {
* simple path match method, only use string and regex
*/
export const pathMatch = (filePath: string, matches?: (string | RegExp)[]): boolean => {
if (!matches?.length) return false
if (!matches?.length)
return false

return matches.some((match) => {
if (typeof match === 'string') {
Expand Down Expand Up @@ -85,11 +88,12 @@ const doJSXPathName: NodeHandler<JSXOpeningElement['name']> = (name) => {
}

export const doJSXOpeningElement: NodeHandler<
JSXOpeningElement,
{ relativePath: string }
JSXOpeningElement,
{ relativePath: string }
> = (node, option) => {
const { stop } = doJSXPathName(node.name)
if (stop) return { stop }
if (stop)
return { stop }

const { relativePath } = option
const line = node.loc?.start.line
Expand Down
3 changes: 2 additions & 1 deletion packages/inspector/src/Inspector/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const getCodeInfo = (_codeInfo: CodeInfoLike): CodeInfo => (
export const gotoServerEditor = (_codeInfo?: CodeInfoLike, options?: {
editor?: TrustedEditor;
}) => {
if (!_codeInfo) return
if (!_codeInfo)
return
const codeInfo = getCodeInfo(_codeInfo)

const {
Expand Down
23 changes: 14 additions & 9 deletions packages/inspector/src/Inspector/utils/fiber.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { Fiber } from 'react-reconciler'

// eslint-disable-next-line unused-imports/no-unused-imports
import type { InspectAgent } from '../types'


Expand Down Expand Up @@ -31,7 +29,8 @@ const cachedFiberKeys: Set<string> = new Set()
* like: https://github.com/facebook/react/blob/v17.0.0/packages/react-dom/src/client/ReactDOM.js#L220
*/
const getFiberWithDevtoolHook = (element: any): Fiber | undefined => {
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__?.renderers) return
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__?.renderers)
return

const { renderers } = window.__REACT_DEVTOOLS_GLOBAL_HOOK__

Expand Down Expand Up @@ -90,9 +89,11 @@ export const getElementFiber = (_element?: Element): Fiber | undefined => {
}

export const getElementFiberUpward = (element: Element | null | undefined): Fiber | undefined => {
if (!element) return undefined
if (!element)
return undefined
const fiber = getElementFiber(element)
if (fiber) return fiber
if (fiber)
return fiber
return getElementFiberUpward(element.parentElement)
}

Expand Down Expand Up @@ -150,8 +151,10 @@ export function * genFiberSourceChain(fiber?: Fiber | null): Generator<Fiber, vo
*/
export const getFiberName = (fiber?: Fiber | null): string | undefined => {
const fiberType = fiber?.type
if (!fiberType) return undefined
if (typeof fiberType === 'string') return fiberType
if (!fiberType)
return undefined
if (typeof fiberType === 'string')
return fiberType

const { displayName, name } = fiberType

Expand Down Expand Up @@ -277,8 +280,10 @@ export const getDisplayNameForFiber = (fiber: Fiber): string | null => {
* https://github.com/facebook/react/blob/v18.3.0/packages/react-devtools-shared/src/backend/renderer.js#L418
*/
const resolveFiberType = (type: any): (() => void) | null => {
if (!type) return null
if (typeof type === 'function') return type
if (!type)
return null
if (typeof type === 'function')
return type
if (typeof type === 'object' && '$$typeof' in type) {
switch (type.$$typeof) {
case Symbol.for('react.memo'): {
Expand Down
27 changes: 18 additions & 9 deletions packages/inspector/src/Inspector/utils/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
* https://github.com/facebook/react/blob/v18.0.0/packages/react-reconciler/src/ReactFiber.new.js#L648-L649
*/
export const getCodeInfoFromDebugSource = (fiber?: Fiber): CodeInfo | undefined => {
if (!fiber) return undefined
if (!fiber)
return undefined

/**
* only find forward with 2 level _debugOwner, otherwise to normal `fiber.return`
Expand All @@ -44,7 +45,8 @@ export const getCodeInfoFromDebugSource = (fiber?: Fiber): CodeInfo | undefined
?? fiber._debugOwner?._debugOwner?._debugSource
) as Source & { columnNumber?: number }

if (!debugSource) return undefined
if (!debugSource)
return undefined

const {
fileName,
Expand Down Expand Up @@ -76,7 +78,8 @@ export const getCodeInfoFromDebugSource = (fiber?: Fiber): CodeInfo | undefined
* code location data-attribute props inject by `@react-dev-inspector/babel-plugin`
*/
export const getCodeInfoFromProps = (fiber?: Fiber): CodeInfo | undefined => {
if (!fiber?.pendingProps) return undefined
if (!fiber?.pendingProps)
return undefined

const {
'data-inspector-line': lineNumber,
Expand All @@ -101,7 +104,8 @@ export const getCodeInfoFromFiber = (fiber?: Fiber): CodeInfo | undefined => {
getCodeInfoFromProps(fiber),
].filter(Boolean) as CodeInfo[]

if (!codeInfos.length) return undefined
if (!codeInfos.length)
return undefined
return Object.assign({}, ...codeInfos)
}

Expand Down Expand Up @@ -151,10 +155,12 @@ export const getCodeInfoFromFiber = (fiber?: Fiber): CodeInfo | undefined => {
* └─ div
*/
export const getReferenceFiber = (baseFiber?: Fiber): Fiber | undefined => {
if (!baseFiber) return undefined
if (!baseFiber)
return undefined

const directParent = getDirectParentFiber(baseFiber)
if (!directParent) return undefined
if (!directParent)
return undefined

const isParentNative = isNativeTagFiber(directParent)
const isOnlyOneChild = !directParent.child!.sibling
Expand All @@ -167,7 +173,8 @@ export const getReferenceFiber = (baseFiber?: Fiber): Fiber | undefined => {
const originReferenceFiber = referenceFiber

while (referenceFiber) {
if (getCodeInfoFromFiber(referenceFiber)) return referenceFiber
if (getCodeInfoFromFiber(referenceFiber))
return referenceFiber

referenceFiber = referenceFiber.return!
}
Expand Down Expand Up @@ -211,9 +218,11 @@ export const getNamedFiber = (baseFiber?: Fiber): Fiber | undefined => {
}

if (getFiberName(fiber)) {
if (!originNamedFiber) originNamedFiber = fiber
if (!originNamedFiber)
originNamedFiber = fiber

if (getCodeInfoFromFiber(fiber)) return fiber
if (getCodeInfoFromFiber(fiber))
return fiber
}

fiber = parent!
Expand Down
6 changes: 3 additions & 3 deletions packages/inspector/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare module 'global' {
/**
* those types are internals in 'https://github.com/facebook/react/blob/v16.14.0/packages/react-devtools-shared/src/backend/types.js'
*/
type RendererID = number;
type RendererID = number
interface ReactRenderer {
findFiberByHostInstance: (instance: any) => Fiber | undefined;
};
Expand All @@ -15,9 +15,9 @@ declare module 'global' {
*/
__REACT_DEVTOOLS_GLOBAL_HOOK__?: {
renderers: Map<RendererID, ReactRenderer>;
},
};

__REACT_DEVTOOLS_TARGET_WINDOW__: Window,
__REACT_DEVTOOLS_TARGET_WINDOW__: Window;
}
}
}
1 change: 0 additions & 1 deletion packages/launch-editor-endpoint/src/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line unused-imports/no-unused-imports
import type { LaunchEditorParams } from './types'

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/middleware/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ declare module 'launch-editor' {
*/
interface LaunchEditorFunction {
(file: ComposableFilePath): void;
(file: ComposableFilePath, specifiedEditor: string): void
(file: ComposableFilePath, onErrorCallback: (fileName: string, message: string | null) => void): void
(file: ComposableFilePath, specifiedEditor: string): void;
(file: ComposableFilePath, onErrorCallback: (fileName: string, message: string | null) => void): void;
}

type ComposableFilePath =
Expand Down
5 changes: 1 addition & 4 deletions packages/web-components/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ export default defineConfig(() => {
})


/**
* @returns {ts.CompilerOptions}
*/
const readCompilerOptions = (tsconfigPath = 'tsconfig.json') => {
const readCompilerOptions = (tsconfigPath = 'tsconfig.json'): ts.CompilerOptions => {
const configFile = ts.readConfigFile(
tsconfigPath,
ts.sys.readFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ export const ElementInspectPanel = <Item extends ItemInfo = ItemInfo>(props: Ele
'aria-selected': isSelected(),
}}
onClick={() => {
if (isSelected()) return
if (isSelected())
return
setSelectedLayers(selects => ({
...selects,
[props.elementChainMode]: index(),
Expand Down
3 changes: 2 additions & 1 deletion packages/web-components/src/Overlay/Overlay.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ export const MoveableDragItem: StoryFn<{ itemSize: 'normal' | 'full' | 'large' }
}>({})

const inspectOnElement = (element?: HTMLElement | null) => {
if (!element) return
if (!element)
return

const boxSizing = getElementDimensions(element)
const boundingRect = getBoundingRect(element)
Expand Down
26 changes: 14 additions & 12 deletions packages/web-components/src/Overlay/OverlayTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ export const InspectorOverlayTip = (props: {
{styles}
</style>
<style>
{props.showCornerHint
? showCornerHintStyles
: null
{
props.showCornerHint
? showCornerHintStyles
: null
}
</style>
<div
Expand Down Expand Up @@ -168,15 +169,16 @@ const styles = css`
user-select: none;
overflow: hidden;
${(isSafari
// for Safari bug of multiple drop-shadow with overflow:hidden will clip shadow
? css`
filter: drop-shadow(0 0 1px #eee9);
`
: css`
filter: drop-shadow(0 0 1px #eee9) drop-shadow(2px 10px 12px var(--color-shadow-1)) drop-shadow(-3px 3px 6px var(--color-shadow-2)) drop-shadow(0 -6px 8px var(--color-shadow-1));
`
)}
${
isSafari
// for Safari bug of multiple drop-shadow with overflow:hidden will clip shadow
? css`
filter: drop-shadow(0 0 1px #eee9);
`
: css`
filter: drop-shadow(0 0 1px #eee9) drop-shadow(2px 10px 12px var(--color-shadow-1)) drop-shadow(-3px 3px 6px var(--color-shadow-2)) drop-shadow(0 -6px 8px var(--color-shadow-1));
`
}
.inspector-tip-info-row {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ export const ContextPanelDemo: StoryFn = () => {
'aria-selected': isSelected(),
}}
onClick={() => {
if (isSelected()) return
if (isSelected())
return
setSelectedLayer(index)
onLayerChange(index)
}}
>
<Layer.LayerItemText>
#{index}
#{index}
</Layer.LayerItemText>
</S.LayerButton>
</Layer.LayerItem>
Expand Down
Loading

0 comments on commit d7f4974

Please sign in to comment.