Skip to content

Commit 1cbf1fc

Browse files
authored
Merge branch 'next' into infra/unicorn/text-encoding-identifier-case
2 parents 4499060 + 28d3bad commit 1cbf1fc

File tree

12 files changed

+78
-93
lines changed

12 files changed

+78
-93
lines changed

.eslintrc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ module.exports = defineConfig({
4949
// Each rule should be checked whether it should be enabled/configured and the problems fixed, or stay disabled permanently.
5050
'unicorn/better-regex': 'off',
5151
'unicorn/catch-error-name': 'off',
52-
'unicorn/consistent-destructuring': 'off',
5352
'unicorn/consistent-function-scoping': 'off',
5453
'unicorn/escape-case': 'off',
5554
'unicorn/filename-case': 'off',
5655
'unicorn/import-style': 'off',
5756
'unicorn/no-array-callback-reference': 'off',
58-
'unicorn/no-array-for-each': 'off',
5957
'unicorn/no-array-reduce': 'off',
6058
'unicorn/no-await-expression-member': 'off',
6159
'unicorn/no-for-loop': 'off',
@@ -68,7 +66,6 @@ module.exports = defineConfig({
6866
'unicorn/prefer-array-some': 'off',
6967
'unicorn/prefer-code-point': 'off',
7068
'unicorn/prefer-export-from': 'off',
71-
'unicorn/prefer-includes': 'off',
7269
'unicorn/prefer-module': 'off',
7370
'unicorn/prefer-native-coercion-functions': 'off',
7471
'unicorn/prefer-negative-index': 'off',

scripts/apidoc/parameterDefaults.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ function patchSignatureParameterDefaults(
130130
throw new Error('Unexpected parameter length mismatch');
131131
}
132132

133-
signatureParameters.forEach(
134-
(param, index) =>
135-
(param.defaultValue = parameterDefaults[index] || param.defaultValue)
136-
);
133+
for (const [index, param] of signatureParameters.entries()) {
134+
param.defaultValue = parameterDefaults[index] || param.defaultValue;
135+
}
137136
}

src/modules/datatype/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ export class DatatypeModule {
407407
const properties = ['foo', 'bar', 'bike', 'a', 'b', 'name', 'prop'];
408408
const returnObject: Record<string, string | number> = {};
409409

410-
properties.forEach((prop) => {
410+
for (const prop of properties) {
411411
returnObject[prop] = this.boolean()
412412
? this.faker.string.sample()
413413
: this.faker.number.int();
414-
});
414+
}
415415

416416
return JSON.stringify(returnObject);
417417
}

src/modules/helpers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export class SimpleHelpersModule {
460460
}
461461

462462
while (range != null) {
463-
if (range[0].indexOf('-') === -1) {
463+
if (!range[0].includes('-')) {
464464
// handle non-ranges
465465
if (isCaseInsensitive && isNaN(Number(range[0]))) {
466466
rangeCodes.push(

src/modules/helpers/unique.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,53 +95,51 @@ export function exec<
9595
startTime = Date.now(),
9696
maxTime = 50,
9797
maxRetries = 50,
98+
currentIterations = 0,
9899
compare = defaultCompare,
99100
store,
100101
} = options;
101102
let { exclude } = options;
102-
options.currentIterations = options.currentIterations ?? 0;
103+
options.currentIterations = currentIterations;
103104

104105
// Support single exclude argument as string
105106
if (!Array.isArray(exclude)) {
106107
exclude = [exclude];
107108
}
108109

109-
// if (options.currentIterations > 0) {
110-
// console.log('iterating', options.currentIterations)
111-
// }
112-
113-
// console.log(now - startTime)
110+
// If out of time -> throw error.
114111
if (now - startTime >= maxTime) {
115112
return errorMessage(
116113
startTime,
117114
now,
118115
`Exceeded maxTime: ${maxTime}`,
119116
store,
120-
options.currentIterations
117+
currentIterations
121118
);
122119
}
123120

124-
if (options.currentIterations >= maxRetries) {
121+
// If out of retries -> throw error.
122+
if (currentIterations >= maxRetries) {
125123
return errorMessage(
126124
startTime,
127125
now,
128126
`Exceeded maxRetries: ${maxRetries}`,
129127
store,
130-
options.currentIterations
128+
currentIterations
131129
);
132130
}
133131

134132
// Execute the provided method to find a potential satisfied value.
135133
const result: ReturnType<TMethod> = method(...args) as ReturnType<TMethod>;
136134

137135
// If the result has not been previously found, add it to the found array and return the value as it's unique.
138-
if (compare(store, result) === -1 && exclude.indexOf(result) === -1) {
136+
if (compare(store, result) === -1 && !exclude.includes(result)) {
139137
store[result] = result;
140138
options.currentIterations = 0;
141139
return result;
142140
}
143141

144-
// console.log('conflict', result);
142+
// Conflict, try again.
145143
options.currentIterations++;
146144
return exec(method, args, {
147145
...options,

src/modules/system/index.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,11 @@ export class SystemModule {
154154
* @since 3.1.0
155155
*/
156156
fileType(): string {
157-
const typeSet = new Set<string>();
158157
const mimeTypes = this.faker.definitions.system.mimeTypes;
159158

160-
Object.keys(mimeTypes).forEach((m) => {
161-
const type = m.split('/')[0];
162-
163-
typeSet.add(type);
164-
});
165-
159+
const typeSet = new Set(
160+
Object.keys(mimeTypes).map((key) => key.split('/')[0])
161+
);
166162
const types = Array.from(typeSet);
167163
return this.faker.helpers.arrayElement(types);
168164
}
@@ -179,22 +175,15 @@ export class SystemModule {
179175
* @since 3.1.0
180176
*/
181177
fileExt(mimeType?: string): string {
182-
if (typeof mimeType === 'string') {
183-
const mimes = this.faker.definitions.system.mimeTypes;
184-
return this.faker.helpers.arrayElement(mimes[mimeType].extensions);
185-
}
186-
187178
const mimeTypes = this.faker.definitions.system.mimeTypes;
188-
const extensionSet = new Set<string>();
189179

190-
Object.keys(mimeTypes).forEach((m) => {
191-
if (mimeTypes[m].extensions instanceof Array) {
192-
mimeTypes[m].extensions.forEach((ext) => {
193-
extensionSet.add(ext);
194-
});
195-
}
196-
});
180+
if (typeof mimeType === 'string') {
181+
return this.faker.helpers.arrayElement(mimeTypes[mimeType].extensions);
182+
}
197183

184+
const extensionSet = new Set(
185+
Object.values(mimeTypes).flatMap(({ extensions }) => extensions)
186+
);
198187
const extensions = Array.from(extensionSet);
199188
return this.faker.helpers.arrayElement(extensions);
200189
}

test/all_functional.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { describe, expect, it } from 'vitest';
22
import type { allLocales, Faker, RandomModule } from '../src';
33
import { allFakers, fakerEN } from '../src';
44

5-
const IGNORED_MODULES = [
5+
const IGNORED_MODULES = new Set([
66
'rawDefinitions',
77
'definitions',
88
'helpers',
99
'_randomizer',
1010
'_defaultRefDate',
11-
];
11+
]);
1212

1313
function isTestableModule(mod: string) {
14-
return IGNORED_MODULES.indexOf(mod) === -1;
14+
return !IGNORED_MODULES.has(mod);
1515
}
1616

1717
function isMethodOf(mod: string) {
@@ -119,7 +119,8 @@ describe('functional tests', () => {
119119
}
120120

121121
describe.each(Object.entries(modules))('%s', (module, methods) => {
122-
methods.forEach((meth) => {
122+
// eslint-disable-next-line vitest/prefer-each -- need to dynamically succeed/fail
123+
for (const meth of methods) {
123124
const testAssertion = () => {
124125
// TODO @ST-DDT 2022-03-28: Use random seed once there are no more failures
125126
faker.seed(1);
@@ -140,7 +141,7 @@ describe('functional tests', () => {
140141
// We expect a failure here to ensure we remove the exclusions when fixed
141142
it.fails(`${meth}()`, testAssertion);
142143
}
143-
});
144+
}
144145
});
145146
});
146147
});
@@ -153,7 +154,8 @@ describe('faker.helpers.fake functional tests', () => {
153154
}
154155

155156
describe.each(Object.entries(modules))('%s', (module, methods) => {
156-
methods.forEach((meth) => {
157+
// eslint-disable-next-line vitest/prefer-each -- need to dynamically succeed/fail
158+
for (const meth of methods) {
157159
const testAssertion = () => {
158160
// TODO @ST-DDT 2022-03-28: Use random seed once there are no more failures
159161
faker.seed(1);
@@ -172,7 +174,7 @@ describe('faker.helpers.fake functional tests', () => {
172174
// We expect a failure here to ensure we remove the exclusions when fixed
173175
it.fails(`${meth}()`, testAssertion);
174176
}
175-
});
177+
}
176178
});
177179
});
178180
});

test/modules/color.spec.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ describe('color', () => {
8888
it('should return a random rgb color in decimal format', () => {
8989
const color = faker.color.rgb({ format: 'decimal' });
9090
expect(color).length(3);
91-
color.forEach((value: number) => {
91+
for (const value of color) {
9292
expect(value).toBeGreaterThanOrEqual(0);
9393
expect(value).toBeLessThanOrEqual(255);
94-
});
94+
}
9595
});
9696
});
9797

@@ -124,10 +124,10 @@ describe('color', () => {
124124
});
125125
expect(color[color.length - 1]).toBeGreaterThanOrEqual(0);
126126
expect(color[color.length - 1]).toBeLessThanOrEqual(1);
127-
color.slice(0, 4).forEach((value: number) => {
127+
for (const value of color.slice(0, 4)) {
128128
expect(value).toBeGreaterThanOrEqual(0);
129129
expect(value).toBeLessThanOrEqual(255);
130-
});
130+
}
131131
});
132132
});
133133

@@ -154,21 +154,21 @@ describe('color', () => {
154154
it('should return a random cmyk color', () => {
155155
const color = faker.color.cmyk();
156156
expect(color).length(4);
157-
color.forEach((value: number) => {
157+
for (const value of color) {
158158
expect(value).toBeGreaterThanOrEqual(0);
159159
expect(value).toBeLessThanOrEqual(1);
160-
});
160+
}
161161
});
162162
});
163163

164164
describe(`cmyk({ format: 'decimal' })`, () => {
165165
it('should return a random cmyk color in decimal format', () => {
166166
const color = faker.color.cmyk({ format: 'decimal' });
167167
expect(color).length(4);
168-
color.forEach((value: number) => {
168+
for (const value of color) {
169169
expect(value).toBeGreaterThanOrEqual(0);
170170
expect(value).toBeLessThanOrEqual(1);
171-
});
171+
}
172172
});
173173
});
174174

@@ -196,10 +196,10 @@ describe('color', () => {
196196
expect(color).length(3);
197197
expect(color[0]).toBeGreaterThanOrEqual(0);
198198
expect(color[0]).toBeLessThanOrEqual(360);
199-
color.slice(1).forEach((value: number) => {
199+
for (const value of color.slice(1)) {
200200
expect(value).toBeGreaterThanOrEqual(0);
201201
expect(value).toBeLessThanOrEqual(1);
202-
});
202+
}
203203
});
204204
});
205205

@@ -246,10 +246,10 @@ describe('color', () => {
246246
expect(color).length(3);
247247
expect(color[0]).toBeGreaterThanOrEqual(0);
248248
expect(color[0]).toBeLessThanOrEqual(360);
249-
color.slice(1).forEach((value: number) => {
249+
for (const value of color.slice(1)) {
250250
expect(value).toBeGreaterThanOrEqual(0);
251251
expect(value).toBeLessThanOrEqual(1);
252-
});
252+
}
253253
});
254254
});
255255

@@ -259,10 +259,10 @@ describe('color', () => {
259259
expect(color).length(3);
260260
expect(color[0]).toBeGreaterThanOrEqual(0);
261261
expect(color[0]).toBeLessThanOrEqual(360);
262-
color.slice(1).forEach((value: number) => {
262+
for (const value of color.slice(1)) {
263263
expect(value).toBeGreaterThanOrEqual(0);
264264
expect(value).toBeLessThanOrEqual(1);
265-
});
265+
}
266266
});
267267
});
268268

@@ -286,10 +286,10 @@ describe('color', () => {
286286
expect(color).length(3);
287287
expect(color[0]).toBeGreaterThanOrEqual(0);
288288
expect(color[0]).toBeLessThanOrEqual(1);
289-
color.forEach((value: number) => {
289+
for (const value of color) {
290290
expect(value).toBeGreaterThanOrEqual(-100);
291291
expect(value).toBeLessThanOrEqual(100);
292-
});
292+
}
293293
});
294294
});
295295

@@ -299,10 +299,10 @@ describe('color', () => {
299299
expect(color).length(3);
300300
expect(color[0]).toBeGreaterThanOrEqual(0);
301301
expect(color[0]).toBeLessThanOrEqual(1);
302-
color.forEach((value: number) => {
302+
for (const value of color) {
303303
expect(value).toBeGreaterThanOrEqual(-100);
304304
expect(value).toBeLessThanOrEqual(100);
305-
});
305+
}
306306
});
307307
});
308308

@@ -328,10 +328,10 @@ describe('color', () => {
328328
expect(color).length(3);
329329
expect(color[0]).toBeGreaterThanOrEqual(0);
330330
expect(color[0]).toBeLessThanOrEqual(1);
331-
color.forEach((value: number) => {
331+
for (const value of color) {
332332
expect(value).toBeGreaterThanOrEqual(0);
333333
expect(value).toBeLessThanOrEqual(230);
334-
});
334+
}
335335
});
336336
});
337337

@@ -341,10 +341,10 @@ describe('color', () => {
341341
expect(color).length(3);
342342
expect(color[0]).toBeGreaterThanOrEqual(0);
343343
expect(color[0]).toBeLessThanOrEqual(1);
344-
color.forEach((value: number) => {
344+
for (const value of color) {
345345
expect(value).toBeGreaterThanOrEqual(0);
346346
expect(value).toBeLessThanOrEqual(230);
347-
});
347+
}
348348
});
349349
});
350350

@@ -368,21 +368,21 @@ describe('color', () => {
368368
it('should return a random color for a CSS color space in decimal format', () => {
369369
const color = faker.color.colorByCSSColorSpace();
370370
expect(color).length(3);
371-
color.forEach((value: number) => {
371+
for (const value of color) {
372372
expect(value).toBeGreaterThanOrEqual(0);
373373
expect(value).toBeLessThanOrEqual(1);
374-
});
374+
}
375375
});
376376
});
377377

378378
describe(`colorByCSSColorSpace({ format: 'decimal' })`, () => {
379379
it('should return a random color for a CSS color space in decimal format', () => {
380380
const color = faker.color.colorByCSSColorSpace({ format: 'decimal' });
381381
expect(color).length(3);
382-
color.forEach((value: number) => {
382+
for (const value of color) {
383383
expect(value).toBeGreaterThanOrEqual(0);
384384
expect(value).toBeLessThanOrEqual(1);
385-
});
385+
}
386386
});
387387
});
388388

0 commit comments

Comments
 (0)