Skip to content

Commit

Permalink
style: use generic style for array types (#26738)
Browse files Browse the repository at this point in the history
Using this style provides consistency with Set, Map, etc.

Co-authored-by: Blaine Kasten <[email protected]>
  • Loading branch information
chooban and blainekasten authored Sep 6, 2020
1 parent d878bfd commit 3e92795
Show file tree
Hide file tree
Showing 90 changed files with 313 additions and 278 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ module.exports = {
// bump to @typescript-eslint/parser started showing Flow related errors in ts(x) files
// so disabling them in .ts(x) files
"flowtype/no-types-missing-file-annotation": "off",
"@typescript-eslint/array-type": [
'error',
{ default: 'generic' },
],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function ({

path.parent.id = t.objectPattern(
path.parent.id.elements.reduce(
(acc: BabelTypes.ObjectProperty[], element, i) => {
(acc: Array<BabelTypes.ObjectProperty>, element, i) => {
if (element) {
acc.push(t.objectProperty(t.numericLiteral(i), element))
}
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-cli/src/create-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { initStarter } from "./init-starter"
import { recipesHandler } from "./recipes"
import { startGraphQLServer } from "gatsby-recipes"

const handlerP = (fn: Function) => (...args: unknown[]): void => {
const handlerP = (fn: Function) => (...args: Array<unknown>): void => {
Promise.resolve(fn(...args)).then(
() => process.exit(0),
err => report.panic(err)
Expand Down Expand Up @@ -422,7 +422,7 @@ Gatsby version: ${gatsbyVersion}
}
}

export const createCli = (argv: string[]): yargs.Arguments => {
export const createCli = (argv: Array<string>): yargs.Arguments => {
const cli = yargs(argv).parserConfiguration({
"boolean-negation": false,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/init-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import reporter from "../lib/reporter"

const spawnWithArgs = (
file: string,
args: string[],
args: Array<string>,
options?: execa.Options
): execa.ExecaChildProcess =>
execa(file, args, { stdio: `inherit`, preferLocal: false, ...options })
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-cli/src/reporter/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const packagesToSkipTest = new RegExp(
// TO-DO: move this this out of this file (and probably delete this file completely)
// it's here because it re-implements similar thing as `pretty-error` already does
export const sanitizeStructuredStackTrace = (
stack: stackTrace.StackFrame[]
): IStructuredStackFrame[] => {
stack: Array<stackTrace.StackFrame>
): Array<IStructuredStackFrame> => {
// first filter out not useful call sites
stack = stack.filter(callSite => {
if (!callSite.getFileName()) {
Expand Down Expand Up @@ -86,7 +86,7 @@ export function getErrorFormatter(): PrettyError {
}

prettyError.render = (
err: PrettyRenderError | PrettyRenderError[]
err: PrettyRenderError | Array<PrettyRenderError>
): string => {
if (Array.isArray(err)) {
return err.map(e => prettyError.render(e)).join(`\n`)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/reporter/loggers/ink/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CLI extends React.Component<ICLIProps, ICLIState> {
readonly state: ICLIState = {
hasError: false,
}
memoizedReactElementsForMessages: React.ReactElement[] = []
memoizedReactElementsForMessages: Array<React.ReactElement> = []

componentDidCatch(error: Error, info: React.ErrorInfo): void {
trackBuildError(`INK`, {
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby-cli/src/reporter/patch-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import util from "util"
import { reporter as gatsbyReporter } from "./reporter"

export function patchConsole(reporter: typeof gatsbyReporter): void {
console.log = (...args: any[]): void => {
console.log = (...args: Array<any>): void => {
const [format, ...rest] = args
reporter.log(util.format(format === undefined ? `` : format, ...rest))
}
console.warn = (...args: any[]): void => {
console.warn = (...args: Array<any>): void => {
const [format, ...rest] = args
reporter.warn(util.format(format === undefined ? `` : format, ...rest))
}
console.info = (...args: any[]): void => {
console.info = (...args: Array<any>): void => {
const [format, ...rest] = args
reporter.info(util.format(format === undefined ? `` : format, ...rest))
}
console.error = (format: any, ...args: any[]): void => {
console.error = (format: any, ...args: Array<any>): void => {
reporter.error(util.format(format === undefined ? `` : format, ...args))
}
}
4 changes: 2 additions & 2 deletions packages/gatsby-cli/src/reporter/redux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const diagnosticsMiddleware = createStructuredLoggingDiagnosticsMiddleware(
export type GatsbyCLIStore = typeof store
type StoreListener = (store: GatsbyCLIStore) => void
type ActionLogListener = (action: ActionsUnion) => any
type Thunk = (...args: any[]) => ActionsUnion
type Thunk = (...args: Array<any>) => ActionsUnion

const storeSwapListeners: StoreListener[] = []
const storeSwapListeners: Array<StoreListener> = []
const onLogActionListeners = new Set<ActionLogListener>()

export const getStore = (): typeof store => store
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/reporter/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Actions, ActivityStatuses, ActivityTypes } from "../constants"
import { IStructuredError } from "../../structured-errors/types"

export interface IGatsbyCLIState {
messages: ILog[]
messages: Array<ILog>
activities: {
[id: string]: IActivity
}
Expand Down
12 changes: 6 additions & 6 deletions packages/gatsby-cli/src/reporter/reporter-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export interface IProgressReporter {
tick(increment?: number): void
panicOnBuild(
arg: any,
...otherArgs: any[]
): IStructuredError | IStructuredError[]
panic(arg: any, ...otherArgs: any[]): void
...otherArgs: Array<any>
): IStructuredError | Array<IStructuredError>
panic(arg: any, ...otherArgs: Array<any>): void
end(): void
done(): void
total: number
Expand Down Expand Up @@ -82,8 +82,8 @@ export const createProgressReporter = ({

panicOnBuild(
errorMeta: ErrorMeta,
error?: Error | Error[]
): IStructuredError | IStructuredError[] {
error?: Error | Array<Error>
): IStructuredError | Array<IStructuredError> {
span.finish()

reporterActions.setActivityErrored({
Expand All @@ -93,7 +93,7 @@ export const createProgressReporter = ({
return reporter.panicOnBuild(errorMeta, error)
},

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

reporterActions.endActivity({
Expand Down
12 changes: 6 additions & 6 deletions packages/gatsby-cli/src/reporter/reporter-timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export interface ITimerReporter {
setStatus(statusText: string): void
panicOnBuild(
arg: any,
...otherArgs: any[]
): IStructuredError | IStructuredError[]
panic(arg: any, ...otherArgs: any[]): void
...otherArgs: Array<any>
): IStructuredError | Array<IStructuredError>
panic(arg: any, ...otherArgs: Array<any>): void
end(): void
span: Span
}
Expand Down Expand Up @@ -52,8 +52,8 @@ export const createTimerReporter = ({

panicOnBuild(
errorMeta: ErrorMeta,
error?: Error | Error[]
): IStructuredError | IStructuredError[] {
error?: Error | Array<Error>
): IStructuredError | Array<IStructuredError> {
span.finish()

reporterActions.setActivityErrored({
Expand All @@ -63,7 +63,7 @@ export const createTimerReporter = ({
return reporter.panicOnBuild(errorMeta, error)
},

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

reporterActions.endActivity({
Expand Down
20 changes: 10 additions & 10 deletions packages/gatsby-cli/src/reporter/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Reporter {
/**
* Log arguments and exit process with status 1.
*/
panic = (errorMeta: ErrorMeta, error?: Error | Error[]): never => {
panic = (errorMeta: ErrorMeta, error?: Error | Array<Error>): never => {
const reporterError = this.error(errorMeta, error)
trackError(`GENERAL_PANIC`, { error: reporterError })
prematureEnd()
Expand All @@ -74,8 +74,8 @@ class Reporter {

panicOnBuild = (
errorMeta: ErrorMeta,
error?: Error | Error[]
): IStructuredError | IStructuredError[] => {
error?: Error | Array<Error>
): IStructuredError | Array<IStructuredError> => {
const reporterError = this.error(errorMeta, error)
trackError(`BUILD_PANIC`, { error: reporterError })
if (process.env.gatsby_executing_command === `build`) {
Expand All @@ -86,9 +86,9 @@ class Reporter {
}

error = (
errorMeta: ErrorMeta | ErrorMeta[],
error?: Error | Error[]
): IStructuredError | IStructuredError[] => {
errorMeta: ErrorMeta | Array<ErrorMeta>,
error?: Error | Array<Error>
): IStructuredError | Array<IStructuredError> => {
let details: {
error?: Error
context: {}
Expand All @@ -104,7 +104,7 @@ class Reporter {
if (Array.isArray(error)) {
return error.map(errorItem =>
this.error(errorMeta, errorItem)
) as IStructuredError[]
) as Array<IStructuredError>
}
details.error = error
details.context = {
Expand All @@ -121,9 +121,9 @@ class Reporter {
// reporter.error([Error]);
} else if (Array.isArray(errorMeta)) {
// when we get an array of messages, call this function once for each error
return errorMeta.map(errorItem =>
this.error(errorItem)
) as IStructuredError[]
return errorMeta.map(errorItem => this.error(errorItem)) as Array<
IStructuredError
>
// 4.
// reporter.error(errorMeta);
} else if (typeof errorMeta === `object`) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/reporter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export type ErrorMeta =
}
| string
| Error
| ErrorMeta[]
| Array<ErrorMeta>
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/structured-errors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface IStructuredStackFrame {
export interface IStructuredError {
code?: string
text: string
stack: IStructuredStackFrame[]
stack: Array<IStructuredStackFrame>
filePath?: string
location?: {
start: ILocationPosition
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-core-utils/src/create-require-from-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from "path"
* We need to use private Module methods in this polyfill
*/
interface IModulePrivateMethods {
_nodeModulePaths: (directory: string) => string[]
_nodeModulePaths: (directory: string) => Array<string>
_compile: (src: string, file: string) => void
}

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-core-utils/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os from "os"
* Joins all given path segments and converts
* @param paths A sequence of path segments
*/
export function joinPath(...paths: string[]): string {
export function joinPath(...paths: Array<string>): string {
const joinedPath = path.join(...paths)
if (os.platform() === `win32`) {
return joinedPath.replace(/\\/g, `\\\\`)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-core-utils/src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os from "os"
* Joins all given segments and converts using a forward slash (/) as a delimiter
* @param segments A sequence of segments
*/
export function urlResolve(...segments: string[]): string {
export function urlResolve(...segments: Array<string>): string {
const joinedPath = path.join(...segments)
if (os.platform() === `win32`) {
return joinedPath.replace(/\\/g, `/`)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-page-utils/src/ignore-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface IPathIgnoreOptions {

export function ignorePath(
path: string,
ignore?: IPathIgnoreOptions | string | string[] | null
ignore?: IPathIgnoreOptions | string | Array<string> | null
): boolean {
// Don't do anything if no ignore patterns
if (!ignore) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createPage(
filePath: string,
pagesDirectory: string,
actions: Actions,
ignore: string[],
ignore: Array<string>,
graphql: CreatePagesArgs["graphql"],
reporter: Reporter
): void {
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-page-creator/src/extract-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ function extractUrlParamsForQuery(createdPath: string): string {
}

return parts
.reduce<string[]>((queryParts: string[], part: string): string[] => {
.reduce<Array<string>>((queryParts: Array<string>, part: string): Array<
string
> => {
if (part.startsWith(`{`)) {
return queryParts.concat(
deriveNesting(compose(removeFileExtension, extractField)(part))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Please change this to: "${filePath.replace(/index$/, ``)}"`
}
})
)
).filter(Boolean) as string[]
).filter(Boolean) as Array<string>

if (file.length === 0 || file[0].length === 0) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { collectionExtractQueryString } from "./collection-extract-query-string"
export function watchCollectionBuilder(
absolutePath: string,
previousQueryString: string,
paths: string[],
paths: Array<string>,
actions: Actions,
reporter: Reporter,
rerunCollectionBuilder: () => void
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-telemetry/src/__tests__/error-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe(`Errors Helpers`, () => {
expect(sanitizedErrorString).toEqual(
expect.not.stringContaining(`sidharthachatterjee`)
)
const result = sanitizedErrorString.match(/\$SNIP/g) as string[]
const result = sanitizedErrorString.match(/\$SNIP/g) as Array<string>
expect(result.length).toBe(4)

mockCwd.mockRestore()
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-telemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function trackFeatureIsUsed(name: string): void {
instance.trackFeatureIsUsed(name)
}
export function trackCli(
input: string | string[],
input: string | Array<string>,
tags?: ITelemetryTagsPayload,
opts?: ITelemetryOptsPayload
): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-telemetry/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface ITelemetryTagsPayload {
duration?: number
uiSource?: string
valid?: boolean
plugins?: string[]
plugins?: Array<string>
pathname?: string
error?: IStructuredError | Array<IStructuredError>
cacheStatus?: string
Expand Down Expand Up @@ -202,7 +202,7 @@ export class AnalyticsTracker {
}

captureEvent(
type: string | string[] = ``,
type: string | Array<string> = ``,
tags: ITelemetryTagsPayload = {},
opts: ITelemetryOptsPayload = { debounce: false }
): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

let mockResults = {}

export const resolveModuleExports = (input: unknown): string[] | undefined => {
export const resolveModuleExports = (
input: unknown
): Array<string> | undefined => {
// return a mocked result
if (typeof input === `string`) {
return mockResults[input]
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/create-graphql-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createGraphQLRunner = (
graphqlTracing,
})

const eventTypes: string[] = [
const eventTypes: Array<string> = [
`DELETE_CACHE`,
`CREATE_NODE`,
`DELETE_NODE`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe(`Load plugins`, () => {
* Both will cause snapshots to differ.
*/
const replaceFieldsThatCanVary = (
plugins: IFlattenedPlugin[]
): IFlattenedPlugin[] =>
plugins: Array<IFlattenedPlugin>
): Array<IFlattenedPlugin> =>
plugins.map(plugin => {
if (plugin.pluginOptions && plugin.pluginOptions.path) {
plugin.pluginOptions = {
Expand Down
Loading

0 comments on commit 3e92795

Please sign in to comment.