From ef32445ac406fa175a7bf77e3ff8bea628f879e0 Mon Sep 17 00:00:00 2001 From: Capelo Date: Tue, 8 Jul 2025 15:26:24 +0100 Subject: [PATCH] chore: adjust eslint rules for if statements and fix new errors --- next/eslint.config.mjs | 3 +++ next/src/custom/order.ts | 11 +++++++---- next/src/errors/messages.ts | 3 ++- next/src/field/schema.ts | 12 ++++++++---- next/src/modify-schema.ts | 2 +- next/src/utils.ts | 3 ++- next/src/validation/format.ts | 15 ++++++++++----- next/test/custom/order.test.ts | 3 ++- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/next/eslint.config.mjs b/next/eslint.config.mjs index db282a1a3..d3fe8ed8d 100644 --- a/next/eslint.config.mjs +++ b/next/eslint.config.mjs @@ -2,4 +2,7 @@ import antfu from '@antfu/eslint-config' export default antfu({ ignores: ['test/v0-baseline-test-results.json'], + rules: { + curly: ['error', 'all'], + }, }) diff --git a/next/src/custom/order.ts b/next/src/custom/order.ts index 5e50aa83b..ff13a6891 100644 --- a/next/src/custom/order.ts +++ b/next/src/custom/order.ts @@ -15,8 +15,9 @@ function sort(fields: Field[], order: string[]): Field[] { // The else actually only happens when both are Infinity, // i.e., not specified in the order array - if (indexA !== indexB) + if (indexA !== indexB) { return indexA - indexB + } // If not specified, maintain original relative order return fields.indexOf(a) - fields.indexOf(b) @@ -33,11 +34,13 @@ export function setCustomOrder(schema: JsfSchema, fields: Field[]): Field[] { // but it's only because our typing is likely not right. // See internal discussion: // - https://remote-com.slack.com/archives/C02HTN0LY02/p1738745237733389?thread_ts=1738741631.346809&cid=C02HTN0LY02 - if (typeof schema === 'boolean') - throw new Error('Schema must be an object') + if (typeof schema === 'boolean') { + throw new TypeError('Schema must be an object') + } - if (schema['x-jsf-order'] !== undefined) + if (schema['x-jsf-order'] !== undefined) { return sort(fields, schema['x-jsf-order']) + } return fields } diff --git a/next/src/errors/messages.ts b/next/src/errors/messages.ts index 588f85698..8e18167a5 100644 --- a/next/src/errors/messages.ts +++ b/next/src/errors/messages.ts @@ -124,8 +124,9 @@ function getTypeErrorMessage(schemaType: JsfSchemaType | JsfSchemaType[] | undef if (Array.isArray(schemaType)) { // Map 'integer' to 'number' in error messages const formattedTypes = schemaType.map((type) => { - if (type === 'integer') + if (type === 'integer') { return 'number' + } return type }) diff --git a/next/src/field/schema.ts b/next/src/field/schema.ts index 0000902db..a46c5070e 100644 --- a/next/src/field/schema.ts +++ b/next/src/field/schema.ts @@ -71,14 +71,18 @@ function getInputTypeFromSchema(type: JsfSchemaType, schema: NonBooleanJsfSchema switch (type) { case 'string': { const { oneOf, format } = schema - if (format === 'email') + if (format === 'email') { return 'email' - if (format === 'date') + } + if (format === 'date') { return 'date' - if (format === 'data-url') + } + if (format === 'data-url') { return 'file' - if (oneOf) + } + if (oneOf) { return 'radio' + } return 'text' } case 'number': diff --git a/next/src/modify-schema.ts b/next/src/modify-schema.ts index bd6b015c1..abfd6f940 100644 --- a/next/src/modify-schema.ts +++ b/next/src/modify-schema.ts @@ -396,7 +396,7 @@ function findMissingFields(conditional: JsfSchema | undefined, { fields, path }: missingFields[fieldName] = { path } } - // TODO support nested fields (eg if properties.adddress.properties.door_number) + // TODO support nested fields (eg if properties.address.properties.door_number) }) return missingFields diff --git a/next/src/utils.ts b/next/src/utils.ts index 5d99bd0a1..4e971bced 100644 --- a/next/src/utils.ts +++ b/next/src/utils.ts @@ -46,8 +46,9 @@ export function getField(fields: Field[], name: string, ...subNames: string[]) { // Helper function to convert KB to MB export function convertKBToMB(kb: number): number { - if (kb === 0) + if (kb === 0) { return 0 + } const mb = kb / 1024 // KB to MB return Number.parseFloat(mb.toFixed(2)) // Keep 2 decimal places } diff --git a/next/src/validation/format.ts b/next/src/validation/format.ts index 65b9c282e..8ac1d1497 100644 --- a/next/src/validation/format.ts +++ b/next/src/validation/format.ts @@ -73,21 +73,24 @@ const formatValidationFunctions: Record boolean> = { return value.length <= 254 && PATTERNS.IDN_EMAIL.test(value) }, [Format.Hostname]: (value) => { - if (value.length > 255) + if (value.length > 255) { return false + } const labels = value.split('.') return labels.every(label => PATTERNS.HOSTNAME.test(label)) }, [Format.IDNHostname]: (value) => { - if (value.length > 255) + if (value.length > 255) { return false + } const labels = value.split('.') return labels.every(label => label.length <= 63 && PATTERNS.IDN_HOSTNAME.test(label)) }, [Format.IPv4]: (value) => { const parts = value.split('.') - if (parts.length !== 4) + if (parts.length !== 4) { return false + } return parts.every((part) => { const num = Number.parseInt(part, 10) return num >= 0 && num <= 255 && part === num.toString() @@ -95,13 +98,15 @@ const formatValidationFunctions: Record boolean> = { }, [Format.IPv6]: (value) => { const parts = value.split(':') - if (parts.length > 8) + if (parts.length > 8) { return false + } let hasDoubleColon = false return parts.every((part) => { if (part === '') { - if (hasDoubleColon) + if (hasDoubleColon) { return false + } hasDoubleColon = true return true } diff --git a/next/test/custom/order.test.ts b/next/test/custom/order.test.ts index 82ac78fc0..ae0e0e509 100644 --- a/next/test/custom/order.test.ts +++ b/next/test/custom/order.test.ts @@ -44,8 +44,9 @@ describe('custom order', () => { expect(mainKeys).toEqual(['name', 'address']) const addressField = form.fields.find(field => field.name === 'address') - if (addressField === undefined) + if (addressField === undefined) { throw new Error('Address field not found') + } // This already throws if "fields" is undefined const addressKeys = addressField.fields?.map(field => field.name)