Skip to content

Commit 8673c3e

Browse files
committed
Merge remote-tracking branch 'origin/master' into chore/expressions-types
2 parents 195e4fd + b32b80d commit 8673c3e

File tree

12 files changed

+51
-43
lines changed

12 files changed

+51
-43
lines changed

.eslintignore

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

API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ const schema = Joi.any().description('this key will match anything you give it')
723723

724724
#### `any.empty(schema)`
725725

726-
Considers anything that matches the schema to be empty (`undefined`).
727-
- `schema` - any object or **joi** schema to match. An undefined schema unsets that rule.
726+
Considers anything that matches the schema to be empty (`undefined`). Overrides any previous calls to empty.
727+
- `schema` - an object, value, or **joi** schema to match or an array of objects, values, and **joi** schemas to match. An undefined schema unsets that rule.
728728

729729
```js
730730
let schema = Joi.string().empty('');

benchmarks/bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (args.compare) {
3838
try {
3939
compare = JSON.parse(Fs.readFileSync(args.compare, 'utf8'));
4040
}
41-
catch (e) {
41+
catch {
4242
// Ignore error
4343
}
4444
}

eslint.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
const HapiPlugin = require('@hapi/eslint-plugin');
4+
5+
module.exports = [
6+
{
7+
ignores: ['browser', 'dist', 'sandbox.js']
8+
},
9+
...HapiPlugin.configs.module
10+
];

lib/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,8 @@ declare namespace Joi {
10611061
disallow(...values: any[]): this;
10621062

10631063
/**
1064-
* Considers anything that matches the schema to be empty (undefined).
1065-
* @param schema - any object or joi schema to match. An undefined schema unsets that rule.
1064+
* Considers anything that matches the schema to be empty (undefined). Overrides any previous calls to empty.
1065+
* @param schema - an object, value, or joi schema to match or an array of objects, values, and joi schemas to match. An undefined schema unsets that rule.
10661066
*/
10671067
empty(schema?: SchemaLike): this;
10681068

@@ -2127,12 +2127,12 @@ declare namespace Joi {
21272127
array<TSchema = any[]>(): ArraySchema<TSchema>;
21282128

21292129
/**
2130-
* Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via boolean().
2130+
* Generates a schema object that matches a boolean data type (as well as the strings 'true' and 'false'). Can also be called via boolean().
21312131
*/
21322132
bool<TSchema = boolean>(): BooleanSchema<TSchema>;
21332133

21342134
/**
2135-
* Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool().
2135+
* Generates a schema object that matches a boolean data type (as well as the strings 'true' and 'false'). Can also be called via bool().
21362136
*/
21372137
boolean<TSchema = boolean>(): BooleanSchema<TSchema>;
21382138

lib/types/binary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = Any.extend({
2121
try {
2222
return { value: Buffer.from(value, schema._flags.encoding) };
2323
}
24-
catch (ignoreErr) { }
24+
catch { }
2525
}
2626
}
2727
},

lib/types/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ internals.generate = function (schema, value, state, prefs) {
115115
try {
116116
linked = path.length ? perspective.$_reach(path) : perspective;
117117
}
118-
catch (ignoreErr) {
118+
catch {
119119
internals.assert(false, 'to non-existing schema', ref, schema, state, prefs);
120120
}
121121

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515
"validation"
1616
],
1717
"dependencies": {
18-
"@hapi/hoek": "^11.0.4",
19-
"@hapi/tlds": "^1.0.6",
20-
"@hapi/topo": "^6.0.2",
2118
"@hapi/address": "^5.1.1",
19+
"@hapi/formula": "^3.0.2",
20+
"@hapi/hoek": "^11.0.7",
2221
"@hapi/pinpoint": "^2.0.1",
23-
"@hapi/formula": "^3.0.2"
22+
"@hapi/tlds": "^1.1.0",
23+
"@hapi/topo": "^6.0.2"
2424
},
2525
"devDependencies": {
2626
"@hapi/bourne": "^3.0.0",
2727
"@hapi/code": "^9.0.3",
28+
"@hapi/eslint-plugin": "^7.0.0",
2829
"@hapi/joi-legacy-test": "npm:@hapi/[email protected]",
29-
"@hapi/lab": "^25.1.3",
30-
"@types/node": "^18.18.3",
31-
"typescript": "^5.2.2"
30+
"@hapi/lab": "^26.0.0",
31+
"@types/node": "^18.19.80",
32+
"typescript": "^5.8.2"
3233
},
3334
"scripts": {
3435
"prepublishOnly": "cd browser && npm install && npm run build",

test/extend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ describe('extension', () => {
15301530
try {
15311531
return { value: Bourne.parse(value) };
15321532
}
1533-
catch (ignoreErr) { }
1533+
catch { }
15341534
}
15351535
}
15361536
});
@@ -1579,7 +1579,7 @@ describe('extension', () => {
15791579
try {
15801580
return { value: Bourne.parse(value) };
15811581
}
1582-
catch (ignoreErr) { }
1582+
catch { }
15831583
}
15841584
}
15851585
});

test/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ validOpts = { stripUnknown: bool };
5959
validOpts = { stripUnknown: { arrays: bool } };
6060
validOpts = { stripUnknown: { objects: bool } };
6161
validOpts = { stripUnknown: { arrays: bool, objects: bool } };
62-
validOpts = { presence: 'optional' || 'required' || 'forbidden' };
62+
validOpts = { presence: 'optional' };
63+
validOpts = { presence: 'required' };
64+
validOpts = { presence: 'forbidden' };
6365
validOpts = { context: obj };
6466
validOpts = { noDefaults: bool };
6567
validOpts = {
@@ -203,17 +205,17 @@ validErrItem = {
203205
context: obj,
204206
};
205207

206-
validErrFunc = (errs) => errs[0];
208+
validErrFunc = (errs) => errs[0] ? errs[0] : [];
207209
validErrFunc = (errs) => 'Some error';
208210
validErrFunc = (errs) => err;
209211

210212
// error() can take function with ErrorReport argument
211213
validErrFunc = (errors) => {
212-
const path: string = errors[0].path[0];
213-
const code: string = errors[0].code;
214-
const messages = errors[0].prefs.messages;
214+
const path: string | undefined = errors[0]?.path[0];
215+
const code: string | undefined = errors[0]?.code;
216+
const messages = errors[0]?.prefs.messages;
215217

216-
const message: string = messages ? messages[code].rendered : 'Error';
218+
const message: string = messages && code && messages[code]?.rendered || 'Error';
217219

218220
const validationErr = new Error();
219221
validationErr.message = `[${path}]: ${message}`;

test/types/object.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ describe('object', () => {
19411941
Joi.object().or({});
19421942
error = false;
19431943
}
1944-
catch (e) {
1944+
catch {
19451945
error = true;
19461946
}
19471947

@@ -1951,7 +1951,7 @@ describe('object', () => {
19511951
Joi.object().or(123);
19521952
error = false;
19531953
}
1954-
catch (e) {
1954+
catch {
19551955
error = true;
19561956
}
19571957

@@ -2085,7 +2085,7 @@ describe('object', () => {
20852085
Joi.object().oxor({});
20862086
error = false;
20872087
}
2088-
catch (e) {
2088+
catch {
20892089
error = true;
20902090
}
20912091

@@ -2095,7 +2095,7 @@ describe('object', () => {
20952095
Joi.object().oxor(123);
20962096
error = false;
20972097
}
2098-
catch (e) {
2098+
catch {
20992099
error = true;
21002100
}
21012101

@@ -3734,7 +3734,7 @@ describe('object', () => {
37343734
Joi.object().with({});
37353735
error = false;
37363736
}
3737-
catch (e) {
3737+
catch {
37383738
error = true;
37393739
}
37403740

@@ -3744,7 +3744,7 @@ describe('object', () => {
37443744
Joi.object().with(123);
37453745
error = false;
37463746
}
3747-
catch (e) {
3747+
catch {
37483748
error = true;
37493749
}
37503750

@@ -3971,7 +3971,7 @@ describe('object', () => {
39713971
Joi.object().without({});
39723972
error = false;
39733973
}
3974-
catch (e) {
3974+
catch {
39753975
error = true;
39763976
}
39773977

@@ -3981,7 +3981,7 @@ describe('object', () => {
39813981
Joi.object().without(123);
39823982
error = false;
39833983
}
3984-
catch (e) {
3984+
catch {
39853985
error = true;
39863986
}
39873987

test/types/string.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7618,7 +7618,7 @@ describe('string', () => {
76187618
['file:///whatever', true],
76197619
['mailto:[email protected]', true],
76207620
['ftp://www.example.com', true],
7621-
['javascript:alert(\'hello\');', true], // eslint-disable-line no-script-url
7621+
['javascript:alert(\'hello\');', true],
76227622
['xmpp:[email protected]', true],
76237623
['f://some.host/path', true],
76247624
['http://localhost:18/asdf', true],
@@ -7660,7 +7660,7 @@ describe('string', () => {
76607660
['dash-test://foo/bar', true],
76617661
['xmpp:[email protected]', true],
76627662
['http://atpass:foo%[email protected]:8080/path?search=foo#bar', true],
7663-
['javascript:alert(\'hello\');', true], // eslint-disable-line no-script-url
7663+
['javascript:alert(\'hello\');', true],
76647664
['file://localhost/etc/node/', true],
76657665
['file:///etc/node/', true],
76667666
['http://USER:[email protected]/', true],
@@ -8046,7 +8046,7 @@ describe('string', () => {
80468046
['file:///whatever', true],
80478047
['mailto:[email protected]', true],
80488048
['ftp://www.example.com', true],
8049-
['javascript:alert(\'hello\');', true], // eslint-disable-line no-script-url
8049+
['javascript:alert(\'hello\');', true],
80508050
['xmpp:[email protected]', true],
80518051
['f://some.host/path', true],
80528052
['http://localhost:18/asdf', true],
@@ -8076,7 +8076,7 @@ describe('string', () => {
80768076
['dash-test://foo/bar', true],
80778077
['xmpp:[email protected]', true],
80788078
['http://atpass:foo%[email protected]:8080/path?search=foo#bar', true],
8079-
['javascript:alert(\'hello\');', true], // eslint-disable-line no-script-url
8079+
['javascript:alert(\'hello\');', true],
80808080
['file://localhost/etc/node/', true],
80818081
['file:///etc/node/', true],
80828082
['http://USER:[email protected]/', true],
@@ -8406,7 +8406,7 @@ describe('string', () => {
84068406
value: 'javascript:alert(\'hello\');',
84078407
label: 'value'
84088408
}
8409-
}], // eslint-disable-line no-script-url
8409+
}],
84108410
['xmpp:[email protected]', false, {
84118411
message: '"value" must be a valid relative uri',
84128412
path: [],
@@ -8676,7 +8676,7 @@ describe('string', () => {
86768676
value: 'javascript:alert(\'hello\');',
86778677
label: 'value'
86788678
}
8679-
}], // eslint-disable-line no-script-url
8679+
}],
86808680
['file://localhost/etc/node/', false, {
86818681
message: '"value" must be a valid relative uri',
86828682
path: [],

0 commit comments

Comments
 (0)