Skip to content

Commit 13b17ee

Browse files
authored
chore(eslint): set array-type lint rule to generic (#5899)
* chore(eslint): set array-type lint rule to generic * chore: fix prettier
1 parent 770d454 commit 13b17ee

File tree

67 files changed

+642
-590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+642
-590
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const config = {
3434
},
3535
},
3636
rules: {
37+
'@typescript-eslint/array-type': ['error', { default: 'generic', readonly: 'generic' }],
3738
'@typescript-eslint/ban-types': 'off',
3839
'@typescript-eslint/ban-ts-comment': 'off',
3940
'@typescript-eslint/consistent-type-imports': [

packages/codemods/src/v4/__testfixtures__/type-arguments.input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import * as React from 'react'
22
import { useQueries, useQuery, useQueryClient } from 'react-query'
33

44
type Todos = {
5-
items: readonly {
5+
items: ReadonlyArray<{
66
id: string
77
text: string
8-
}[]
8+
}>
99
ts: number
1010
}
1111

packages/codemods/src/v4/__testfixtures__/type-arguments.output.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import * as React from 'react'
22
import { useQueries, useQuery, useQueryClient } from 'react-query'
33

44
type Todos = {
5-
items: readonly {
5+
items: ReadonlyArray<{
66
id: string
77
text: string
8-
}[]
8+
}>
99
ts: number
1010
}
1111

packages/eslint-plugin-query/src/rules/exhaustive-deps.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { TSESLint } from '@typescript-eslint/utils'
44

55
export const ExhaustiveDepsUtils = {
66
isRelevantReference(params: {
7-
context: Readonly<TSESLint.RuleContext<string, readonly unknown[]>>
7+
context: Readonly<TSESLint.RuleContext<string, ReadonlyArray<unknown>>>
88
reference: TSESLint.Scope.Reference
99
scopeManager: TSESLint.Scope.ScopeManager
1010
}) {

packages/eslint-plugin-query/src/utils/ast-utils.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'
77
export const ASTUtils = {
88
isNodeOfOneOf<T extends AST_NODE_TYPES>(
99
node: TSESTree.Node,
10-
types: readonly T[],
10+
types: ReadonlyArray<T>,
1111
): node is TSESTree.Node & { type: T } {
1212
return types.includes(node.type as T)
1313
},
@@ -20,7 +20,7 @@ export const ASTUtils = {
2020
): node is TSESTree.Identifier {
2121
return ASTUtils.isIdentifier(node) && node.name === name
2222
},
23-
isIdentifierWithOneOfNames<T extends string[]>(
23+
isIdentifierWithOneOfNames<T extends Array<string>>(
2424
node: TSESTree.Node,
2525
name: T,
2626
): node is TSESTree.Identifier & { name: T[number] } {
@@ -41,15 +41,15 @@ export const ASTUtils = {
4141
)
4242
},
4343
findPropertyWithIdentifierKey(
44-
properties: TSESTree.ObjectLiteralElement[],
44+
properties: Array<TSESTree.ObjectLiteralElement>,
4545
key: string,
4646
): TSESTree.Property | undefined {
4747
return properties.find((x) =>
4848
ASTUtils.isPropertyWithIdentifierKey(x, key),
4949
) as TSESTree.Property | undefined
5050
},
51-
getNestedIdentifiers(node: TSESTree.Node): TSESTree.Identifier[] {
52-
const identifiers: TSESTree.Identifier[] = []
51+
getNestedIdentifiers(node: TSESTree.Node): Array<TSESTree.Identifier> {
52+
const identifiers: Array<TSESTree.Identifier> = []
5353

5454
if (ASTUtils.isIdentifier(node)) {
5555
identifiers.push(node)
@@ -131,7 +131,7 @@ export const ASTUtils = {
131131
},
132132
traverseUpOnly(
133133
identifier: TSESTree.Node,
134-
allowedNodeTypes: AST_NODE_TYPES[],
134+
allowedNodeTypes: Array<AST_NODE_TYPES>,
135135
): TSESTree.Node {
136136
const parent = identifier.parent
137137

@@ -159,7 +159,7 @@ export const ASTUtils = {
159159
scopeManager: TSESLint.Scope.ScopeManager
160160
sourceCode: Readonly<TSESLint.SourceCode>
161161
node: TSESTree.Node
162-
}): TSESLint.Scope.Reference[] {
162+
}): Array<TSESLint.Scope.Reference> {
163163
const { scopeManager, sourceCode, node } = params
164164
const scope = scopeManager.acquire(node)
165165

@@ -207,7 +207,7 @@ export const ASTUtils = {
207207
return identifier !== null && /^(use|[A-Z])/.test(identifier.name)
208208
},
209209
getFunctionAncestor(
210-
context: Readonly<RuleContext<string, readonly unknown[]>>,
210+
context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>,
211211
) {
212212
return context.getAncestors().find((x) => {
213213
if (x.type === AST_NODE_TYPES.FunctionDeclaration) {
@@ -227,7 +227,7 @@ export const ASTUtils = {
227227
},
228228
getReferencedExpressionByIdentifier(params: {
229229
node: TSESTree.Node
230-
context: Readonly<RuleContext<string, readonly unknown[]>>
230+
context: Readonly<RuleContext<string, ReadonlyArray<unknown>>>
231231
}) {
232232
const { node, context } = params
233233

@@ -242,8 +242,10 @@ export const ASTUtils = {
242242

243243
return resolvedNode.init
244244
},
245-
getNestedReturnStatements(node: TSESTree.Node): TSESTree.ReturnStatement[] {
246-
const returnStatements: TSESTree.ReturnStatement[] = []
245+
getNestedReturnStatements(
246+
node: TSESTree.Node,
247+
): Array<TSESTree.ReturnStatement> {
248+
const returnStatements: Array<TSESTree.ReturnStatement> = []
247249

248250
if (node.type === AST_NODE_TYPES.ReturnStatement) {
249251
returnStatements.push(node)

packages/eslint-plugin-query/src/utils/detect-react-query-imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type EnhancedCreate = (
1818

1919
export function detectTanstackQueryImports(create: EnhancedCreate): Create {
2020
return (context, optionsWithDefault) => {
21-
const tanstackQueryImportSpecifiers: TSESTree.ImportClause[] = []
21+
const tanstackQueryImportSpecifiers: Array<TSESTree.ImportClause> = []
2222

2323
const helpers: Helpers = {
2424
isTanstackQueryImport(node) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export function uniqueBy<T>(arr: T[], fn: (x: T) => unknown): T[] {
1+
export function uniqueBy<T>(arr: Array<T>, fn: (x: T) => unknown): Array<T> {
22
return arr.filter((x, i, a) => a.findIndex((y) => fn(x) === fn(y)) === i)
33
}

packages/query-async-storage-persister/src/__tests__/asyncThrottle.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { sleep as delay } from './utils'
55
describe('asyncThrottle', () => {
66
test('basic', async () => {
77
const interval = 10
8-
const execTimeStamps: number[] = []
8+
const execTimeStamps: Array<number> = []
99
const mockFunc = vi.fn(
1010
async (id: number, complete?: (value?: unknown) => void) => {
1111
await delay(1)
@@ -33,7 +33,7 @@ describe('asyncThrottle', () => {
3333

3434
test('Bug #3331 case 1: Special timing', async () => {
3535
const interval = 1000
36-
const execTimeStamps: number[] = []
36+
const execTimeStamps: Array<number> = []
3737
const mockFunc = vi.fn(
3838
async (id: number, complete?: (value?: unknown) => void) => {
3939
await delay(30)
@@ -62,7 +62,7 @@ describe('asyncThrottle', () => {
6262

6363
test('Bug #3331 case 2: "func" execution time is greater than the interval.', async () => {
6464
const interval = 1000
65-
const execTimeStamps: number[] = []
65+
const execTimeStamps: Array<number> = []
6666
const mockFunc = vi.fn(
6767
async (id: number, complete?: (value?: unknown) => void) => {
6868
await delay(interval + 10)

packages/query-async-storage-persister/src/asyncThrottle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const noop = () => {
77
/* do nothing */
88
}
99

10-
export function asyncThrottle<Args extends readonly unknown[]>(
10+
export function asyncThrottle<Args extends ReadonlyArray<unknown>>(
1111
func: (...args: Args) => Promise<void>,
1212
{ interval = 1000, onError = noop }: AsyncThrottleOptions = {},
1313
) {

packages/query-core/src/hydration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ interface DehydratedQuery {
3838
}
3939

4040
export interface DehydratedState {
41-
mutations: DehydratedMutation[]
42-
queries: DehydratedQuery[]
41+
mutations: Array<DehydratedMutation>
42+
queries: Array<DehydratedQuery>
4343
}
4444

4545
// FUNCTIONS

0 commit comments

Comments
 (0)