Skip to content

Commit 7674d33

Browse files
committed
Merge branch 'next' into unicorn/prefer-spread
2 parents 7a48f89 + 28d3bad commit 7674d33

File tree

12 files changed

+80
-97
lines changed

12 files changed

+80
-97
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: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,12 @@ 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-
166-
const types = [...typeSet];
167-
return this.faker.helpers.arrayElement(types);
159+
const typeSet = new Set(
160+
Object.keys(mimeTypes).map((key) => key.split('/')[0])
161+
);
162+
return this.faker.helpers.arrayElement([...typeSet]);
168163
}
169164

170165
/**
@@ -179,24 +174,16 @@ export class SystemModule {
179174
* @since 3.1.0
180175
*/
181176
fileExt(mimeType?: string): string {
177+
const mimeTypes = this.faker.definitions.system.mimeTypes;
178+
182179
if (typeof mimeType === 'string') {
183-
const mimes = this.faker.definitions.system.mimeTypes;
184-
return this.faker.helpers.arrayElement(mimes[mimeType].extensions);
180+
return this.faker.helpers.arrayElement(mimeTypes[mimeType].extensions);
185181
}
186182

187-
const mimeTypes = this.faker.definitions.system.mimeTypes;
188-
const extensionSet = new Set<string>();
189-
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-
});
197-
198-
const extensions = [...extensionSet];
199-
return this.faker.helpers.arrayElement(extensions);
183+
const extensionSet = new Set(
184+
Object.values(mimeTypes).flatMap(({ extensions }) => extensions)
185+
);
186+
return this.faker.helpers.arrayElement([...extensionSet]);
200187
}
201188

202189
/**

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
});

0 commit comments

Comments
 (0)