Skip to content
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
3 changes: 3 additions & 0 deletions next/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ import antfu from '@antfu/eslint-config'

export default antfu({
ignores: ['test/v0-baseline-test-results.json'],
rules: {
curly: ['error', 'all'],
},
})
11 changes: 7 additions & 4 deletions next/src/custom/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion next/src/errors/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
12 changes: 8 additions & 4 deletions next/src/field/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion next/src/modify-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion next/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 10 additions & 5 deletions next/src/validation/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,40 @@ const formatValidationFunctions: Record<Format, (value: string) => 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()
})
},
[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
}
Expand Down
3 changes: 2 additions & 1 deletion next/test/custom/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down