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(lint): lint config refactoring and re-enable some stylistic rules #11257

Merged
merged 6 commits into from
Aug 15, 2024
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
41 changes: 9 additions & 32 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ module.exports = {
},
},
],
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['$api/*'],
message:
'Importing from $api is only supported in *.routeHooks.{js,ts} files',
},
],
},
],
},
env: {
// We use the most modern environment available. Then we rely on Babel to
Expand Down Expand Up @@ -182,6 +170,8 @@ module.exports = {
rules: {
// This is disabled for now because of our legacy usage of `require`. It should be enabled in the future.
'@typescript-eslint/no-require-imports': 'off',
// This is disabled for now because of our vast usage of `any`. It should be enabled in the future.
'@typescript-eslint/no-explicit-any': 'off',

// We allow exceptions to the no-unused-vars rule for variables that start with an underscore
'no-unused-vars': 'off',
Expand All @@ -190,20 +180,18 @@ module.exports = {
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
],

// TODO(jgmw): Look into enabling these eventually
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/consistent-generic-constructors': 'off',
// We want consistent `import type {} from '...'`
'@typescript-eslint/consistent-type-imports': 'error',

// We want consistent curly brackets
curly: 'error',

// Stylistic rules we have disabled
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'off',
'@typescript-eslint/consistent-type-imports': 'error',

// Specific 'stylistic' rules we alter
camelcase: 'off',
curly: 'error',
},
},
{
Expand Down Expand Up @@ -232,17 +220,6 @@ module.exports = {
jest: true,
},
},
{
files: ['packages/structure/src/**'],
rules: {
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-case-declarations': 'off',
'prefer-const': 'off',
'no-empty': 'warn',
'no-unused-expressions': 'off',
},
},
// Browser Context
//
// We prevent "window" from being used, and instead require "global".
Expand Down
2 changes: 1 addition & 1 deletion packages/api-server/src/logFormatter/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const emojiLog: Record<string, string> = {
trace: '🧵',
}

export const ignoredCustomData: Array<string> = [
export const ignoredCustomData: string[] = [
'time',
'pid',
'hostname',
Expand Down
2 changes: 1 addition & 1 deletion packages/api-server/src/plugins/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function redwoodFastifyGraphQLServer(
if (graphqlOptions?.realtime) {
const { useRedwoodRealtime } = await import('@redwoodjs/realtime')

const originalExtraPlugins: Array<Plugin<any>> =
const originalExtraPlugins: Plugin<any>[] =
graphqlOptions.extraPlugins ?? []
originalExtraPlugins.push(useRedwoodRealtime(graphqlOptions.realtime))
graphqlOptions.extraPlugins = originalExtraPlugins
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const getAuthenticationContext = async ({
}

// Run through decoders until one returns a decoded payload
let authDecoders: Array<Decoder> = []
let authDecoders: Decoder[] = []

if (Array.isArray(authDecoder)) {
authDecoders = authDecoder
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface CacheFindManyOptions<
conditions?: TFindManyArgs
}

export type CacheKey = string | Array<string>
export type CacheKey = string | string[]
export type LatestQuery = Record<string, unknown>

type GenericDelegate = {
Expand Down
27 changes: 12 additions & 15 deletions packages/api/src/validations/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface AcceptanceValidatorOptions extends WithOptionalMessage {
/**
* An array of values that, if any match, will pass the validation.
*/
in?: Array<unknown>
in?: unknown[]
}

type EmailValidatorOptions = WithOptionalMessage
Expand All @@ -34,7 +34,7 @@ interface ExclusionValidatorOptions extends WithOptionalMessage {
/**
* The list of values that cannot be used.
*/
in?: Array<unknown>
in?: unknown[]
caseSensitive?: boolean
}

Expand All @@ -49,7 +49,7 @@ interface InclusionValidatorOptions extends WithOptionalMessage {
/**
* The list of values that can be used.
*/
in?: Array<unknown>
in?: unknown[]
caseSensitive?: boolean
}

Expand All @@ -74,7 +74,7 @@ interface LengthValidatorOptions extends WithOptionalMessage {
* length: { between: [2, 255] }
* })
*/
between?: Array<number>
between?: number[]
}

interface NumericalityValidatorOptions extends WithOptionalMessage {
Expand Down Expand Up @@ -155,7 +155,7 @@ interface CustomValidatorOptions extends WithOptionalMessage {
interface UniquenessValidatorOptions extends WithOptionalMessage {
db?: PrismaClient
}
type UniquenessWhere = Record<'AND' | 'NOT', Array<Record<string, unknown>>>
type UniquenessWhere = Record<'AND' | 'NOT', Record<string, unknown>[]>

interface ValidationRecipe {
/**
Expand Down Expand Up @@ -189,7 +189,7 @@ interface ValidationRecipe {
*
* Opposite of the [inclusion](https://redwoodjs.com/docs/services.html#inclusion) validation.
*/
exclusion?: Array<unknown> | ExclusionValidatorOptions
exclusion?: unknown[] | ExclusionValidatorOptions
/**
* Requires that the value match a given regular expression.
*/
Expand All @@ -199,7 +199,7 @@ interface ValidationRecipe {
*
* Opposite of the [exclusion](https://redwoodjs.com/docs/services.html#exclusion) validation.
*/
inclusion?: Array<unknown> | InclusionValidatorOptions
inclusion?: unknown[] | InclusionValidatorOptions
/**
* Requires that the value meet one or more of a number of string length validations.
*/
Expand Down Expand Up @@ -270,7 +270,7 @@ const VALIDATORS = {
name: string,
options: boolean | AcceptanceValidatorOptions,
) => {
let acceptedValues: Array<unknown>
let acceptedValues: unknown[]

if (typeof options === 'object') {
acceptedValues = options.in || []
Expand Down Expand Up @@ -309,7 +309,7 @@ const VALIDATORS = {
exclusion: (
value: unknown,
name: string,
options: Array<unknown> | ExclusionValidatorOptions,
options: unknown[] | ExclusionValidatorOptions,
) => {
const [exclusionList, val] = prepareExclusionInclusion(value, options)

Expand Down Expand Up @@ -348,7 +348,7 @@ const VALIDATORS = {
inclusion: (
value: unknown,
name: string,
options: Array<unknown> | InclusionValidatorOptions,
options: unknown[] | InclusionValidatorOptions,
) => {
const [inclusionList, val] = prepareExclusionInclusion(value, options)

Expand Down Expand Up @@ -554,11 +554,8 @@ const validationError = (
// can simply be used with Array.includes to perform exclusion/inclusion checks.
const prepareExclusionInclusion = (
value: unknown,
options:
| Array<unknown>
| InclusionValidatorOptions
| ExclusionValidatorOptions,
): [Array<unknown>, unknown] => {
options: unknown[] | InclusionValidatorOptions | ExclusionValidatorOptions,
): [unknown[], unknown] => {
const inputList = (Array.isArray(options) && options) || options.in || []

// default case sensitivity to true
Expand Down
6 changes: 3 additions & 3 deletions packages/auth-providers/dbAuth/api/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ export function getDbAuthResponseBuilder(
},
corsHeaders: CorsHeaders,
) => {
const headers: Record<string, string | Array<string>> = {
const headers: Record<string, string | string[]> = {
...Object.fromEntries(response.headers?.entries() || []),
...corsHeaders,
}

const dbAuthResponse: {
statusCode: number
headers: Record<string, string | Array<string>>
multiValueHeaders?: Record<string, Array<string>>
headers: Record<string, string | string[]>
multiValueHeaders?: Record<string, string[]>
body?: string
} = {
...response,
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-config/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const BABEL_PLUGIN_TRANSFORM_RUNTIME_OPTIONS = {
// Plugin shape: [ ["Target", "Options", "name"] ],
// a custom "name" can be supplied so that user's do not accidentally overwrite
// Redwood's own plugins when they specify their own.
export type PluginList = Array<PluginShape>
export type PluginList = PluginShape[]
type PluginShape =
| [PluginTarget, PluginOptions, undefined | string]
| [PluginTarget, PluginOptions]
Expand All @@ -85,7 +85,7 @@ export const getApiSideBabelPlugins = ({
} = {}) => {
const tsConfig = parseTypeScriptConfigFiles()

const plugins: Array<PluginShape | boolean> = [
const plugins: (PluginShape | boolean)[] = [
...getCommonPlugins(),
// Needed to support `/** @jsxImportSource custom-jsx-library */`
// comments in JSX files
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-config/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if (!RUNTIME_CORE_JS_VERSION) {
)
}

export const getCommonPlugins = (): Array<[string, PluginOptions]> => {
export const getCommonPlugins = (): [string, PluginOptions][] => {
return [
['@babel/plugin-transform-class-properties', { loose: true }],
// Note: The private method loose mode configuration setting must be the
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-config/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export const getWebSideOverrides = (
forPrerender: false,
forRsc: false,
},
): Array<TransformOptions> => {
): TransformOptions[] => {
// Have to use a readonly array here because of a limitation in TS
// See https://stackoverflow.com/a/70763406/88106
const overrides: ReadonlyArray<false | TransformOptions> = [
const overrides: readonly (false | TransformOptions)[] = [
{
test: /.+Cell.(js|tsx|jsx)$/,
plugins: [require('./plugins/babel-plugin-redwood-cell').default],
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-helpers/src/auth/setupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface AuthHandlerArgs {
webAuthn?: boolean
webPackages?: string[]
apiPackages?: string[]
extraTasks?: Array<ListrTask<AuthGeneratorCtx> | undefined>
extraTasks?: (ListrTask<AuthGeneratorCtx> | undefined)[]
notes?: string[]
verbose?: boolean
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let mockExecutedTaskTitles: Array<string> = []
let mockSkippedTaskTitles: Array<string> = []
let mockExecutedTaskTitles: string[] = []
let mockSkippedTaskTitles: string[] = []

vi.mock('fs', async () => {
const memfs = await import('memfs')
Expand Down Expand Up @@ -32,7 +32,7 @@ vi.mock('../../../../../../lib/runTransform', () => {
vi.mock('listr2', () => {
return {
// Return a constructor function, since we're calling `new` on Listr
Listr: vi.fn().mockImplementation((tasks: Array<any>) => {
Listr: vi.fn().mockImplementation((tasks: any[]) => {
return {
run: async () => {
mockExecutedTaskTitles = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let mockExecutedTaskTitles: Array<string> = []
let mockSkippedTaskTitles: Array<string> = []
let mockExecutedTaskTitles: string[] = []
let mockSkippedTaskTitles: string[] = []

vi.mock('fs', async () => ({ ...memfsFs, default: { ...memfsFs } }))
vi.mock('node:fs', async () => ({ ...memfsFs, default: { ...memfsFs } }))
Expand All @@ -12,7 +12,7 @@ vi.mock('../../../../../../lib/runTransform', () => ({
vi.mock('listr2', () => {
return {
// Return a constructor function, since we're calling `new` on Listr
Listr: vi.fn().mockImplementation((tasks: Array<any>) => {
Listr: vi.fn().mockImplementation((tasks: any[]) => {
return {
run: async () => {
mockExecutedTaskTitles = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const rwPaths = getPaths()
export const handler = async ({ force }: Args) => {
const extension = isTypeScriptProject() ? 'ts' : 'js'

const notes: Array<string> = []
const notes: string[] = []

const tasks = new Listr([
addApiPackages(['@envelop/sentry@5', '@sentry/node@7']),
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/setup/ui/__tests__/tailwindcss.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let mockExecutedTaskTitles: Array<string> = []
let mockSkippedTaskTitles: Array<string> = []
let mockSkipValues: Array<string> = []
let mockExecutedTaskTitles: string[] = []
let mockSkippedTaskTitles: string[] = []
let mockSkipValues: string[] = []
let mockPrompt: (() => boolean) | undefined

vi.mock('fs', async () => ({ ...memfsFs, default: { ...memfsFs } }))
Expand All @@ -21,7 +21,7 @@ vi.mock('fs-extra', async () => {
}
})
vi.mock('execa', () => ({
default: (...args: Array<any>) => {
default: (...args: any[]) => {
// Create an empty config file when `tailwindcss init` is called.
// If we don't do this, later stages of the setup will fail.
if (args[0] === 'yarn' && args[1].join(' ').includes('tailwindcss init')) {
Expand All @@ -33,7 +33,7 @@ vi.mock('execa', () => ({
vi.mock('listr2', () => {
return {
// Return a constructor function, since we're calling `new` on Listr
Listr: vi.fn().mockImplementation((tasks: Array<any>) => {
Listr: vi.fn().mockImplementation((tasks: any[]) => {
return {
run: async () => {
mockExecutedTaskTitles = []
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/testLib/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const parseGqlQueryToAst = (gqlQuery: string) => {
}

export const parseDocumentAST = (document: DocumentNode) => {
const operations: Array<Operation> = []
const operations: Operation[] = []

visit(document, {
OperationDefinition(node: OperationDefinitionNode) {
Expand All @@ -220,11 +220,11 @@ export const parseDocumentAST = (document: DocumentNode) => {
interface Operation {
operation: OperationTypeNode
name: string | undefined
fields: Array<string | Field>
fields: (string | Field)[]
}

interface Field {
string: Array<string | Field>
string: (string | Field)[]
}

const getFields = (field: FieldNode): any => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export default async function transform(file: FileInfo, api: API) {
)
})

const svgsToConvert: Array<{
const svgsToConvert: {
filePath: string
importSourcePath: StringLiteral
}> = []
}[] = []

const importOrExportStatementsWithSvg = [
...svgImports.paths(),
Expand Down
Loading
Loading