Skip to content

Commit

Permalink
Add eslint configuration (#9144)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed May 14, 2024
1 parent 1cef2ec commit 623592b
Show file tree
Hide file tree
Showing 50 changed files with 466 additions and 83 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

66 changes: 66 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// @ts-check

const eslint = require('@eslint/js')
const tseslint = require('typescript-eslint')

module.exports = tseslint.config(
{
ignores: [
'**/.keystone/',
'**/dist/',
'**/node_modules/',
'**/syntax-error.js'
],
},
eslint.configs.recommended,
...tseslint.configs.strict,
// ...tseslint.configs.stylistic,
{
rules: {
// TODO: remove
'no-empty': 'off',
'no-extra-boolean-cast': 'off',
'no-async-promise-executor': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'prefer-const': 'off',
'no-regex-spaces': 'off',
'no-useless-escape': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-invalid-void-type': 'off',
'@typescript-eslint/no-namespace': 'off',
'import/no-unresolved': 'off',
// TODO: remove

semi: ['error', 'never'],
'block-spacing': ['error', 'always'],
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
'comma-spacing': ['error', { before: false, after: true }],
'func-call-spacing': ['error', 'never'],
'no-undef': 'off', // https://typescript-eslint.io/troubleshooting/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
'semi-spacing': ['error', { before: false, after: true }],
'space-before-blocks': ['error', 'always'],
'space-before-function-paren': ['error', 'always'],
'space-in-parens': ['error', 'never'],
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: { delimiter: 'none' },
singleline: { delimiter: 'comma', requireLast: false }
}
],
'@typescript-eslint/consistent-type-imports': ['error', {
disallowTypeAnnotations: true,
fixStyle: 'inline-type-imports',
prefer: 'type-imports',
}],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/semi': ['error', 'never'],
}
}
)
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@changesets/cli": "^2.18.0",
"@changesets/get-github-info": "^0.6.0",
"@changesets/get-release-plan": "^4.0.0",
"@eslint/js": "^9.2.0",
"@manypkg/cli": "^0.21.0",
"@preconstruct/cli": "2.8.4",
"@types/jest": "^29.0.0",
Expand All @@ -37,9 +38,11 @@
"@types/react-dom": "^18.0.4",
"esbuild": "^0.21.0",
"esbuild-jest": "^0.5.0",
"eslint": "^9.2.0",
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.0.0",
"typescript": "~5.4.0"
"typescript": "~5.4.5",
"typescript-eslint": "^7.8.0"
},
"preconstruct": {
"packages": [
Expand Down
4 changes: 2 additions & 2 deletions packages/cloudinary/src/views/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FieldContainer, FieldDescription, FieldLabel } from '@keystone-ui/field
import { Pill } from '@keystone-ui/pill'
import { Button } from '@keystone-ui/button'
import { type FieldProps } from '@keystone-6/core/types'
import { type controller } from '.'

function useObjectURL (fileData: File | undefined) {
let [objectURL, setObjectURL] = useState<string | undefined>(undefined)
Expand All @@ -28,7 +29,7 @@ export function Field ({
field,
value,
onChange,
}: FieldProps<typeof import('.').controller>) {
}: FieldProps<typeof controller>) {
const inputRef = useRef<HTMLInputElement | null>(null)

const errorMessage = value.kind === 'upload' ? validateImage(value.data) : undefined
Expand All @@ -42,7 +43,6 @@ export function Field ({
// Generate a random input key when the value changes, to ensure the file input is unmounted and
// remounted (this is the only way to reset its value and ensure onChange will fire again if
// the user selects the same file again)
// eslint-disable-next-line react-hooks/exhaustive-deps
const inputKey = useMemo(() => Math.random(), [value])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ function useQueryParamsFromLocalStorage (listKey: string) {
}
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[localStorageKey, router.isReady]
)
useEffect(() => {
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import { printSchema, GraphQLSchema } from 'graphql'
import { type ChildProcess } from 'node:child_process'

import { printSchema, type GraphQLSchema } from 'graphql'
import { getGenerators, formatSchema } from '@prisma/internals'
import { ExitError } from './scripts/utils'
import { type __ResolvedKeystoneConfig } from './types'
Expand Down Expand Up @@ -105,8 +107,7 @@ export async function generatePrismaClient (cwd: string, system: System) {
await generator.generate()
} finally {
const closePromise = new Promise<void>(resolve => {
const child = (generator as any).generatorProcess
.child as import('child_process').ChildProcess
const child = (generator as any).generatorProcess.child as ChildProcess
child.once('exit', () => {
resolve()
})
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/fields/non-null-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export function resolveHasValidation ({
db,
validation
}: {
db?: { isNullable?: boolean },
validation?: unknown,
db?: { isNullable?: boolean }
validation?: unknown
}) {
if (db?.isNullable === false) return true
if (validation !== undefined) return true
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/bigInt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type BigIntFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
const MAX_INT = 9223372036854775807n
const MIN_INT = -9223372036854775808n

export function bigInt <ListTypeInfo extends BaseListTypeInfo>(
export function bigInt <ListTypeInfo extends BaseListTypeInfo> (
config: BigIntFieldConfig<ListTypeInfo> = {}
): FieldTypeFunc<ListTypeInfo> {
const {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/checkbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type CheckboxFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
}
}

export function checkbox <ListTypeInfo extends BaseListTypeInfo>(
export function checkbox <ListTypeInfo extends BaseListTypeInfo> (
config: CheckboxFieldConfig<ListTypeInfo> = {}
): FieldTypeFunc<ListTypeInfo> {
const {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fields/types/decimal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { graphql } from '../../..'
import { assertReadIsNonNullAllowed, getResolvedIsNullable } from '../../non-null-graphql'
import { filters } from '../../filters'
import { type DecimalFieldMeta } from './views'

export type DecimalFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> & {
Expand Down Expand Up @@ -179,7 +180,7 @@ export const decimal =
}),
__ksTelemetryFieldTypeName: '@keystone-6/decimal',
views: '@keystone-6/core/fields/types/decimal/views',
getAdminMeta: (): import('./views').DecimalFieldMeta => ({
getAdminMeta: (): DecimalFieldMeta => ({
defaultValue: defaultValue ?? null,
precision,
scale,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function inputResolver (
return context.files(storage).getDataFromStream(upload.createReadStream(), upload.filename)
}

export function file <ListTypeInfo extends BaseListTypeInfo>(config: FileFieldConfig<ListTypeInfo>): FieldTypeFunc<ListTypeInfo> {
export function file <ListTypeInfo extends BaseListTypeInfo> (config: FileFieldConfig<ListTypeInfo>): FieldTypeFunc<ListTypeInfo> {
return meta => {
const { fieldKey } = meta
const storage = meta.getStorage(config.storage)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/fields/types/file/views/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { FieldContainer, FieldDescription, FieldLabel } from '@keystone-ui/field
import { Button } from '@keystone-ui/button'
import { type FieldProps } from '../../../../types'
import { type FileValue } from './index'
import { type controller } from '.'

export function Field ({
autoFocus,
field,
value,
onChange,
}: FieldProps<typeof import('.').controller>) {
}: FieldProps<typeof controller>) {
const inputRef = useRef<HTMLInputElement | null>(null)

const errorMessage = createErrorMessage(value)
Expand All @@ -35,7 +36,6 @@ export function Field ({
// Generate a random input key when the value changes, to ensure the file input is unmounted and
// remounted (this is the only way to reset its value and ensure onChange will fire again if
// the user selects the same file again)
// eslint-disable-next-line react-hooks/exhaustive-deps
const inputKey = useMemo(() => Math.random(), [value])

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function isValidImageExtension (extension: string): extension is ImageExtension
return extensionsSet.has(extension)
}

export function image <ListTypeInfo extends BaseListTypeInfo>(config: ImageFieldConfig<ListTypeInfo>): FieldTypeFunc<ListTypeInfo> {
export function image <ListTypeInfo extends BaseListTypeInfo> (config: ImageFieldConfig<ListTypeInfo>): FieldTypeFunc<ListTypeInfo> {
return meta => {
const { fieldKey } = meta
const storage = meta.getStorage(config.storage)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/fields/types/image/views/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Button } from '@keystone-ui/button'
import { type FieldProps } from '../../../../types'
import { SUPPORTED_IMAGE_EXTENSIONS } from '../utils'
import { type ImageValue } from './index'
import { type controller } from '.'

function useObjectURL (fileData: File | undefined) {
let [objectURL, setObjectURL] = useState<string | undefined>(undefined)
Expand All @@ -29,7 +30,7 @@ export function Field ({
field,
value,
onChange,
}: FieldProps<typeof import('.').controller>) {
}: FieldProps<typeof controller>) {
const inputRef = useRef<HTMLInputElement | null>(null)

const errorMessage = createErrorMessage(value)
Expand All @@ -49,7 +50,6 @@ export function Field ({
// Generate a random input key when the value changes, to ensure the file input is unmounted and
// remounted (this is the only way to reset its value and ensure onChange will fire again if
// the user selects the same file again)
// eslint-disable-next-line react-hooks/exhaustive-deps
const inputKey = useMemo(() => Math.random(), [value])
const accept = useMemo(
() => SUPPORTED_IMAGE_EXTENSIONS.map(ext => [`.${ext}`, `image/${ext}`].join(', ')).join(', '),
Expand Down Expand Up @@ -104,7 +104,7 @@ function ImgView ({
errorMessage?: string
value: ImageValue
onChange?: (value: ImageValue) => void
field: ReturnType<typeof import('.').controller>
field: ReturnType<typeof controller>
inputRef: RefObject<HTMLInputElement>
}) {
const [imageDimensions, setImageDimensions] = useState({ width: 0, height: 0 })
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/integer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type IntegerFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
const MAX_INT = 2147483647
const MIN_INT = -2147483648

export function integer <ListTypeInfo extends BaseListTypeInfo>({
export function integer <ListTypeInfo extends BaseListTypeInfo> ({
isIndexed,
defaultValue: _defaultValue,
validation,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/multiselect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type MultiselectFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
const MAX_INT = 2147483647
const MIN_INT = -2147483648

export function multiselect <ListTypeInfo extends BaseListTypeInfo>(
export function multiselect <ListTypeInfo extends BaseListTypeInfo> (
config: MultiselectFieldConfig<ListTypeInfo>
): FieldTypeFunc<ListTypeInfo> {
const {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/password/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type PasswordFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
map?: string
extendPrismaSchema?: (field: string) => string
}
bcrypt?: Pick<typeof import('bcryptjs'), 'compare' | 'hash'>
bcrypt?: Pick<typeof bcryptjs, 'compare' | 'hash'>
}

const PasswordState = graphql.object<{ isSet: boolean }>()({
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fields/types/relationship/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type BaseListTypeInfo, type FieldTypeFunc, type CommonFieldConfig, fieldType } from '../../../types'
import { graphql } from '../../..'
import { getAdminMetaForRelationshipField } from '../../../lib/create-admin-meta'
import { type controller } from './views'

// This is the default display mode for Relationships
type SelectDisplayConfig = {
Expand Down Expand Up @@ -99,7 +100,7 @@ export const relationship =
...config,
__ksTelemetryFieldTypeName: '@keystone-6/relationship',
views: '@keystone-6/core/fields/types/relationship/views',
getAdminMeta: (): Parameters<typeof import('./views').controller>[0]['fieldMeta'] => {
getAdminMeta: (): Parameters<typeof controller>[0]['fieldMeta'] => {
const adminMetaRoot = getAdminMetaForRelationshipField()
const localListMeta = adminMetaRoot.listsByKey[listKey]
const foreignListMeta = adminMetaRoot.listsByKey[foreignListKey]
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fields/types/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { graphql } from '../../..'
import { assertReadIsNonNullAllowed, getResolvedIsNullable } from '../../non-null-graphql'
import { filters } from '../../filters'
import { type AdminSelectFieldMeta } from './views'

export type SelectFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
CommonFieldConfig<ListTypeInfo> &
Expand Down Expand Up @@ -72,7 +73,7 @@ export const select =
): CommonFieldConfig<ListTypeInfo> & {
__ksTelemetryFieldTypeName: string
views: string
getAdminMeta: () => import('./views').AdminSelectFieldMeta
getAdminMeta: () => AdminSelectFieldMeta
} => {
const values = new Set(options.map(x => x.value))
if (values.size !== options.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type TextFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
}
}

export function text <ListTypeInfo extends BaseListTypeInfo>(
export function text <ListTypeInfo extends BaseListTypeInfo> (
config: TextFieldConfig<ListTypeInfo> = {}
): FieldTypeFunc<ListTypeInfo> {
const {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fields/types/text/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
type FieldProps,
} from '../../../../types'
import { CellContainer, CellLink } from '../../../../admin-ui/components'
import { type TextFieldMeta } from '..'

export function Field ({
field,
Expand Down Expand Up @@ -140,7 +141,7 @@ export const CardValue: CardValueComponent = ({ item, field }) => {
)
}

type Config = FieldControllerConfig<import('..').TextFieldMeta>
type Config = FieldControllerConfig<TextFieldMeta>

type Validation = {
isRequired: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/fields/types/timestamp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type TimestampFieldConfig<ListTypeInfo extends BaseListTypeInfo> =
}
}

export function timestamp <ListTypeInfo extends BaseListTypeInfo>(
export function timestamp <ListTypeInfo extends BaseListTypeInfo> (
config: TimestampFieldConfig<ListTypeInfo> = {}
): FieldTypeFunc<ListTypeInfo> {
const {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/assets/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import fs from 'node:fs'
import path from 'node:path'
import { pipeline } from 'node:stream'

import { StorageConfig } from '../../types'
import { FileAdapter, ImageAdapter } from './types'
import { type StorageConfig } from '../../types'
import { type FileAdapter, type ImageAdapter } from './types'

export function localImageAssetsAPI (
storageConfig: StorageConfig & { kind: 'local' }
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/context/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function createContext ({
graphQLSchemaSudo: GraphQLSchema
prismaClient: unknown
prismaTypes: {
DbNull: unknown,
DbNull: unknown
JsonNull: unknown
}
}) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/core/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export async function createMany (
}

type UpdateInput = {
where: UniqueInputFilter,
where: UniqueInputFilter
data: Record<string, unknown>
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/core/queries/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { maybeCacheControlFromInfo } from '@apollo/cache-control-types'
import { GraphQLResolveInfo } from 'graphql'
import { type GraphQLResolveInfo } from 'graphql'
import {
type BaseItem,
type FindManyArgsValue,
Expand Down

0 comments on commit 623592b

Please sign in to comment.