Skip to content

Commit 3e92795

Browse files
style: use generic style for array types (#26738)
Using this style provides consistency with Set, Map, etc. Co-authored-by: Blaine Kasten <[email protected]>
1 parent d878bfd commit 3e92795

File tree

90 files changed

+313
-278
lines changed

Some content is hidden

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

90 files changed

+313
-278
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ module.exports = {
168168
// bump to @typescript-eslint/parser started showing Flow related errors in ts(x) files
169169
// so disabling them in .ts(x) files
170170
"flowtype/no-types-missing-file-annotation": "off",
171+
"@typescript-eslint/array-type": [
172+
'error',
173+
{ default: 'generic' },
174+
],
171175
},
172176
},
173177
],

packages/babel-preset-gatsby/src/optimize-hook-destructuring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function ({
5353

5454
path.parent.id = t.objectPattern(
5555
path.parent.id.elements.reduce(
56-
(acc: BabelTypes.ObjectProperty[], element, i) => {
56+
(acc: Array<BabelTypes.ObjectProperty>, element, i) => {
5757
if (element) {
5858
acc.push(t.objectProperty(t.numericLiteral(i), element))
5959
}

packages/gatsby-cli/src/create-cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { initStarter } from "./init-starter"
1212
import { recipesHandler } from "./recipes"
1313
import { startGraphQLServer } from "gatsby-recipes"
1414

15-
const handlerP = (fn: Function) => (...args: unknown[]): void => {
15+
const handlerP = (fn: Function) => (...args: Array<unknown>): void => {
1616
Promise.resolve(fn(...args)).then(
1717
() => process.exit(0),
1818
err => report.panic(err)
@@ -422,7 +422,7 @@ Gatsby version: ${gatsbyVersion}
422422
}
423423
}
424424

425-
export const createCli = (argv: string[]): yargs.Arguments => {
425+
export const createCli = (argv: Array<string>): yargs.Arguments => {
426426
const cli = yargs(argv).parserConfiguration({
427427
"boolean-negation": false,
428428
})

packages/gatsby-cli/src/init-starter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import reporter from "../lib/reporter"
1717

1818
const spawnWithArgs = (
1919
file: string,
20-
args: string[],
20+
args: Array<string>,
2121
options?: execa.Options
2222
): execa.ExecaChildProcess =>
2323
execa(file, args, { stdio: `inherit`, preferLocal: false, ...options })

packages/gatsby-cli/src/reporter/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const packagesToSkipTest = new RegExp(
1313
// TO-DO: move this this out of this file (and probably delete this file completely)
1414
// it's here because it re-implements similar thing as `pretty-error` already does
1515
export const sanitizeStructuredStackTrace = (
16-
stack: stackTrace.StackFrame[]
17-
): IStructuredStackFrame[] => {
16+
stack: Array<stackTrace.StackFrame>
17+
): Array<IStructuredStackFrame> => {
1818
// first filter out not useful call sites
1919
stack = stack.filter(callSite => {
2020
if (!callSite.getFileName()) {
@@ -86,7 +86,7 @@ export function getErrorFormatter(): PrettyError {
8686
}
8787

8888
prettyError.render = (
89-
err: PrettyRenderError | PrettyRenderError[]
89+
err: PrettyRenderError | Array<PrettyRenderError>
9090
): string => {
9191
if (Array.isArray(err)) {
9292
return err.map(e => prettyError.render(e)).join(`\n`)

packages/gatsby-cli/src/reporter/loggers/ink/cli.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CLI extends React.Component<ICLIProps, ICLIState> {
2727
readonly state: ICLIState = {
2828
hasError: false,
2929
}
30-
memoizedReactElementsForMessages: React.ReactElement[] = []
30+
memoizedReactElementsForMessages: Array<React.ReactElement> = []
3131

3232
componentDidCatch(error: Error, info: React.ErrorInfo): void {
3333
trackBuildError(`INK`, {

packages/gatsby-cli/src/reporter/patch-console.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import util from "util"
66
import { reporter as gatsbyReporter } from "./reporter"
77

88
export function patchConsole(reporter: typeof gatsbyReporter): void {
9-
console.log = (...args: any[]): void => {
9+
console.log = (...args: Array<any>): void => {
1010
const [format, ...rest] = args
1111
reporter.log(util.format(format === undefined ? `` : format, ...rest))
1212
}
13-
console.warn = (...args: any[]): void => {
13+
console.warn = (...args: Array<any>): void => {
1414
const [format, ...rest] = args
1515
reporter.warn(util.format(format === undefined ? `` : format, ...rest))
1616
}
17-
console.info = (...args: any[]): void => {
17+
console.info = (...args: Array<any>): void => {
1818
const [format, ...rest] = args
1919
reporter.info(util.format(format === undefined ? `` : format, ...rest))
2020
}
21-
console.error = (format: any, ...args: any[]): void => {
21+
console.error = (format: any, ...args: Array<any>): void => {
2222
reporter.error(util.format(format === undefined ? `` : format, ...args))
2323
}
2424
}

packages/gatsby-cli/src/reporter/redux/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const diagnosticsMiddleware = createStructuredLoggingDiagnosticsMiddleware(
1919
export type GatsbyCLIStore = typeof store
2020
type StoreListener = (store: GatsbyCLIStore) => void
2121
type ActionLogListener = (action: ActionsUnion) => any
22-
type Thunk = (...args: any[]) => ActionsUnion
22+
type Thunk = (...args: Array<any>) => ActionsUnion
2323

24-
const storeSwapListeners: StoreListener[] = []
24+
const storeSwapListeners: Array<StoreListener> = []
2525
const onLogActionListeners = new Set<ActionLogListener>()
2626

2727
export const getStore = (): typeof store => store

packages/gatsby-cli/src/reporter/redux/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Actions, ActivityStatuses, ActivityTypes } from "../constants"
22
import { IStructuredError } from "../../structured-errors/types"
33

44
export interface IGatsbyCLIState {
5-
messages: ILog[]
5+
messages: Array<ILog>
66
activities: {
77
[id: string]: IActivity
88
}

packages/gatsby-cli/src/reporter/reporter-progress.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export interface IProgressReporter {
2020
tick(increment?: number): void
2121
panicOnBuild(
2222
arg: any,
23-
...otherArgs: any[]
24-
): IStructuredError | IStructuredError[]
25-
panic(arg: any, ...otherArgs: any[]): void
23+
...otherArgs: Array<any>
24+
): IStructuredError | Array<IStructuredError>
25+
panic(arg: any, ...otherArgs: Array<any>): void
2626
end(): void
2727
done(): void
2828
total: number
@@ -82,8 +82,8 @@ export const createProgressReporter = ({
8282

8383
panicOnBuild(
8484
errorMeta: ErrorMeta,
85-
error?: Error | Error[]
86-
): IStructuredError | IStructuredError[] {
85+
error?: Error | Array<Error>
86+
): IStructuredError | Array<IStructuredError> {
8787
span.finish()
8888

8989
reporterActions.setActivityErrored({
@@ -93,7 +93,7 @@ export const createProgressReporter = ({
9393
return reporter.panicOnBuild(errorMeta, error)
9494
},
9595

96-
panic(errorMeta: ErrorMeta, error?: Error | Error[]): void {
96+
panic(errorMeta: ErrorMeta, error?: Error | Array<Error>): void {
9797
span.finish()
9898

9999
reporterActions.endActivity({

packages/gatsby-cli/src/reporter/reporter-timer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export interface ITimerReporter {
2121
setStatus(statusText: string): void
2222
panicOnBuild(
2323
arg: any,
24-
...otherArgs: any[]
25-
): IStructuredError | IStructuredError[]
26-
panic(arg: any, ...otherArgs: any[]): void
24+
...otherArgs: Array<any>
25+
): IStructuredError | Array<IStructuredError>
26+
panic(arg: any, ...otherArgs: Array<any>): void
2727
end(): void
2828
span: Span
2929
}
@@ -52,8 +52,8 @@ export const createTimerReporter = ({
5252

5353
panicOnBuild(
5454
errorMeta: ErrorMeta,
55-
error?: Error | Error[]
56-
): IStructuredError | IStructuredError[] {
55+
error?: Error | Array<Error>
56+
): IStructuredError | Array<IStructuredError> {
5757
span.finish()
5858

5959
reporterActions.setActivityErrored({
@@ -63,7 +63,7 @@ export const createTimerReporter = ({
6363
return reporter.panicOnBuild(errorMeta, error)
6464
},
6565

66-
panic(errorMeta: ErrorMeta, error?: Error | Error[]): void {
66+
panic(errorMeta: ErrorMeta, error?: Error | Array<Error>): void {
6767
span.finish()
6868

6969
reporterActions.endActivity({

packages/gatsby-cli/src/reporter/reporter.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Reporter {
6565
/**
6666
* Log arguments and exit process with status 1.
6767
*/
68-
panic = (errorMeta: ErrorMeta, error?: Error | Error[]): never => {
68+
panic = (errorMeta: ErrorMeta, error?: Error | Array<Error>): never => {
6969
const reporterError = this.error(errorMeta, error)
7070
trackError(`GENERAL_PANIC`, { error: reporterError })
7171
prematureEnd()
@@ -74,8 +74,8 @@ class Reporter {
7474

7575
panicOnBuild = (
7676
errorMeta: ErrorMeta,
77-
error?: Error | Error[]
78-
): IStructuredError | IStructuredError[] => {
77+
error?: Error | Array<Error>
78+
): IStructuredError | Array<IStructuredError> => {
7979
const reporterError = this.error(errorMeta, error)
8080
trackError(`BUILD_PANIC`, { error: reporterError })
8181
if (process.env.gatsby_executing_command === `build`) {
@@ -86,9 +86,9 @@ class Reporter {
8686
}
8787

8888
error = (
89-
errorMeta: ErrorMeta | ErrorMeta[],
90-
error?: Error | Error[]
91-
): IStructuredError | IStructuredError[] => {
89+
errorMeta: ErrorMeta | Array<ErrorMeta>,
90+
error?: Error | Array<Error>
91+
): IStructuredError | Array<IStructuredError> => {
9292
let details: {
9393
error?: Error
9494
context: {}
@@ -104,7 +104,7 @@ class Reporter {
104104
if (Array.isArray(error)) {
105105
return error.map(errorItem =>
106106
this.error(errorMeta, errorItem)
107-
) as IStructuredError[]
107+
) as Array<IStructuredError>
108108
}
109109
details.error = error
110110
details.context = {
@@ -121,9 +121,9 @@ class Reporter {
121121
// reporter.error([Error]);
122122
} else if (Array.isArray(errorMeta)) {
123123
// when we get an array of messages, call this function once for each error
124-
return errorMeta.map(errorItem =>
125-
this.error(errorItem)
126-
) as IStructuredError[]
124+
return errorMeta.map(errorItem => this.error(errorItem)) as Array<
125+
IStructuredError
126+
>
127127
// 4.
128128
// reporter.error(errorMeta);
129129
} else if (typeof errorMeta === `object`) {

packages/gatsby-cli/src/reporter/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export type ErrorMeta =
1010
}
1111
| string
1212
| Error
13-
| ErrorMeta[]
13+
| Array<ErrorMeta>

packages/gatsby-cli/src/structured-errors/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface IStructuredStackFrame {
2424
export interface IStructuredError {
2525
code?: string
2626
text: string
27-
stack: IStructuredStackFrame[]
27+
stack: Array<IStructuredStackFrame>
2828
filePath?: string
2929
location?: {
3030
start: ILocationPosition

packages/gatsby-core-utils/src/create-require-from-path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from "path"
55
* We need to use private Module methods in this polyfill
66
*/
77
interface IModulePrivateMethods {
8-
_nodeModulePaths: (directory: string) => string[]
8+
_nodeModulePaths: (directory: string) => Array<string>
99
_compile: (src: string, file: string) => void
1010
}
1111

packages/gatsby-core-utils/src/path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import os from "os"
55
* Joins all given path segments and converts
66
* @param paths A sequence of path segments
77
*/
8-
export function joinPath(...paths: string[]): string {
8+
export function joinPath(...paths: Array<string>): string {
99
const joinedPath = path.join(...paths)
1010
if (os.platform() === `win32`) {
1111
return joinedPath.replace(/\\/g, `\\\\`)

packages/gatsby-core-utils/src/url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import os from "os"
55
* Joins all given segments and converts using a forward slash (/) as a delimiter
66
* @param segments A sequence of segments
77
*/
8-
export function urlResolve(...segments: string[]): string {
8+
export function urlResolve(...segments: Array<string>): string {
99
const joinedPath = path.join(...segments)
1010
if (os.platform() === `win32`) {
1111
return joinedPath.replace(/\\/g, `/`)

packages/gatsby-page-utils/src/ignore-path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface IPathIgnoreOptions {
77

88
export function ignorePath(
99
path: string,
10-
ignore?: IPathIgnoreOptions | string | string[] | null
10+
ignore?: IPathIgnoreOptions | string | Array<string> | null
1111
): boolean {
1212
// Don't do anything if no ignore patterns
1313
if (!ignore) return false

packages/gatsby-plugin-page-creator/src/create-page-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function createPage(
1818
filePath: string,
1919
pagesDirectory: string,
2020
actions: Actions,
21-
ignore: string[],
21+
ignore: Array<string>,
2222
graphql: CreatePagesArgs["graphql"],
2323
reporter: Reporter
2424
): void {

packages/gatsby-plugin-page-creator/src/extract-query.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ function extractUrlParamsForQuery(createdPath: string): string {
6565
}
6666

6767
return parts
68-
.reduce<string[]>((queryParts: string[], part: string): string[] => {
68+
.reduce<Array<string>>((queryParts: Array<string>, part: string): Array<
69+
string
70+
> => {
6971
if (part.startsWith(`{`)) {
7072
return queryParts.concat(
7173
deriveNesting(compose(removeFileExtension, extractField)(part))

packages/gatsby-plugin-page-creator/src/validate-path-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Please change this to: "${filePath.replace(/index$/, ``)}"`
4343
}
4444
})
4545
)
46-
).filter(Boolean) as string[]
46+
).filter(Boolean) as Array<string>
4747

4848
if (file.length === 0 || file[0].length === 0) {
4949
throw new Error(

packages/gatsby-plugin-page-creator/src/watch-collection-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { collectionExtractQueryString } from "./collection-extract-query-string"
1313
export function watchCollectionBuilder(
1414
absolutePath: string,
1515
previousQueryString: string,
16-
paths: string[],
16+
paths: Array<string>,
1717
actions: Actions,
1818
reporter: Reporter,
1919
rerunCollectionBuilder: () => void

packages/gatsby-telemetry/src/__tests__/error-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe(`Errors Helpers`, () => {
9090
expect(sanitizedErrorString).toEqual(
9191
expect.not.stringContaining(`sidharthachatterjee`)
9292
)
93-
const result = sanitizedErrorString.match(/\$SNIP/g) as string[]
93+
const result = sanitizedErrorString.match(/\$SNIP/g) as Array<string>
9494
expect(result.length).toBe(4)
9595

9696
mockCwd.mockRestore()

packages/gatsby-telemetry/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function trackFeatureIsUsed(name: string): void {
3434
instance.trackFeatureIsUsed(name)
3535
}
3636
export function trackCli(
37-
input: string | string[],
37+
input: string | Array<string>,
3838
tags?: ITelemetryTagsPayload,
3939
opts?: ITelemetryOptsPayload
4040
): void {

packages/gatsby-telemetry/src/telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface ITelemetryTagsPayload {
7777
duration?: number
7878
uiSource?: string
7979
valid?: boolean
80-
plugins?: string[]
80+
plugins?: Array<string>
8181
pathname?: string
8282
error?: IStructuredError | Array<IStructuredError>
8383
cacheStatus?: string
@@ -202,7 +202,7 @@ export class AnalyticsTracker {
202202
}
203203

204204
captureEvent(
205-
type: string | string[] = ``,
205+
type: string | Array<string> = ``,
206206
tags: ITelemetryTagsPayload = {},
207207
opts: ITelemetryOptsPayload = { debounce: false }
208208
): void {

packages/gatsby/src/bootstrap/__mocks__/resolve-module-exports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
let mockResults = {}
44

5-
export const resolveModuleExports = (input: unknown): string[] | undefined => {
5+
export const resolveModuleExports = (
6+
input: unknown
7+
): Array<string> | undefined => {
68
// return a mocked result
79
if (typeof input === `string`) {
810
return mockResults[input]

packages/gatsby/src/bootstrap/create-graphql-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const createGraphQLRunner = (
3232
graphqlTracing,
3333
})
3434

35-
const eventTypes: string[] = [
35+
const eventTypes: Array<string> = [
3636
`DELETE_CACHE`,
3737
`CREATE_NODE`,
3838
`DELETE_NODE`,

packages/gatsby/src/bootstrap/load-plugins/__tests__/load-plugins.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe(`Load plugins`, () => {
1010
* Both will cause snapshots to differ.
1111
*/
1212
const replaceFieldsThatCanVary = (
13-
plugins: IFlattenedPlugin[]
14-
): IFlattenedPlugin[] =>
13+
plugins: Array<IFlattenedPlugin>
14+
): Array<IFlattenedPlugin> =>
1515
plugins.map(plugin => {
1616
if (plugin.pluginOptions && plugin.pluginOptions.path) {
1717
plugin.pluginOptions = {

0 commit comments

Comments
 (0)