Skip to content

Commit 55e5be7

Browse files
committed
perf: 🍻 make prettier printwidth to 120
1 parent 84baf63 commit 55e5be7

File tree

9 files changed

+23
-91
lines changed

9 files changed

+23
-91
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"trailingComma": "all",
44
"semi": false,
55
"endOfLine": "auto",
6-
"singleQuote": true
6+
"singleQuote": true,
7+
"printWidth": 120
78
}

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,7 @@ It can be called by `this.$errors.**`
430430

431431
```vue
432432
<template>
433-
<v-form
434-
v-model="valid"
435-
lazy-validation
436-
@keydown.native="$errors.onKeydown"
437-
@submit.prevent="submit"
438-
>
433+
<v-form v-model="valid" lazy-validation @keydown.native="$errors.onKeydown" @submit.prevent="submit">
439434
<v-container>
440435
<v-row>
441436
<v-col cols="12" md="4">
@@ -458,13 +453,7 @@ It can be called by `this.$errors.**`
458453
/>
459454
</v-col>
460455
<v-col cols="12" md="4">
461-
<v-text-field
462-
v-model="email"
463-
:counter="10"
464-
label="Email"
465-
required
466-
:error-messages="$errors.first('email')"
467-
/>
456+
<v-text-field v-model="email" :counter="10" label="Email" required :error-messages="$errors.first('email')" />
468457
</v-col>
469458
<v-col cols="12" md="4">
470459
<v-text-field v-model="email" label="E-mail" required />

src/__tests__/base-service.test.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ describe('BaseService', () => {
8989
{ first_name: 'Chantouch', last_name: 'Sek', id: 2 },
9090
]
9191
mockAdapter.onGet('/posts?id=1&first_name=Dara').reply(200, { data: items })
92-
const { data } = await service
93-
.setParameter('id', 1)
94-
.setParameters({ first_name: 'Dara' })
95-
.all()
92+
const { data } = await service.setParameter('id', 1).setParameters({ first_name: 'Dara' }).all()
9693
expect(data).toEqual(items)
9794
})
9895

@@ -110,9 +107,7 @@ describe('BaseService', () => {
110107
pc: null,
111108
})
112109
const items = [user2, { first_name: 'Chantouch', last_name: 'Sek', id: 2 }]
113-
mockAdapter
114-
.onGet('/posts?id=1&last_name=Hok&search[name]=hello&first_name=Dara')
115-
.reply(200, { data: items })
110+
mockAdapter.onGet('/posts?id=1&last_name=Hok&search[name]=hello&first_name=Dara').reply(200, { data: items })
116111
const { data } = await service
117112
.setParameter('id=1&last_name=Hok&search[name]=hello')
118113
.setParameters({ first_name: 'Dara' })
@@ -148,18 +143,13 @@ describe('BaseService', () => {
148143
{ first_name: 'Dara', last_name: 'Hok', id: 1 },
149144
{ first_name: 'Chantouch', last_name: 'Sek', id: 2 },
150145
]
151-
mockAdapter
152-
.onGet('/posts?search[id]=1&first_name=Dara')
153-
.reply(200, { data: items })
146+
mockAdapter.onGet('/posts?search[id]=1&first_name=Dara').reply(200, { data: items })
154147
const params = {
155148
search: { id: 1 },
156149
first_name: 'Dara',
157150
last_name: 'Hok',
158151
}
159-
const { data } = await service
160-
.setParameters(params)
161-
.removeParameters(['last_name'])
162-
.all()
152+
const { data } = await service.setParameters(params).removeParameters(['last_name']).all()
163153
expect(data).toEqual(items)
164154
expect(service.parameters).toEqual({
165155
search: { id: 1 },
@@ -266,12 +256,7 @@ describe('BaseService', () => {
266256
expect(request.data.get('files[0]')).toEqual(file)
267257
expect(request.data.get('__proto__')).toEqual(null)
268258

269-
expect(getFormDataKeys(request.data)).toEqual([
270-
'field1[foo]',
271-
'field1[bar]',
272-
'field2',
273-
'files[0]',
274-
])
259+
expect(getFormDataKeys(request.data)).toEqual(['field1[foo]', 'field1[bar]', 'field2', 'files[0]'])
275260
return [200, {}]
276261
})
277262

@@ -359,7 +344,5 @@ describe('BaseService', () => {
359344

360345
function getFormDataKeys(formData: any) {
361346
// This is because the FormData.keys() is missing from the jsdom implementations.
362-
return formData[Object.getOwnPropertySymbols(formData)[0]]._entries.map(
363-
(e: any) => e.name,
364-
)
347+
return formData[Object.getOwnPropertySymbols(formData)[0]]._entries.map((e: any) => e.name)
365348
}

src/__tests__/validator.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ describe('Validator', () => {
3333
test('Check if error has "name" key.', () => {
3434
validator.add('name', 'The name field is required.')
3535
expect(validator.has('name')).toBeTruthy()
36-
expect(validator.first(['name', 'form.name'])).toBe(
37-
'The name field is required.',
38-
)
36+
expect(validator.first(['name', 'form.name'])).toBe('The name field is required.')
3937
})
4038
test('Check if has error by multi key', () => {
4139
validator.add('name', 'The name field is required.')
@@ -202,9 +200,7 @@ describe('Validator', () => {
202200
age: ['This age field is required'],
203201
}
204202

205-
expect(validator.firstBy(errors, 'age')).toEqual(
206-
'This age field is required',
207-
)
203+
expect(validator.firstBy(errors, 'age')).toEqual('This age field is required')
208204
})
209205

210206
it('get first by without any field', () => {
@@ -214,9 +210,7 @@ describe('Validator', () => {
214210
age: ['This age field is required'],
215211
}
216212

217-
expect(validator.firstBy(errors)).toEqual(
218-
'This fist name field is required',
219-
)
213+
expect(validator.firstBy(errors)).toEqual('This fist name field is required')
220214
})
221215

222216
it('get first array by nested array', () => {
@@ -230,8 +224,6 @@ describe('Validator', () => {
230224
const errors = { name: [{ kh: ['This fist name field is required'] }] }
231225
validator.fill(errors)
232226

233-
expect(validator.first(['name[0].kh'])).toEqual(
234-
'This fist name field is required',
235-
)
227+
expect(validator.first(['name[0].kh'])).toEqual('This fist name field is required')
236228
})
237229
})

src/core/BaseService.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import type {
2-
AxiosError,
3-
AxiosInstance,
4-
AxiosResponse,
5-
Method,
6-
AxiosRequestConfig,
7-
} from 'axios'
1+
import type { AxiosError, AxiosInstance, AxiosResponse, Method, AxiosRequestConfig } from 'axios'
82
import type { Errors } from '..'
93
import Validator from './Validator'
104
import { hasFiles, objectToFormData, removeDoubleSlash } from '../util'
@@ -92,19 +86,12 @@ class BaseService {
9286
return this.delete<T>(id)
9387
}
9488

95-
submit<T = any>(
96-
method: Method,
97-
parameter?: string | number,
98-
form?: T,
99-
config?: AxiosRequestConfig,
100-
): Promise<T> {
89+
submit<T = any>(method: Method, parameter?: string | number, form?: T, config?: AxiosRequestConfig): Promise<T> {
10190
BaseService.__validateRequestType(method)
10291
this.beforeSubmit()
10392
return new Promise((resolve, reject) => {
10493
const data = hasFiles(form) ? objectToFormData(form) : form
105-
const endpoint = parameter
106-
? `/${this.endpoint}/${parameter}`
107-
: `/${this.endpoint}`
94+
const endpoint = parameter ? `/${this.endpoint}/${parameter}` : `/${this.endpoint}`
10895
const url = this.__getParameterString(removeDoubleSlash(endpoint))
10996
config = Object.assign({}, config, { url, data, method })
11097
this.$http(config)
@@ -155,8 +142,7 @@ class BaseService {
155142
]
156143
if (!requestTypes.includes(requestType)) {
157144
throw new Error(
158-
`\`${requestType}\` is not a valid request type, ` +
159-
`must be one of: \`${requestTypes.join('`, `')}\`.`,
145+
`\`${requestType}\` is not a valid request type, ` + `must be one of: \`${requestTypes.join('`, `')}\`.`,
160146
)
161147
}
162148
return requestType

src/core/Validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloneDeep, get, has, isArray, omit } from 'lodash'
1+
import { cloneDeep, get, has, omit } from 'lodash'
22
import { is, toCamelCase, toSnakeCase } from '../util'
33

44
class Validator {

src/util/formData.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { hasOwnProperty, isArray, isFile } from './objects'
22

3-
export function objectToFormData(
4-
object: any,
5-
formData = new FormData(),
6-
parent = '',
7-
): FormData {
3+
export function objectToFormData(object: any, formData = new FormData(), parent = ''): FormData {
84
if (object === null || object === 'undefined' || object.length === 0) {
95
formData.append(parent, object)
106
} else {

src/util/objects.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@ export function hasOwnProperty(obj: any, key: any) {
88
}
99

1010
export function isFile(object: any): boolean {
11-
if (
12-
typeof window === 'undefined' ||
13-
typeof File !== 'function' ||
14-
typeof FileList !== 'function'
15-
) {
11+
if (typeof window === 'undefined' || typeof File !== 'function' || typeof FileList !== 'function') {
1612
return false
1713
}
1814
return object instanceof File || object instanceof FileList
1915
}
2016

2117
export function is(errors: any, error: any): boolean {
22-
return isArray(error)
23-
? error.some((w: string) => is(errors, w))
24-
: errors.includes(error)
18+
return isArray(error) ? error.some((w: string) => is(errors, w)) : errors.includes(error)
2519
}

tsconfig.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2021",
44
"module": "CommonJS",
5-
"lib": [
6-
"ES5",
7-
"ES6",
8-
"ES2015",
9-
"ES2016",
10-
"ES2017",
11-
"ES2018",
12-
"ESNext",
13-
"DOM"
14-
],
5+
"lib": ["ES5", "ES6", "ES2015", "ES2016", "ES2017", "ES2018", "ESNext", "DOM"],
156
"moduleResolution": "Node",
167
"esModuleInterop": true,
178
"strict": true,

0 commit comments

Comments
 (0)