Skip to content

Commit b0e8917

Browse files
authored
chore(config-validator): update ajv to v8 (#3242)
ajv introduced some breaking changes from v6 to v7, and from v7 to v8. Most can be found in [their migration guide](https://ajv.js.org/v6-to-v8-migration.html). This commit addresses the following: - `ErrorObject.dataPath` was renamed to `ErrorObject.instacePath` - Wordings of some errors changed (e.g. "should" -> "must") - Strict mode does not allow a top-level `default` value - Disable [strict mode](https://ajv.js.org/strict-mode.html) - The `plugins` schema included an invalid object definition for `rules` - `schemaId` is no longer an ajv option - `missingRefs` no longer seems to affect the usage of ajv in the project - `addKeyword` has its signature changed The tests pass and everyone's seemingly happy; do say if anything's still scary-looking. Obsoletes #2888.
1 parent dfe69b0 commit b0e8917

File tree

6 files changed

+72
-53
lines changed

6 files changed

+72
-53
lines changed

Diff for: @commitlint/config-validator/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"dependencies": {
4141
"@commitlint/types": "^17.0.0",
42-
"ajv": "^6.12.6"
42+
"ajv": "^8.11.0"
4343
},
4444
"gitHead": "d829bf6260304ca8d6811f329fcdd1b6c50e9749"
4545
}

Diff for: @commitlint/config-validator/src/__snapshots__/validate.test.ts.snap

+39-39
Original file line numberDiff line numberDiff line change
@@ -2,134 +2,134 @@
22

33
exports[`validation should fail for defaultIgnoresNotBoolean 1`] = `
44
"Commitlint configuration in defaultIgnoresNotBoolean.js is invalid:
5-
- Property \\"defaultIgnores\\" has the wrong type - should be boolean.
5+
- Property \\"defaultIgnores\\" has the wrong type - must be boolean.
66
"
77
`;
88

99
exports[`validation should fail for extendsAsObject 1`] = `
1010
"Commitlint configuration in extendsAsObject.js is invalid:
11-
- Property \\"extends\\" has the wrong type - should be array.
12-
- Property \\"extends\\" has the wrong type - should be string.
13-
- \\"extends\\" should match exactly one schema in oneOf. Value: {\\"test\\":1}.
11+
- Property \\"extends\\" has the wrong type - must be array.
12+
- Property \\"extends\\" has the wrong type - must be string.
13+
- \\"/extends\\" must match exactly one schema in oneOf. Value: {\\"test\\":1}.
1414
"
1515
`;
1616

1717
exports[`validation should fail for extendsWithFunction 1`] = `
1818
"Commitlint configuration in extendsWithFunction.js is invalid:
19-
- Property \\"extends[0]\\" has the wrong type - should be string.
20-
- Property \\"extends\\" has the wrong type - should be string.
21-
- \\"extends\\" should match exactly one schema in oneOf. Value: [null].
19+
- Property \\"extends/0\\" has the wrong type - must be string.
20+
- Property \\"extends\\" has the wrong type - must be string.
21+
- \\"/extends\\" must match exactly one schema in oneOf. Value: [null].
2222
"
2323
`;
2424

2525
exports[`validation should fail for formatterAsObject 1`] = `
2626
"Commitlint configuration in formatterAsObject.js is invalid:
27-
- Property \\"formatter\\" has the wrong type - should be string.
27+
- Property \\"formatter\\" has the wrong type - must be string.
2828
"
2929
`;
3030

3131
exports[`validation should fail for helpUrlAsArray 1`] = `
3232
"Commitlint configuration in helpUrlAsArray.js is invalid:
33-
- Property \\"helpUrl\\" has the wrong type - should be string.
33+
- Property \\"helpUrl\\" has the wrong type - must be string.
3434
"
3535
`;
3636

3737
exports[`validation should fail for helpUrlNotString 1`] = `
3838
"Commitlint configuration in helpUrlNotString.js is invalid:
39-
- Property \\"helpUrl\\" has the wrong type - should be string.
39+
- Property \\"helpUrl\\" has the wrong type - must be string.
4040
"
4141
`;
4242

4343
exports[`validation should fail for ignoresFunction 1`] = `
4444
"Commitlint configuration in ignoresFunction.js is invalid:
45-
- Property \\"ignores\\" has the wrong type - should be array.
45+
- Property \\"ignores\\" has the wrong type - must be array.
4646
"
4747
`;
4848

4949
exports[`validation should fail for ignoresNotFunction 1`] = `
5050
"Commitlint configuration in ignoresNotFunction.js is invalid:
51-
- \\"ignores[0]\\" should be a function. Value: 1.
51+
- \\"/ignores/0\\" should be a function. Value: 1.
5252
"
5353
`;
5454

5555
exports[`validation should fail for parserPreset 1`] = `
5656
"Commitlint configuration in parserPreset.js is invalid:
57-
- Property \\"parserPreset\\" has the wrong type - should be string.
58-
- Property \\"parserPreset\\" has the wrong type - should be object.
59-
- \\"parserPreset\\" should be a function. Value: [].
60-
- \\"parserPreset\\" should match exactly one schema in oneOf. Value: [].
57+
- Property \\"parserPreset\\" has the wrong type - must be string.
58+
- Property \\"parserPreset\\" has the wrong type - must be object.
59+
- \\"/parserPreset\\" should be a function. Value: [].
60+
- \\"/parserPreset\\" must match exactly one schema in oneOf. Value: [].
6161
"
6262
`;
6363

6464
exports[`validation should fail for pluginsNotArray 1`] = `
6565
"Commitlint configuration in pluginsNotArray.js is invalid:
66-
- Property \\"plugins\\" has the wrong type - should be array.
66+
- Property \\"plugins\\" has the wrong type - must be array.
6767
"
6868
`;
6969

7070
exports[`validation should fail for rules1 1`] = `
7171
"Commitlint configuration in rules1.js is invalid:
72-
- \\"rules['a'][0]\\" should be equal to one of the allowed values. Value: 3.
73-
- \\"rules['a']\\" should be a function. Value: [3].
74-
- \\"rules['a']\\" should match exactly one schema in oneOf. Value: [3].
72+
- \\"/rules/a/0\\" must be equal to one of the allowed values. Value: 3.
73+
- \\"/rules/a\\" should be a function. Value: [3].
74+
- \\"/rules/a\\" must match exactly one schema in oneOf. Value: [3].
7575
"
7676
`;
7777

7878
exports[`validation should fail for rules2 1`] = `
7979
"Commitlint configuration in rules2.js is invalid:
80-
- \\"rules['b']\\" should NOT have more than 3 items. Value: [1,\\"test\\",2,2].
81-
- \\"rules['b']\\" should be a function. Value: [1,\\"test\\",2,2].
82-
- \\"rules['b']\\" should match exactly one schema in oneOf. Value: [1,\\"test\\",2,2].
80+
- \\"/rules/b\\" must NOT have more than 3 items. Value: [1,\\"test\\",2,2].
81+
- \\"/rules/b\\" should be a function. Value: [1,\\"test\\",2,2].
82+
- \\"/rules/b\\" must match exactly one schema in oneOf. Value: [1,\\"test\\",2,2].
8383
"
8484
`;
8585

8686
exports[`validation should fail for rules3 1`] = `
8787
"Commitlint configuration in rules3.js is invalid:
88-
- \\"rules['c']\\" should NOT have fewer than 1 items. Value: [].
89-
- \\"rules['c']\\" should be a function. Value: [].
90-
- \\"rules['c']\\" should match exactly one schema in oneOf. Value: [].
88+
- \\"/rules/c\\" must NOT have fewer than 1 items. Value: [].
89+
- \\"/rules/c\\" should be a function. Value: [].
90+
- \\"/rules/c\\" must match exactly one schema in oneOf. Value: [].
9191
"
9292
`;
9393

9494
exports[`validation should fail for rules4 1`] = `
9595
"Commitlint configuration in rules4.js is invalid:
96-
- Property \\"rules['d'][0]\\" has the wrong type - should be number.
97-
- \\"rules['d'][0]\\" should be equal to one of the allowed values. Value: [].
98-
- \\"rules['d']\\" should be a function. Value: [[],[],[]].
99-
- \\"rules['d']\\" should match exactly one schema in oneOf. Value: [[],[],[]].
96+
- Property \\"rules/d/0\\" has the wrong type - must be number.
97+
- \\"/rules/d/0\\" must be equal to one of the allowed values. Value: [].
98+
- \\"/rules/d\\" should be a function. Value: [[],[],[]].
99+
- \\"/rules/d\\" must match exactly one schema in oneOf. Value: [[],[],[]].
100100
"
101101
`;
102102

103103
exports[`validation should fail for rules5 1`] = `
104104
"Commitlint configuration in rules5.js is invalid:
105-
- Property \\"rules['e']\\" has the wrong type - should be array.
106-
- \\"rules['e']\\" should be a function. Value: {}.
107-
- \\"rules['e']\\" should match exactly one schema in oneOf. Value: {}.
105+
- Property \\"rules/e\\" has the wrong type - must be array.
106+
- \\"/rules/e\\" should be a function. Value: {}.
107+
- \\"/rules/e\\" must match exactly one schema in oneOf. Value: {}.
108108
"
109109
`;
110110

111111
exports[`validation should fail for rulesAsArray 1`] = `
112112
"Commitlint configuration in rulesAsArray.js is invalid:
113-
- Property \\"rules\\" has the wrong type - should be object.
113+
- Property \\"rules\\" has the wrong type - must be object.
114114
"
115115
`;
116116

117117
exports[`validation should fail for whenConfigIsNotObject 1`] = `
118118
"Commitlint configuration in whenConfigIsNotObject.js is invalid:
119-
- Config has the wrong type - should be object.
119+
- Config has the wrong type - must be object.
120120
"
121121
`;
122122

123123
exports[`validation should fail for whenConfigIsNotObject2 1`] = `
124124
"Commitlint configuration in whenConfigIsNotObject2.js is invalid:
125-
- Config has the wrong type - should be object.
125+
- Config has the wrong type - must be object.
126126
"
127127
`;
128128

129129
exports[`validation should fail for withPluginsAsObject 1`] = `
130130
"Commitlint configuration in withPluginsAsObject.js is invalid:
131-
- Property \\"plugins[0]\\" has the wrong type - should be string.
132-
- \\"plugins[0]\\" should have required property '.rules'. Value: {}.
133-
- \\"plugins[0]\\" should match some schema in anyOf. Value: {}.
131+
- Property \\"plugins/0\\" has the wrong type - must be string.
132+
- \\"/plugins/0\\" must have required property 'rules'. Value: {}.
133+
- \\"/plugins/0\\" must match a schema in anyOf. Value: {}.
134134
"
135135
`;

Diff for: @commitlint/config-validator/src/commitlint.schema.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
3-
"default": {},
43
"type": "object",
54
"definitions": {
65
"rule": {
@@ -82,8 +81,13 @@
8281
"anyOf": [
8382
{"type": "string"},
8483
{
84+
"type": "object",
8585
"required": ["rules"],
86-
"rules": {}
86+
"properties": {
87+
"rules": {
88+
"type": "object"
89+
}
90+
}
8791
}
8892
]
8993
}

Diff for: @commitlint/config-validator/src/formatErrors.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ export function formatErrors(errors: ErrorObject[]): string {
1313
error.keyword === 'additionalProperties' &&
1414
'additionalProperty' in error.params
1515
) {
16-
const formattedPropertyPath = error.dataPath.length
17-
? `${error.dataPath.slice(1)}.${error.params.additionalProperty}`
16+
const formattedPropertyPath = error.instancePath.length
17+
? `${error.instancePath.slice(1)}.${error.params.additionalProperty}`
1818
: error.params.additionalProperty;
1919

2020
return `Unexpected top-level property "${formattedPropertyPath}"`;
2121
}
2222
if (error.keyword === 'type') {
23-
const formattedField = error.dataPath.slice(1);
23+
const formattedField = error.instancePath.slice(1);
2424
if (!formattedField) {
2525
return `Config has the wrong type - ${error.message}`;
2626
}
2727
return `Property "${formattedField}" has the wrong type - ${error.message}`;
2828
}
2929
const field =
30-
(error.dataPath[0] === '.'
31-
? error.dataPath.slice(1)
32-
: error.dataPath) || 'Config';
30+
(error.instancePath[0] === '.'
31+
? error.instancePath.slice(1)
32+
: error.instancePath) || 'Config';
3333
if (error.keyword === 'typeof') {
3434
return `"${field}" should be a ${error.schema}. Value: ${JSON.stringify(
3535
error.data

Diff for: @commitlint/config-validator/src/validate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ export function validateConfig(
1919
): asserts config is UserConfig {
2020
const ajv = new Ajv({
2121
meta: false,
22+
strict: false,
2223
useDefaults: true,
2324
validateSchema: false,
24-
missingRefs: 'ignore',
2525
verbose: true,
26-
schemaId: 'auto',
2726
});
2827

29-
ajv.addKeyword('typeof', {
28+
ajv.addKeyword({
29+
keyword: 'typeof',
3030
validate: function typeOfFunc(schema: any, data: any) {
3131
return typeof data === schema;
3232
},

Diff for: yarn.lock

+17-2
Original file line numberDiff line numberDiff line change
@@ -3016,7 +3016,7 @@ aggregate-error@^3.0.0:
30163016
clean-stack "^2.0.0"
30173017
indent-string "^4.0.0"
30183018

3019-
ajv@^6.10.0, ajv@^6.12.4, ajv@^6.12.6:
3019+
ajv@^6.10.0, ajv@^6.12.4:
30203020
version "6.12.6"
30213021
resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4"
30223022
integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==
@@ -3026,6 +3026,16 @@ ajv@^6.10.0, ajv@^6.12.4, ajv@^6.12.6:
30263026
json-schema-traverse "^0.4.1"
30273027
uri-js "^4.2.2"
30283028

3029+
ajv@^8.11.0:
3030+
version "8.11.0"
3031+
resolved "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz#977e91dd96ca669f54a11e23e378e33b884a565f"
3032+
integrity sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==
3033+
dependencies:
3034+
fast-deep-equal "^3.1.1"
3035+
json-schema-traverse "^1.0.0"
3036+
require-from-string "^2.0.2"
3037+
uri-js "^4.2.2"
3038+
30293039
ansi-align@^3.0.0:
30303040
version "3.0.1"
30313041
resolved "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59"
@@ -6434,6 +6444,11 @@ json-schema-traverse@^0.4.1:
64346444
resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
64356445
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==
64366446

6447+
json-schema-traverse@^1.0.0:
6448+
version "1.0.0"
6449+
resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2"
6450+
integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==
6451+
64376452
json-stable-stringify-without-jsonify@^1.0.1:
64386453
version "1.0.1"
64396454
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
@@ -8339,7 +8354,7 @@ require-directory@^2.1.1:
83398354
resolved "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
83408355
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=
83418356

8342-
require-from-string@2.0.2:
8357+
require-from-string@2.0.2, require-from-string@^2.0.2:
83438358
version "2.0.2"
83448359
resolved "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
83458360
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==

0 commit comments

Comments
 (0)