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(eslint): add no-duplicates, consistent-type-imports #219

Merged
merged 5 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changeset/good-ads-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@suspensive/react-query": patch
"@suspensive/react": patch
---

chore(eslint): add no-duplicates, consistent-type-imports
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": ["packlint", "codecov", "tsup"]
Expand Down
3 changes: 2 additions & 1 deletion configs/eslint-config-js/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ module.exports = {
extends: ['plugin:import/recommended', './noimport.js'],
plugins: ['import'],
rules: {
'sort-imports': ['error', { ignoreDeclarationSort: true }],
'import/no-duplicates': 'error',
'import/order': [
'warn',
{
groups: ['builtin', 'external', 'internal', ['parent', 'sibling'], 'index'],
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
'sort-imports': ['error', { ignoreDeclarationSort: true }],
},
}
1 change: 1 addition & 0 deletions configs/eslint-config-ts/noimport.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
rules: {
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'jsdoc/require-description': 'warn',
'jsdoc/require-returns': 'off',
'jsdoc/require-jsdoc': 'off',
Expand Down
1 change: 1 addition & 0 deletions configs/eslint-config-ts/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
],
rules: {
'sort-imports': ['error', { ignoreDeclarationSort: true }],
'import/no-duplicates': 'error',
'import/order': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion configs/tsup/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options } from 'tsup'
import type { Options } from 'tsup'

export const options: Options = {
banner: { js: '"use client"' },
Expand Down
2 changes: 1 addition & 1 deletion configs/vitest/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs'
import path, { dirname } from 'path'
import { UserConfig } from 'vitest/config'
import type { UserConfig } from 'vitest/config'

export const forPackage = (userConfig?: UserConfig): UserConfig => {
const packageJsonPath = path.resolve(dirname('.'), 'package.json')
Expand Down
3 changes: 2 additions & 1 deletion packages/react-query/src/QueryAsyncBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AsyncBoundary } from '@suspensive/react'
import { useQueryErrorResetBoundary } from '@tanstack/react-query'
import { ComponentPropsWithoutRef, ComponentRef, forwardRef } from 'react'
import type { ComponentPropsWithoutRef, ComponentRef } from 'react'
import { forwardRef } from 'react'

const BaseQueryAsyncBoundary = forwardRef<
ComponentRef<typeof AsyncBoundary>,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-query/src/QueryErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ErrorBoundary } from '@suspensive/react'
import { useQueryErrorResetBoundary } from '@tanstack/react-query'
import { ComponentPropsWithoutRef, ComponentRef, forwardRef } from 'react'
import type { ComponentPropsWithoutRef, ComponentRef } from 'react'
import { forwardRef } from 'react'

/**
* This component wrapping QueryErrorResetBoundary of @tanstack/react-query with @suspensive/react's ErrorBoundary.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-hooks/rules-of-hooks */
import { InfiniteData } from '@tanstack/react-query'
import type { InfiniteData } from '@tanstack/react-query'
import { expectError, expectType } from 'tsd'
import { useSuspenseInfiniteQuery } from '../dist'

Expand Down
5 changes: 2 additions & 3 deletions packages/react-query/src/useSuspenseInfiniteQuery.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
import type {
InfiniteData,
QueryFunction,
QueryKey,
UseInfiniteQueryOptions,
UseInfiniteQueryResult,
parseQueryArgs,
useInfiniteQuery,
} from '@tanstack/react-query'
import { parseQueryArgs, useInfiniteQuery } from '@tanstack/react-query'

export type BaseUseSuspenseInfiniteQueryResult<TData = unknown> = Omit<
UseInfiniteQueryResult<TData>,
Expand Down
5 changes: 3 additions & 2 deletions packages/react-query/src/useSuspenseQueries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { QueryFunction, QueryKey, UseQueryOptions, UseQueryResult, useQueries } from '@tanstack/react-query'
import { UseSuspenseQueryResultOnLoading, UseSuspenseQueryResultOnSuccess } from './useSuspenseQuery'
import type { QueryFunction, QueryKey, UseQueryOptions, UseQueryResult } from '@tanstack/react-query'
import { useQueries } from '@tanstack/react-query'
import type { UseSuspenseQueryResultOnLoading, UseSuspenseQueryResultOnSuccess } from './useSuspenseQuery'

// Avoid TS depth-limit error in case of large array literal
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -77,13 +78,13 @@
: UseQueryOptionsForUseSuspenseQueries[]

// results
type GetResult<T> = T extends { queryFnData: any; data: infer TData }

Check warning on line 81 in packages/react-query/src/useSuspenseQueries.ts

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Unexpected any. Specify a different type
? UseSuspenseQueryResultOnSuccess<TData>
: T extends { queryFnData: infer TQueryFnData }
? UseSuspenseQueryResultOnSuccess<TQueryFnData>
: T extends { data: infer TData }
? UseSuspenseQueryResultOnSuccess<TData>
: T extends [any, infer TData]

Check warning on line 87 in packages/react-query/src/useSuspenseQueries.ts

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Unexpected any. Specify a different type
? UseSuspenseQueryResultOnSuccess<TData>
: T extends [infer TQueryFnData]
? UseSuspenseQueryResultOnSuccess<TQueryFnData>
Expand Down Expand Up @@ -117,8 +118,8 @@
: UseSuspenseQueryResultOnSuccess<unknown>

export type QueriesResults<
T extends any[],

Check warning on line 121 in packages/react-query/src/useSuspenseQueries.ts

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Unexpected any. Specify a different type
Result extends any[] = [],

Check warning on line 122 in packages/react-query/src/useSuspenseQueries.ts

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Unexpected any. Specify a different type
Depth extends ReadonlyArray<number> = []
> = Depth['length'] extends MAXIMUM_DEPTH
? UseQueryResult[]
Expand All @@ -132,11 +133,11 @@
? UseSuspenseQueryResultOnSuccess<unknown extends TData ? TQueryFnData : TData>[]
: (UseSuspenseQueryResultOnSuccess<unknown> | UseSuspenseQueryResultOnLoading)[]

type UseSuspenseQueries = <T extends any[]>(arg: {

Check warning on line 136 in packages/react-query/src/useSuspenseQueries.ts

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Unexpected any. Specify a different type
queries: readonly [...SuspenseQueriesOptions<T>]
context?: UseQueryOptions['context']
}) => QueriesResults<T>
export const useSuspenseQueries: UseSuspenseQueries = <T extends any[]>({

Check warning on line 140 in packages/react-query/src/useSuspenseQueries.ts

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Unexpected any. Specify a different type
queries,
context,
}: {
Expand Down
10 changes: 2 additions & 8 deletions packages/react-query/src/useSuspenseQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
QueryFunction,
QueryKey,
UseQueryOptions,
UseQueryResult,
parseQueryArgs,
useQuery,
} from '@tanstack/react-query'
import type { QueryFunction, QueryKey, UseQueryOptions, UseQueryResult } from '@tanstack/react-query'
import { parseQueryArgs, useQuery } from '@tanstack/react-query'

export interface BaseUseSuspenseQueryResult<TData = unknown>
extends Omit<UseQueryResult<TData>, 'error' | 'isError' | 'isFetching'> {
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/AsyncBoundary.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { act, render, waitFor } from '@testing-library/react'
import { ComponentProps, createElement } from 'react'
import type { ComponentProps } from 'react'
import { createElement } from 'react'
import { createRoot } from 'react-dom/client'
import { vi } from 'vitest'
import { ERROR_MESSAGE, FALLBACK, MS_100, Suspend, TEXT, ThrowError } from './utils/toTest'
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/AsyncBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ComponentProps, ComponentRef, ComponentType, SuspenseProps, forwardRef } from 'react'
import type { ComponentProps, ComponentRef, ComponentType, SuspenseProps } from 'react'
import { forwardRef } from 'react'
import { ErrorBoundary } from './ErrorBoundary'
import { Suspense } from './Suspense'
import { PropsWithoutChildren } from './types'
import type { PropsWithoutChildren } from './types'

type ErrorBoundaryProps = ComponentProps<typeof ErrorBoundary>
type AsyncBoundaryProps = Omit<SuspenseProps, 'fallback'> &
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/Delay.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentProps, ComponentType, PropsWithChildren, createContext, useContext, useState } from 'react'
import type { ComponentProps, ComponentType, PropsWithChildren } from 'react'
import { createContext, useContext, useState } from 'react'
import { useSetTimeout } from './hooks'
import { PropsWithoutChildren } from './types'
import type { PropsWithoutChildren } from './types'

type DelayProps = PropsWithChildren<{
ms?: number
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/ErrorBoundary.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { act, render } from '@testing-library/react'
import { ComponentProps, ComponentRef, createElement, createRef, useEffect } from 'react'
import type { ComponentProps, ComponentRef } from 'react'
import { createElement, createRef, useEffect } from 'react'
import { createRoot } from 'react-dom/client'
import { vi } from 'vitest'
import { useSetTimeout } from './hooks'
Expand Down
12 changes: 3 additions & 9 deletions packages/react/src/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { ComponentProps, ComponentType, ErrorInfo, FunctionComponent, PropsWithChildren, ReactNode } from 'react'
import {
Component,
ComponentProps,
ComponentType,
ErrorInfo,
FunctionComponent,
PropsWithChildren,
ReactNode,
createContext,
createElement,
forwardRef,
Expand All @@ -16,9 +11,8 @@
useState,
} from 'react'
import { ErrorBoundaryGroupContext } from './ErrorBoundaryGroup'
import { PropsWithoutChildren } from './types'
import { hasResetKeysChanged } from './utils'
import { assert } from './utils'
import type { PropsWithoutChildren } from './types'
import { assert, hasResetKeysChanged } from './utils'

export type ErrorBoundaryFallbackProps = {
/**
Expand Down Expand Up @@ -155,8 +149,8 @@

const ErrorBoundaryContext = createContext<ErrorBoundaryContextType | null>(null)

/**

Check warning on line 152 in packages/react/src/ErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Missing JSDoc block description
* @experimental This is experimental feature.

Check warning on line 153 in packages/react/src/ErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Invalid JSDoc tag name "experimental"
*/
export const useErrorBoundary = <TError extends Error = Error>() => {
const [state, setState] = useState<ErrorBoundaryState<TError>>({
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/ErrorBoundaryGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentProps, ComponentType, PropsWithChildren, createContext, useContext, useEffect, useMemo } from 'react'
import type { ComponentProps, ComponentType, PropsWithChildren } from 'react'
import { createContext, useContext, useEffect, useMemo } from 'react'
import { useIsChanged, useKey } from './hooks'
import { PropsWithoutChildren } from './types'
import type { PropsWithoutChildren } from './types'
import { assert } from './utils'

export const ErrorBoundaryGroupContext = createContext<{ reset: () => void; resetKey: number } | undefined>(undefined)
Expand Down
13 changes: 3 additions & 10 deletions packages/react/src/Suspense.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import {
ComponentProps,
ComponentType,
ReactNode,
Suspense as ReactSuspense,
SuspenseProps,
createContext,
useContext,
} from 'react'
import type { ComponentProps, ComponentType, ReactNode, SuspenseProps } from 'react'
import { Suspense as ReactSuspense, createContext, useContext } from 'react'
import { useIsMounted } from './hooks'
import { PropsWithoutChildren } from './types'
import type { PropsWithoutChildren } from './types'

export const SuspenseContext = createContext<PropsWithoutChildren<SuspenseProps>>({ fallback: undefined })
const useFallbackWithContext = (fallback: ReactNode) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/SuspensiveProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContextType, PropsWithChildren, useMemo } from 'react'
import type { ContextType, PropsWithChildren } from 'react'
import { useMemo } from 'react'
import { DelayContext } from './Delay'
import { SuspenseContext } from './Suspense'

Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/experimental/Await.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FunctionComponent, createElement, useMemo } from 'react'
import type { FunctionComponent } from 'react'
import { createElement, useMemo } from 'react'
import { useSyncExternalStore } from 'use-sync-external-store/shim'
import { Tuple } from '../types'
import type { Tuple } from '../types'
import { hashKey } from '../utils'

export type Key = Tuple
Expand All @@ -25,8 +26,8 @@
reset: () => void
}

/**

Check warning on line 29 in packages/react/src/experimental/Await.tsx

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Missing JSDoc block description
* @experimental This is experimental feature.

Check warning on line 30 in packages/react/src/experimental/Await.tsx

View workflow job for this annotation

GitHub Actions / Check quality (pnpm lint)

Invalid JSDoc tag name "experimental"
*/
export const useAwait = <TData, TKey extends Key>(options: AwaitOptions<TData, TKey>): Awaited<TData> => {
const syncData = () => awaitClient.suspend(options)
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/types/PropsWithoutChildren.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { ComponentProps, ComponentType } from 'react'
import type { ComponentProps, ComponentType } from 'react'

export type PropsWithoutChildren<TProps extends ComponentProps<ComponentType>> = Omit<TProps, 'children'>
5 changes: 3 additions & 2 deletions packages/react/src/utils/hashKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Key } from '../experimental/Await'
import { PlainObject, isPlainObject } from './isPlainObject'
import type { Key } from '../experimental/Await'
import type { PlainObject } from './isPlainObject'
import { isPlainObject } from './isPlainObject'

export const hashKey = (key: Key) =>
JSON.stringify(key, (_, val) =>
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/utils/toTest.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PropsWithChildren, ReactNode, useState } from 'react'
import type { PropsWithChildren, ReactNode } from 'react'
import { useState } from 'react'
import { useSetTimeout } from '../hooks'

const suspendIsNeed = { current: true }
Expand Down
2 changes: 1 addition & 1 deletion websites/visualization/src/app/CommonLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Flex } from '@jsxcss/emotion'
import Image from 'next/image'
import Link from 'next/link'
import { PropsWithChildren } from 'react'
import type { PropsWithChildren } from 'react'

export const CommonLayout = ({ children }: PropsWithChildren) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion websites/visualization/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './global.css'
import { Metadata } from 'next'
import type { Metadata } from 'next'
import { CommonLayout } from './CommonLayout'
import { Providers } from './providers'

Expand Down
2 changes: 1 addition & 1 deletion websites/visualization/src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MediaQueryProvider } from '@jsxcss/emotion'
import { Suspensive, SuspensiveProvider } from '@suspensive/react'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { PropsWithChildren } from 'react'
import type { PropsWithChildren } from 'react'
import { Spinner } from '~/components/uis'

const queryClient = new QueryClient({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Suspense } from '@suspensive/react'
import { useSuspenseQueries, useSuspenseQuery } from '@suspensive/react-query'
import { useEffect, useRef, useState } from 'react'
import { Post, albums, posts, todos } from './api'
import type { Post } from './api'
import { albums, posts, todos } from './api'
import { useIntersectionObserver } from './useIntersectionObserver'

export const PostListSuspensive = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Delay } from '@suspensive/react'
import { useQueries, useQuery } from '@tanstack/react-query'
import { useEffect, useRef, useState } from 'react'
import { Post, albums, posts, todos } from './api'
import type { Post } from './api'
import { albums, posts, todos } from './api'
import { useIntersectionObserver } from './useIntersectionObserver'
import { Spinner } from '~/components/uis'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use client'

import { ErrorBoundary, useErrorBoundary } from '@suspensive/react'
import { PropsWithChildren, createElement, useEffect, useState } from 'react'
import type { PropsWithChildren } from 'react'
import { createElement, useEffect, useState } from 'react'

export default function Page() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { ErrorBoundaryFallbackProps } from '@suspensive/react'
import type { ErrorBoundaryFallbackProps } from '@suspensive/react'
import { Box, Button, Description } from './uis'

export const RejectedFallback = (props: ErrorBoundaryFallbackProps) => (
Expand Down
2 changes: 1 addition & 1 deletion websites/visualization/src/components/uis/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use client'

import styled from '@emotion/styled'
import { PropsWithChildren } from 'react'
import type { PropsWithChildren } from 'react'

export const Button = styled.button`
box-sizing: border-box;
Expand Down
Loading