Skip to content

Commit f62a218

Browse files
UzlopakEomm
andauthored
Use standard and @fastify/pre-commit (#190)
* use standard and snazzy for linting * lint files to standard * remove .prettierrc * remove jest config in package.json Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
1 parent 490c24d commit f62a218

28 files changed

+629
-658
lines changed

.prettierrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,34 @@
2626
"type": "git",
2727
"url": "https://github.com/fastify/fluent-json-schema.git"
2828
},
29-
"lint-staged": {
30-
"*.{json,md,js,ts,yml}": [
31-
"prettier --write",
32-
"git add"
33-
]
34-
},
3529
"scripts": {
30+
"lint": "standard | snazzy",
3631
"test": "npm run test:unit && npm run test:typescript",
3732
"test:unit": "jest --coverage",
3833
"test:watch": "jest src/*.test.js --verbose --watch",
3934
"test:typescript": "tsd",
40-
"prepare": "husky install",
41-
"format": "prettier --write ./src/**/*.js",
4235
"coverage": "jest src/**.test.js --coverage",
4336
"doc": "jsdoc2md ./src/*.js > docs/API.md"
4437
},
38+
"standard": {
39+
"env": [ "jest" ]
40+
},
4541
"devDependencies": {
42+
"@fastify/pre-commit": "^2.0.2",
4643
"ajv": "^8.0.0",
4744
"ajv-formats": "^2.1.1",
48-
"husky": "^8.0.1",
4945
"jest": "^29.0.1",
5046
"jsdoc-to-markdown": "^7.0.0",
51-
"lint-staged": "^13.0.0",
5247
"lodash.merge": "^4.6.2",
53-
"prettier": "^2.2.1",
48+
"snazzy": "^9.0.0",
49+
"standard": "^17.0.0",
5450
"tsd": "^0.24.1"
5551
},
5652
"dependencies": {
5753
"@fastify/deepmerge": "^1.1.0"
58-
}
54+
},
55+
"pre-commit": [
56+
"lint",
57+
"test"
58+
]
5959
}

src/ArraySchema.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const initialState = {
77
type: 'array',
88
definitions: [],
99
properties: [],
10-
required: [],
10+
required: []
1111
}
1212

1313
/**
@@ -23,7 +23,7 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
2323
options = {
2424
generateIds: false,
2525
factory: ArraySchema,
26-
...options,
26+
...options
2727
}
2828
return {
2929
...BaseSchema({ ...options, schema }),
@@ -46,8 +46,7 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
4646
Array.isArray(items) &&
4747
items.filter(v => isFluentSchema(v)).length > 0
4848
)
49-
)
50-
throw new FluentSchemaError("'items' must be a S or an array of S")
49+
) { throw new FluentSchemaError("'items' must be a S or an array of S") }
5150
if (Array.isArray(items)) {
5251
const values = items.map(v => {
5352
const { $schema, ...rest } = v.valueOf()
@@ -59,7 +58,7 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
5958
return setAttribute({ schema, ...options }, [
6059
'items',
6160
{ ...rest },
62-
'array',
61+
'array'
6362
])
6463
},
6564

@@ -72,22 +71,23 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
7271
*/
7372

7473
additionalItems: items => {
75-
if (typeof items !== 'boolean' && !isFluentSchema(items))
74+
if (typeof items !== 'boolean' && !isFluentSchema(items)) {
7675
throw new FluentSchemaError(
7776
"'additionalItems' must be a boolean or a S"
7877
)
78+
}
7979
if (items === false) {
8080
return setAttribute({ schema, ...options }, [
8181
'additionalItems',
8282
false,
83-
'array',
83+
'array'
8484
])
8585
}
8686
const { $schema, ...rest } = items.valueOf()
8787
return setAttribute({ schema, ...options }, [
8888
'additionalItems',
8989
{ ...rest },
90-
'array',
90+
'array'
9191
])
9292
},
9393

@@ -100,8 +100,7 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
100100
*/
101101

102102
contains: value => {
103-
if (!isFluentSchema(value))
104-
throw new FluentSchemaError("'contains' must be a S")
103+
if (!isFluentSchema(value)) { throw new FluentSchemaError("'contains' must be a S") }
105104
const {
106105
$schema,
107106
definitions,
@@ -112,7 +111,7 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
112111
return setAttribute({ schema, ...options }, [
113112
'contains',
114113
{ ...rest },
115-
'array',
114+
'array'
116115
])
117116
},
118117

@@ -127,12 +126,11 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
127126
*/
128127

129128
uniqueItems: boolean => {
130-
if (typeof boolean !== 'boolean')
131-
throw new FluentSchemaError("'uniqueItems' must be a boolean")
129+
if (typeof boolean !== 'boolean') { throw new FluentSchemaError("'uniqueItems' must be a boolean") }
132130
return setAttribute({ schema, ...options }, [
133131
'uniqueItems',
134132
boolean,
135-
'array',
133+
'array'
136134
])
137135
},
138136

@@ -146,8 +144,7 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
146144
*/
147145

148146
minItems: min => {
149-
if (!Number.isInteger(min))
150-
throw new FluentSchemaError("'minItems' must be a integer")
147+
if (!Number.isInteger(min)) { throw new FluentSchemaError("'minItems' must be a integer") }
151148
return setAttribute({ schema, ...options }, ['minItems', min, 'array'])
152149
},
153150

@@ -161,14 +158,13 @@ const ArraySchema = ({ schema = initialState, ...options } = {}) => {
161158
*/
162159

163160
maxItems: max => {
164-
if (!Number.isInteger(max))
165-
throw new FluentSchemaError("'maxItems' must be a integer")
161+
if (!Number.isInteger(max)) { throw new FluentSchemaError("'maxItems' must be a integer") }
166162
return setAttribute({ schema, ...options }, ['maxItems', max, 'array'])
167-
},
163+
}
168164
}
169165
}
170166

171167
module.exports = {
172168
ArraySchema,
173-
default: ArraySchema,
169+
default: ArraySchema
174170
}

src/ArraySchema.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ describe('ArraySchema', () => {
1313
describe('constructor', () => {
1414
it('without params', () => {
1515
expect(ArraySchema().valueOf()).toEqual({
16-
type: 'array',
16+
type: 'array'
1717
})
1818
})
1919

2020
it('from S', () => {
2121
expect(S.array().valueOf()).toEqual({
2222
$schema: 'http://json-schema.org/draft-07/schema#',
23-
type: 'array',
23+
type: 'array'
2424
})
2525
})
2626
})
@@ -34,7 +34,7 @@ describe('ArraySchema', () => {
3434
.valueOf()
3535
).toEqual({
3636
type: 'array',
37-
items: { type: 'number' },
37+
items: { type: 'number' }
3838
})
3939
})
4040
it('valid array', () => {
@@ -44,7 +44,7 @@ describe('ArraySchema', () => {
4444
.valueOf()
4545
).toEqual({
4646
type: 'array',
47-
items: [{ type: 'number' }, { type: 'string' }],
47+
items: [{ type: 'number' }, { type: 'string' }]
4848
})
4949
})
5050
it('invalid', () => {
@@ -64,7 +64,7 @@ describe('ArraySchema', () => {
6464
).toEqual({
6565
type: 'array',
6666
items: [{ type: 'number' }, { type: 'string' }],
67-
additionalItems: { type: 'string' },
67+
additionalItems: { type: 'string' }
6868
})
6969
})
7070
it('false', () => {
@@ -76,7 +76,7 @@ describe('ArraySchema', () => {
7676
).toEqual({
7777
type: 'array',
7878
items: [{ type: 'number' }, { type: 'string' }],
79-
additionalItems: false,
79+
additionalItems: false
8080
})
8181
})
8282
it('invalid', () => {
@@ -94,7 +94,7 @@ describe('ArraySchema', () => {
9494
.valueOf()
9595
).toEqual({
9696
type: 'array',
97-
contains: { type: 'string' },
97+
contains: { type: 'string' }
9898
})
9999
})
100100
it('invalid', () => {
@@ -114,7 +114,7 @@ describe('ArraySchema', () => {
114114
.valueOf()
115115
).toEqual({
116116
type: 'array',
117-
uniqueItems: true,
117+
uniqueItems: true
118118
})
119119
})
120120
it('invalid', () => {
@@ -136,7 +136,7 @@ describe('ArraySchema', () => {
136136
.valueOf()
137137
).toEqual({
138138
type: 'array',
139-
minItems: 3,
139+
minItems: 3
140140
})
141141
})
142142
it('invalid', () => {
@@ -156,7 +156,7 @@ describe('ArraySchema', () => {
156156
.valueOf()
157157
).toEqual({
158158
type: 'array',
159-
maxItems: 5,
159+
maxItems: 5
160160
})
161161
})
162162
it('invalid', () => {
@@ -176,7 +176,7 @@ describe('ArraySchema', () => {
176176

177177
expect(schema).toEqual({
178178
type: 'array',
179-
customKeyword: true,
179+
customKeyword: true
180180
})
181181
})
182182
})

0 commit comments

Comments
 (0)