Skip to content

Commit

Permalink
refactor: Sort imports with eslint (#5634)
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlancollins authored Jul 16, 2023
1 parent 8f19f73 commit 9c721e5
Show file tree
Hide file tree
Showing 129 changed files with 460 additions and 437 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const config = {
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'prettier',
],
Expand Down Expand Up @@ -41,15 +42,38 @@ const config = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unnecessary-condition': 'error',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-inferrable-types': [
'error',
{ ignoreParameters: true },
],
'import/default': 'off',
'import/export': 'off',
'import/namespace': 'off',
'import/newline-after-import': 'error',
'import/no-cycle': 'error',
'import/no-duplicates': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': ['error', { ignore: ['^@tanstack/'] }],
'import/no-unused-modules': ['off', { unusedExports: true }],
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
},
],
'no-redeclare': 'off',
'no-shadow': 'error',
'sort-imports': ['error', { ignoreDeclarationSort: true }],
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-query/src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TSESLint } from '@typescript-eslint/utils'
import { rules } from '../rules'
import type { TSESLint } from '@typescript-eslint/utils'

function generateRecommendedConfig(
allRules: Record<string, TSESLint.RuleModule<any, any>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { TSESLint } from '@typescript-eslint/utils'
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import { ASTUtils } from '../../utils/ast-utils'
import { createRule } from '../../utils/create-rule'
import { uniqueBy } from '../../utils/unique-by'
import { ExhaustiveDepsUtils } from './exhaustive-deps.utils'
import type { TSESLint } from '@typescript-eslint/utils'

const QUERY_KEY = 'queryKey'
const QUERY_FN = 'queryFn'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TSESLint } from '@typescript-eslint/utils'
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import { ASTUtils } from '../../utils/ast-utils'
import type { TSESLint } from '@typescript-eslint/utils'

export const ExhaustiveDepsUtils = {
isRelevantReference(params: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rule, name } from './prefer-query-object-syntax'
import { normalizeIndent } from '../../utils/test-utils'
import { ESLintUtils } from '@typescript-eslint/utils'
import { normalizeIndent } from '../../utils/test-utils'
import { name, rule } from './prefer-query-object-syntax'

const ruleTester = new ESLintUtils.RuleTester({
parser: '@typescript-eslint/parser',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import { createRule } from '../../utils/create-rule'
import { ASTUtils } from '../../utils/ast-utils'
import { objectKeys } from '../../utils/object-utils'
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'

const QUERY_CALLS = {
useQuery: { key: 'queryKey', fn: 'queryFn', type: 'query' },
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-query/src/utils/ast-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import { uniqueBy } from './unique-by'
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
import type TSESLintScopeManager from '@typescript-eslint/scope-manager'
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'
import { uniqueBy } from './unique-by'

export const ASTUtils = {
isNodeOfOneOf<T extends AST_NODE_TYPES>(
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-query/src/utils/create-rule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ESLintUtils } from '@typescript-eslint/utils'
import type { EnhancedCreate } from './detect-react-query-imports'
import { detectTanstackQueryImports } from './detect-react-query-imports'
import type { EnhancedCreate } from './detect-react-query-imports'

const getDocsUrl = (ruleName: string): string =>
`https://tanstack.com/query/v4/docs/eslint/${ruleName}`
Expand Down
2 changes: 1 addition & 1 deletion packages/query-async-storage-persister/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { asyncThrottle } from './asyncThrottle'
import type {
PersistedClient,
Persister,
Promisable,
} from '@tanstack/query-persist-client-core'
import { asyncThrottle } from './asyncThrottle'

interface AsyncStorage {
getItem: (key: string) => Promise<string | null>
Expand Down
12 changes: 6 additions & 6 deletions packages/query-core/src/infiniteQueryObserver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { QueryObserver } from './queryObserver'
import {
hasNextPage,
hasPreviousPage,
infiniteQueryBehavior,
} from './infiniteQueryBehavior'
import type {
DefaultedInfiniteQueryObserverOptions,
FetchNextPageOptions,
Expand All @@ -9,12 +15,6 @@ import type {
} from './types'
import type { QueryClient } from './queryClient'
import type { NotifyOptions, ObserverFetchOptions } from './queryObserver'
import { QueryObserver } from './queryObserver'
import {
hasNextPage,
hasPreviousPage,
infiniteQueryBehavior,
} from './infiniteQueryBehavior'
import type { Query } from './query'

type InfiniteQueryObserverListener<TData, TError> = (
Expand Down
10 changes: 5 additions & 5 deletions packages/query-core/src/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { MutationOptions, MutationStatus, MutationMeta } from './types'
import type { MutationCache } from './mutationCache'
import type { MutationObserver } from './mutationObserver'
import type { Logger } from './logger'
import { defaultLogger } from './logger'
import { notifyManager } from './notifyManager'
import { Removable } from './removable'
import type { Retryer } from './retryer'
import { canFetch, createRetryer } from './retryer'
import type { MutationMeta, MutationOptions, MutationStatus } from './types'
import type { MutationCache } from './mutationCache'
import type { MutationObserver } from './mutationObserver'
import type { Logger } from './logger'
import type { Retryer } from './retryer'

// TYPES

Expand Down
8 changes: 4 additions & 4 deletions packages/query-core/src/mutationCache.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { notifyManager } from './notifyManager'
import { Mutation } from './mutation'
import { matchMutation, noop } from './utils'
import { Subscribable } from './subscribable'
import type { MutationObserver } from './mutationObserver'
import type { MutationOptions, NotifyEvent } from './types'
import type { QueryClient } from './queryClient'
import { notifyManager } from './notifyManager'
import type { Action, MutationState } from './mutation'
import { Mutation } from './mutation'
import type { MutationFilters } from './utils'
import { matchMutation, noop } from './utils'
import { Subscribable } from './subscribable'

// TYPES

Expand Down
8 changes: 4 additions & 4 deletions packages/query-core/src/mutationObserver.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Action, Mutation } from './mutation'
import { getDefaultState } from './mutation'
import { notifyManager } from './notifyManager'
import type { QueryClient } from './queryClient'
import { Subscribable } from './subscribable'
import { shallowEqualObjects } from './utils'
import type { QueryClient } from './queryClient'
import type {
MutateOptions,
MutationObserverBaseResult,
MutationObserverResult,
MutationObserverOptions,
MutationObserverResult,
} from './types'
import { shallowEqualObjects } from './utils'
import type { Action, Mutation } from './mutation'

// TYPES

Expand Down
6 changes: 3 additions & 3 deletions packages/query-core/src/queriesObserver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { difference, replaceAt } from './utils'
import { notifyManager } from './notifyManager'
import { QueryObserver } from './queryObserver'
import { Subscribable } from './subscribable'
import type {
DefaultedQueryObserverOptions,
QueryObserverOptions,
QueryObserverResult,
DefaultedQueryObserverOptions,
} from './types'
import type { QueryClient } from './queryClient'
import type { NotifyOptions } from './queryObserver'
import { QueryObserver } from './queryObserver'
import { Subscribable } from './subscribable'

type QueriesObserverListener = (result: QueryObserverResult[]) => void

Expand Down
16 changes: 8 additions & 8 deletions packages/query-core/src/query.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { getAbortController, noop, replaceData, timeUntilStale } from './utils'
import { defaultLogger } from './logger'
import { notifyManager } from './notifyManager'
import { canFetch, createRetryer, isCancelledError } from './retryer'
import { Removable } from './removable'
import type {
CancelOptions,
FetchStatus,
InitialDataFunction,
QueryFunctionContext,
QueryKey,
QueryMeta,
QueryOptions,
QueryStatus,
QueryFunctionContext,
QueryMeta,
CancelOptions,
SetDataOptions,
FetchStatus,
} from './types'
import type { QueryCache } from './queryCache'
import type { QueryObserver } from './queryObserver'
import type { Logger } from './logger'
import { defaultLogger } from './logger'
import { notifyManager } from './notifyManager'
import type { Retryer } from './retryer'
import { isCancelledError, canFetch, createRetryer } from './retryer'
import { Removable } from './removable'

// TYPES

Expand Down
8 changes: 4 additions & 4 deletions packages/query-core/src/queryCache.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { QueryFilters } from './utils'
import { hashQueryKeyByOptions, matchQuery, parseFilterArgs } from './utils'
import type { Action, QueryState } from './query'
import { Query } from './query'
import type { NotifyEvent, QueryKey, QueryOptions } from './types'
import { notifyManager } from './notifyManager'
import type { QueryClient } from './queryClient'
import { Subscribable } from './subscribable'
import type { QueryFilters } from './utils'
import type { Action, QueryState } from './query'
import type { NotifyEvent, QueryKey, QueryOptions } from './types'
import type { QueryClient } from './queryClient'
import type { QueryObserver } from './queryObserver'

// TYPES
Expand Down
28 changes: 14 additions & 14 deletions packages/query-core/src/queryClient.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import type { QueryFilters, Updater, MutationFilters } from './utils'
import {
functionalUpdate,
hashQueryKey,
hashQueryKeyByOptions,
noop,
parseFilterArgs,
parseQueryArgs,
partialMatchKey,
hashQueryKeyByOptions,
functionalUpdate,
} from './utils'
import { QueryCache } from './queryCache'
import { MutationCache } from './mutationCache'
import { focusManager } from './focusManager'
import { onlineManager } from './onlineManager'
import { notifyManager } from './notifyManager'
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
import { defaultLogger } from './logger'
import type { CancelOptions, DefaultedQueryObserverOptions } from './types'
import type { Logger } from './logger'
import type { QueryState } from './query'
import type {
QueryClientConfig,
DefaultOptions,
FetchInfiniteQueryOptions,
FetchQueryOptions,
Expand All @@ -19,6 +27,7 @@ import type {
MutationKey,
MutationObserverOptions,
MutationOptions,
QueryClientConfig,
QueryFunction,
QueryKey,
QueryObserverOptions,
Expand All @@ -30,16 +39,7 @@ import type {
SetDataOptions,
WithRequired,
} from './types'
import type { QueryState } from './query'
import { QueryCache } from './queryCache'
import { MutationCache } from './mutationCache'
import { focusManager } from './focusManager'
import { onlineManager } from './onlineManager'
import { notifyManager } from './notifyManager'
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
import type { CancelOptions, DefaultedQueryObserverOptions } from './types'
import type { Logger } from './logger'
import { defaultLogger } from './logger'
import type { MutationFilters, QueryFilters, Updater } from './utils'

// TYPES

Expand Down
10 changes: 5 additions & 5 deletions packages/query-core/src/queryObserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'
import {
isServer,
isValidTimeout,
Expand All @@ -8,6 +7,9 @@ import {
timeUntilStale,
} from './utils'
import { notifyManager } from './notifyManager'
import { focusManager } from './focusManager'
import { Subscribable } from './subscribable'
import { canFetch, isCancelledError } from './retryer'
import type {
PlaceholderDataFunction,
QueryKey,
Expand All @@ -17,11 +19,9 @@ import type {
QueryOptions,
RefetchOptions,
} from './types'
import type { Query, QueryState, Action, FetchOptions } from './query'
import type { Action, FetchOptions, Query, QueryState } from './query'
import type { QueryClient } from './queryClient'
import { focusManager } from './focusManager'
import { Subscribable } from './subscribable'
import { canFetch, isCancelledError } from './retryer'
import type { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'

type QueryObserverListener<TData, TError> = (
result: QueryObserverResult<TData, TError>,
Expand Down
4 changes: 2 additions & 2 deletions packages/query-core/src/tests/hydration.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { QueryCache } from '../queryCache'
import { dehydrate, hydrate } from '../hydration'
import {
createQueryClient,
executeMutation,
mockNavigatorOnLine,
sleep,
} from './utils'
import { QueryCache } from '../queryCache'
import { dehydrate, hydrate } from '../hydration'

async function fetchData<TData>(value: TData, ms?: number): Promise<TData> {
await sleep(ms || 0)
Expand Down
6 changes: 3 additions & 3 deletions packages/query-core/src/tests/infiniteQueryBehavior.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { waitFor } from '@testing-library/react'
import { InfiniteQueryObserver } from '@tanstack/query-core'
import { createQueryClient, queryKey } from './utils'
import type {
QueryClient,
InfiniteQueryObserverResult,
QueryCache,
QueryClient,
} from '@tanstack/query-core'
import { InfiniteQueryObserver } from '@tanstack/query-core'
import { createQueryClient, queryKey } from './utils'

describe('InfiniteQueryBehavior', () => {
let queryClient: QueryClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InfiniteQueryObserver } from '..'
import { createQueryClient, queryKey, sleep } from './utils'
import type { QueryClient } from '..'
import { InfiniteQueryObserver } from '..'

describe('InfiniteQueryObserver', () => {
let queryClient: QueryClient
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/tests/mutationCache.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { waitFor } from '@testing-library/react'
import { queryKey, sleep, executeMutation, createQueryClient } from './utils'
import { MutationCache, MutationObserver } from '..'
import { createQueryClient, executeMutation, queryKey, sleep } from './utils'

describe('mutationCache', () => {
describe('MutationCacheConfig error callbacks', () => {
Expand Down
Loading

0 comments on commit 9c721e5

Please sign in to comment.