Skip to content

Commit ef32445

Browse files
chore: adjust eslint rules for if statements and fix new errors
1 parent 3432b75 commit ef32445

File tree

8 files changed

+35
-17
lines changed

8 files changed

+35
-17
lines changed

next/eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ import antfu from '@antfu/eslint-config'
22

33
export default antfu({
44
ignores: ['test/v0-baseline-test-results.json'],
5+
rules: {
6+
curly: ['error', 'all'],
7+
},
58
})

next/src/custom/order.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ function sort(fields: Field[], order: string[]): Field[] {
1515

1616
// The else actually only happens when both are Infinity,
1717
// i.e., not specified in the order array
18-
if (indexA !== indexB)
18+
if (indexA !== indexB) {
1919
return indexA - indexB
20+
}
2021

2122
// If not specified, maintain original relative order
2223
return fields.indexOf(a) - fields.indexOf(b)
@@ -33,11 +34,13 @@ export function setCustomOrder(schema: JsfSchema, fields: Field[]): Field[] {
3334
// but it's only because our typing is likely not right.
3435
// See internal discussion:
3536
// - https://remote-com.slack.com/archives/C02HTN0LY02/p1738745237733389?thread_ts=1738741631.346809&cid=C02HTN0LY02
36-
if (typeof schema === 'boolean')
37-
throw new Error('Schema must be an object')
37+
if (typeof schema === 'boolean') {
38+
throw new TypeError('Schema must be an object')
39+
}
3840

39-
if (schema['x-jsf-order'] !== undefined)
41+
if (schema['x-jsf-order'] !== undefined) {
4042
return sort(fields, schema['x-jsf-order'])
43+
}
4144

4245
return fields
4346
}

next/src/errors/messages.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ function getTypeErrorMessage(schemaType: JsfSchemaType | JsfSchemaType[] | undef
124124
if (Array.isArray(schemaType)) {
125125
// Map 'integer' to 'number' in error messages
126126
const formattedTypes = schemaType.map((type) => {
127-
if (type === 'integer')
127+
if (type === 'integer') {
128128
return 'number'
129+
}
129130
return type
130131
})
131132

next/src/field/schema.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ function getInputTypeFromSchema(type: JsfSchemaType, schema: NonBooleanJsfSchema
7171
switch (type) {
7272
case 'string': {
7373
const { oneOf, format } = schema
74-
if (format === 'email')
74+
if (format === 'email') {
7575
return 'email'
76-
if (format === 'date')
76+
}
77+
if (format === 'date') {
7778
return 'date'
78-
if (format === 'data-url')
79+
}
80+
if (format === 'data-url') {
7981
return 'file'
80-
if (oneOf)
82+
}
83+
if (oneOf) {
8184
return 'radio'
85+
}
8286
return 'text'
8387
}
8488
case 'number':

next/src/modify-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ function findMissingFields(conditional: JsfSchema | undefined, { fields, path }:
396396
missingFields[fieldName] = { path }
397397
}
398398

399-
// TODO support nested fields (eg if properties.adddress.properties.door_number)
399+
// TODO support nested fields (eg if properties.address.properties.door_number)
400400
})
401401

402402
return missingFields

next/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ export function getField(fields: Field[], name: string, ...subNames: string[]) {
4646

4747
// Helper function to convert KB to MB
4848
export function convertKBToMB(kb: number): number {
49-
if (kb === 0)
49+
if (kb === 0) {
5050
return 0
51+
}
5152
const mb = kb / 1024 // KB to MB
5253
return Number.parseFloat(mb.toFixed(2)) // Keep 2 decimal places
5354
}

next/src/validation/format.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,40 @@ const formatValidationFunctions: Record<Format, (value: string) => boolean> = {
7373
return value.length <= 254 && PATTERNS.IDN_EMAIL.test(value)
7474
},
7575
[Format.Hostname]: (value) => {
76-
if (value.length > 255)
76+
if (value.length > 255) {
7777
return false
78+
}
7879
const labels = value.split('.')
7980
return labels.every(label => PATTERNS.HOSTNAME.test(label))
8081
},
8182
[Format.IDNHostname]: (value) => {
82-
if (value.length > 255)
83+
if (value.length > 255) {
8384
return false
85+
}
8486
const labels = value.split('.')
8587
return labels.every(label => label.length <= 63 && PATTERNS.IDN_HOSTNAME.test(label))
8688
},
8789
[Format.IPv4]: (value) => {
8890
const parts = value.split('.')
89-
if (parts.length !== 4)
91+
if (parts.length !== 4) {
9092
return false
93+
}
9194
return parts.every((part) => {
9295
const num = Number.parseInt(part, 10)
9396
return num >= 0 && num <= 255 && part === num.toString()
9497
})
9598
},
9699
[Format.IPv6]: (value) => {
97100
const parts = value.split(':')
98-
if (parts.length > 8)
101+
if (parts.length > 8) {
99102
return false
103+
}
100104
let hasDoubleColon = false
101105
return parts.every((part) => {
102106
if (part === '') {
103-
if (hasDoubleColon)
107+
if (hasDoubleColon) {
104108
return false
109+
}
105110
hasDoubleColon = true
106111
return true
107112
}

next/test/custom/order.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ describe('custom order', () => {
4444
expect(mainKeys).toEqual(['name', 'address'])
4545

4646
const addressField = form.fields.find(field => field.name === 'address')
47-
if (addressField === undefined)
47+
if (addressField === undefined) {
4848
throw new Error('Address field not found')
49+
}
4950

5051
// This already throws if "fields" is undefined
5152
const addressKeys = addressField.fields?.map(field => field.name)

0 commit comments

Comments
 (0)