Skip to content

Commit

Permalink
chore(linting): Re-enable some ts-eslint rules (#11256)
Browse files Browse the repository at this point in the history
Refactors the eslint config to re-enable some of the recommended rules
which had been disable.

This PR does change types but my hope is that they aren't functional
changes so will not be breaking or have an effect.
  • Loading branch information
Josh-Walker-GM authored Aug 14, 2024
1 parent 560df46 commit f8dc55a
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 32 deletions.
34 changes: 16 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,30 @@ module.exports = {
},
// TypeScript specific linting
{
files: ['*.ts', '*.tsx'],
files: ['*.ts', '*.mts', '*.tsx'],
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
],
rules: {
// TODO: look into enabling these eventually
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/prefer-function-type': 'off',

// Specific 'recommended' rules we alter
'@typescript-eslint/no-var-requires': 'off',
// 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',
'@typescript-eslint/no-empty-object-type': 'off',

// We allow exceptions to the no-unused-vars rule for variables that start with an underscore
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
],

// TODO: Look into enabling these eventually
// TODO(jgmw): Look into enabling these eventually
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/consistent-generic-constructors': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
Expand All @@ -220,14 +215,17 @@ module.exports = {
jest: true,
},
},
// Set the correct environment for this eslint config file
{
files: [
'.babelrc.js',
'babel.config.js',
'.eslintrc.js',
'*.config.js',
'jest.setup.js',
],
files: ['.eslintrc.js'],
env: {
node: true,
commonjs: true,
},
},
// Set the correct environment for Jest config files
{
files: ['jest.config.js', 'jest.setup.js'],
env: {
node: true,
commonjs: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/validations/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface AcceptanceValidatorOptions extends WithOptionalMessage {
in?: Array<unknown>
}

interface EmailValidatorOptions extends WithOptionalMessage {}
type EmailValidatorOptions = WithOptionalMessage

interface ExclusionValidatorOptions extends WithOptionalMessage {
/**
Expand Down
1 change: 1 addition & 0 deletions packages/auth-providers/auth0/web/src/auth0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { CurrentUser } from '@redwoodjs/auth'
import { createAuthentication } from '@redwoodjs/auth'

// TODO: Map out this user properly.
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface Auth0User {}

export function createAuth(
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/dbAuth/middleware/build.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'
import { writeFileSync } from 'node:fs'

import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'
import { generateCjsTypes } from '@redwoodjs/framework-tools/cjsTypes'
import { writeFileSync } from 'node:fs'

// CJS build
await build({
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/supabase/middleware/build.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'
import { writeFileSync } from 'node:fs'

import { build, defaultBuildOptions } from '@redwoodjs/framework-tools'
import { generateCjsTypes } from '@redwoodjs/framework-tools/cjsTypes'
import { writeFileSync } from 'node:fs'

// CJS build
await build({
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-packages/storybook-vite/build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { build, defaultIgnorePatterns } from '@redwoodjs/framework-tools'

import fg from 'fast-glob'

import { build, defaultIgnorePatterns } from '@redwoodjs/framework-tools'

await build()

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { build, defaultIgnorePatterns } from '@redwoodjs/framework-tools'

import fg from 'fast-glob'

import { build, defaultIgnorePatterns } from '@redwoodjs/framework-tools'

await build()

// The CLI depends on assets like templates files
Expand Down
1 change: 1 addition & 0 deletions packages/cli/testUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface CustomMatchers<R = unknown> {
}

declare module 'vitest' {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface Assertion<T = any> extends CustomMatchers<T> {}
}

Expand Down
1 change: 1 addition & 0 deletions packages/context/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getAsyncStoreInstance } from './store'

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface GlobalContext extends Record<string, unknown> {}

export const createContextProxy = (target: GlobalContext) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/vitest.setup.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach } from 'vitest'
import { cleanup } from '@testing-library/react'
import { afterEach } from 'vitest'
import '@testing-library/jest-dom/vitest'

afterEach(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server/src/globalContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getAsyncStoreInstance } from './globalContextStore'
/**
* @deprecated This type will be available only from the `@redwoodjs/context` package in a future release.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface GlobalContext extends Record<string, unknown> {}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export { SkipNavLink, SkipNavContent } from './skipNav.js'
* }
*/
// Keep this in index.ts so it can be extended with declaration merging
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface AvailableRoutes {}

// Used by packages/internal/src/generate/templates/web-routerRoutes.d.ts.template
Expand Down
2 changes: 2 additions & 0 deletions packages/router/src/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { createNamedContext } from './createNamedContext.js'
import { gHistory } from './history.js'
import type { TrailingSlashesTypes } from './util.js'

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface LocationContextType extends URL {}

const LocationContext = createNamedContext<LocationContextType>('Location')

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface Location extends URL {}

interface LocationProviderProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/router/vitest.setup.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@testing-library/jest-dom/vitest'

import { afterEach, vi } from 'vitest'
import { cleanup } from '@testing-library/react'
import { afterEach, vi } from 'vitest'

vi.spyOn(globalThis, 'scrollTo').mockImplementation(() => {})

Expand Down
1 change: 1 addition & 0 deletions packages/server-store/src/serverStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AsyncLocalStorage } from 'async_hooks'
import type { ServerAuthState } from '@redwoodjs/auth/dist/AuthProvider/ServerAuthProvider.js' with { 'resolution-mode': 'import' }
import { CookieJar } from '@redwoodjs/cookie-jar'

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface ServerStore extends Map<string, any> {}

let PER_REQ_STORAGE: AsyncLocalStorage<ServerStore>
Expand Down
2 changes: 1 addition & 1 deletion packages/structure/src/x/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,6 @@ export function Command_cli(cmd: string, title = 'run...'): Command {
return { command: 'redwoodjs.cli', arguments: [cmd], title }
}

type ReplacePropTypes<T extends {}, Replacements extends {}> = {
type ReplacePropTypes<T extends object, Replacements extends object> = {
[K in keyof T]: K extends keyof Replacements ? Replacements[K] : T[K]
}
2 changes: 1 addition & 1 deletion packages/testing/vitest.setup.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@testing-library/jest-dom/vitest'

import { afterEach, beforeAll } from 'vitest'
import { cleanup } from '@testing-library/react'
import { afterEach, beforeAll } from 'vitest'

import { startMSW } from './src/web/mockRequests'

Expand Down
8 changes: 8 additions & 0 deletions packages/web/src/apollo/typeOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@ import type {

// @MARK: Override relevant types from Apollo here
declare global {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface QueryOperationResult<
TData = any,
TVariables extends OperationVariables = OperationVariables,
> extends QueryResult<TData, TVariables> {}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface MutationOperationResult<TData, TVariables>
extends MutationTuple<TData, TVariables> {}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface SubscriptionOperationResult<
TData = any,
TVariables extends OperationVariables = OperationVariables,
> extends SubscriptionResult<TData, TVariables> {}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface GraphQLQueryHookOptions<
TData,
TVariables extends OperationVariables,
> extends QueryHookOptions<TData, TVariables> {}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface GraphQLMutationHookOptions<TData, TVariables>
extends MutationHookOptions<TData, TVariables> {}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface GraphQLSubscriptionHookOptions<
TData,
TVariables extends OperationVariables,
> extends SubscriptionHookOptions<TData, TVariables> {}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface SuspenseQueryOperationResult<
TData = any,
TVariables extends OperationVariables = OperationVariables,
> extends UseSuspenseQueryResult<TData, TVariables> {}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface GraphQLSuspenseQueryHookOptions<
TData,
TVariables extends OperationVariables,
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/global.web-auto-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare global {
}

// not defining it here, because it gets overridden by Apollo provider anyway
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface MutationOperationResult<TData, TVariables> {}

// Overridable useQuery and useMutation hooks
Expand Down
2 changes: 1 addition & 1 deletion packages/web/vitest.setup.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@testing-library/jest-dom/vitest'

import { afterEach } from 'vitest'
import { cleanup } from '@testing-library/react'
import { afterEach } from 'vitest'
import '@testing-library/jest-dom/vitest'

afterEach(() => {
Expand Down

0 comments on commit f8dc55a

Please sign in to comment.