Skip to content

Commit

Permalink
Merge branch 'next' into infra/unicorn/no-instanceof-array
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Oct 15, 2023
2 parents 4eca641 + b4fe307 commit 5abbee6
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 30 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module.exports = defineConfig({
// TODO @Shinigami92 2023-09-23: The following rules currently conflict with our code.
// Each rule should be checked whether it should be enabled/configured and the problems fixed, or stay disabled permanently.
'unicorn/better-regex': 'off',
'unicorn/catch-error-name': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/escape-case': 'off',
'unicorn/filename-case': 'off',
Expand Down
6 changes: 3 additions & 3 deletions scripts/apidoc/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export async function generate(): Promise<void> {
// Useful for manually analyzing the content
await app.generateJson(project, pathOutputJson);

const pages = await Promise.all([
const pages = [
...(await processFakerClasses(project)),
...(await processModules(project)).sort((a, b) =>
a.text.localeCompare(b.text)
),
await processFakerRandomizer(project),
processFakerUtilities(project),
]);
await processFakerUtilities(project),
];
await writeApiPagesIndex(pages.map(({ text, link }) => ({ text, link })));
writeApiDiffIndex(
Object.fromEntries(pages.map(({ text, diff }) => [text, diff]))
Expand Down
6 changes: 3 additions & 3 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ async function typeToText(type_?: Type, short = false): Promise<string> {
].join(' | ');
}

return `${type.name}<${type.typeArguments
.map(async (t) => await typeToText(t, short))
.join(', ')}>`;
return `${type.name}<${(
await Promise.all(type.typeArguments.map((t) => typeToText(t, short)))
).join(', ')}>`;

case 'reflection':
return declarationTypeToText(type.declaration, short);
Expand Down
8 changes: 4 additions & 4 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ async function main(): Promise<void> {
}

localeTitle = title;
} catch (e) {
} catch (error) {
console.error(
`Failed to load ${pathMetadata}. Please make sure the file exists and exports a MetadataDefinition.`
);
console.error(e);
console.error(error);
}

const localizedFaker = `faker${locale.replace(/^([a-z]+)/, (part) =>
Expand Down Expand Up @@ -367,8 +367,8 @@ async function main(): Promise<void> {
writeFileSync(pathDocsGuideLocalization, localizationContent);
}

main().catch((e) => {
main().catch((error) => {
// Workaround until top level await is available
console.error(e);
console.error(error);
process.exit(1);
});
2 changes: 1 addition & 1 deletion src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ export class HelpersModule extends SimpleHelpersModule {
// If anyone actually needs to optimize this specific code path, please open a support issue on github
try {
params = JSON.parse(`[${parameters}]`);
} catch (err) {
} catch {
// since JSON.parse threw an error, assume parameters was actually a string
params = [parameters];
}
Expand Down
8 changes: 8 additions & 0 deletions src/modules/number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ export class NumberModule {

/**
* Returns a single random floating-point number for a given precision or range and precision.
* The lower bound is inclusive, the upper bound is exclusive, unless precision is passed.
*
* @param options Upper bound or options object. Defaults to `{}`.
* @param options.min Lower bound for generated number. Defaults to `0.0`.
* @param options.max Upper bound for generated number. Defaults to `1.0`.
* @param options.precision Precision of the generated number, for example `0.01` will round to 2 decimal points.
* If precision is passed, the upper bound is inclusive.
*
* @example
* faker.number.float() // 0.5688541042618454
Expand Down Expand Up @@ -165,6 +167,7 @@ export class NumberModule {

/**
* Returns a [binary](https://en.wikipedia.org/wiki/Binary_number) number.
* The bounds are inclusive.
*
* @param options Maximum value or options object. Defaults to `{}`.
* @param options.min Lower bound for generated number. Defaults to `0`.
Expand Down Expand Up @@ -213,6 +216,7 @@ export class NumberModule {

/**
* Returns an [octal](https://en.wikipedia.org/wiki/Octal) number.
* The bounds are inclusive.
*
* @param options Maximum value or options object. Defaults to `{}`.
* @param options.min Lower bound for generated number. Defaults to `0`.
Expand Down Expand Up @@ -261,11 +265,14 @@ export class NumberModule {

/**
* Returns a lowercase [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) number.
* The bounds are inclusive.
*
* @param options Maximum value or options object. Defaults to `{}`.
* @param options.min Lower bound for generated number. Defaults to `0`.
* @param options.max Upper bound for generated number. Defaults to `15`.
*
* @throws When options define `max < min`.
*
* @example
* faker.number.hex() // 'b'
* faker.number.hex(255) // '9d'
Expand Down Expand Up @@ -305,6 +312,7 @@ export class NumberModule {

/**
* Returns a [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#bigint_type) number.
* The bounds are inclusive.
*
* @param options Maximum value or options object. Defaults to `{}`.
* @param options.min Lower bound for generated bigint. Defaults to `0n`.
Expand Down
54 changes: 40 additions & 14 deletions test/scripts/apidoc/__snapshots__/signature.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports[`signature > analyzeSignature() > complexArrayParameter 1`] = `
"returns": "T",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L358",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L367",
"throws": undefined,
}
`;
Expand Down Expand Up @@ -93,6 +93,7 @@ exports[`signature > analyzeSignature() > expected and actual methods are equal
"optionsInterfaceParamMethodWithDefaults",
"optionsParamMethod",
"optionsTypeParamMethodWithDefaults",
"recordParamMethod",
"requiredNumberParamMethod",
"stringUnionParamMethod",
]
Expand Down Expand Up @@ -198,7 +199,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecated 1`] = `
"test.apidoc.methodWithExample()",
],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L278",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L287",
"throws": undefined,
}
`;
Expand Down Expand Up @@ -250,7 +251,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecatedOption 1`] = `
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L299",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L308",
"throws": undefined,
}
`;
Expand All @@ -268,7 +269,7 @@ exports[`signature > analyzeSignature() > methodWithExample 1`] = `
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L267",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L276",
"throws": undefined,
}
`;
Expand All @@ -288,7 +289,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkers 1`] = `
"test.apidoc.methodWithDeprecated()",
],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L326",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L335",
"throws": undefined,
}
`;
Expand All @@ -308,7 +309,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkersAndBacktic
"test.apidoc.methodWithDeprecated() with parameter <code>bar</code> and <code>baz</code>.",
],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L336",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L345",
"throws": undefined,
}
`;
Expand All @@ -325,7 +326,7 @@ exports[`signature > analyzeSignature() > methodWithSinceMarker 1`] = `
"returns": "number",
"seeAlsos": [],
"since": "1.0.0",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L345",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L354",
"throws": undefined,
}
`;
Expand All @@ -342,7 +343,7 @@ exports[`signature > analyzeSignature() > methodWithThrows 1`] = `
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L287",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L296",
"throws": "a Faker error",
}
`;
Expand Down Expand Up @@ -491,7 +492,7 @@ It also has a more complex description.</p>
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L217",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L226",
"throws": undefined,
}
`;
Expand Down Expand Up @@ -530,15 +531,15 @@ exports[`signature > analyzeSignature() > optionsInterfaceParamMethodWithDefault
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L253",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L262",
"throws": undefined,
}
`;
exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
{
"deprecated": undefined,
"description": "<p>Test with a function parameters.</p>
"description": "<p>Test with an options parameter.</p>
",
"examples": "<div class=\\"language-ts\\"><button title=\\"Copy Code\\" class=\\"copy\\"></button><span class=\\"lang\\">ts</span><pre v-pre class=\\"shiki material-theme-palenight\\"><code><span class=\\"line\\"><span style=\\"color:#82AAFF\\">optionsParamMethod</span><span style=\\"color:#BABED8\\">(options: </span><span style=\\"color:#89DDFF\\">{</span></span>
<span class=\\"line\\"><span style=\\"color:#BABED8\\"> </span><span style=\\"color:#F07178\\">a</span><span style=\\"color:#89DDFF\\">:</span><span style=\\"color:#BABED8\\"> number</span><span style=\\"color:#89DDFF\\">,</span></span>
Expand All @@ -552,7 +553,7 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
"parameters": [
{
"default": undefined,
"description": "<p>The function parameter.</p>
"description": "<p>The options parameter.</p>
",
"name": "options",
"type": "{ ... }",
Expand Down Expand Up @@ -596,7 +597,7 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = `
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L187",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L196",
"throws": undefined,
}
`;
Expand Down Expand Up @@ -635,7 +636,32 @@ exports[`signature > analyzeSignature() > optionsTypeParamMethodWithDefaults 1`]
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L235",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L244",
"throws": undefined,
}
`;
exports[`signature > analyzeSignature() > recordParamMethod 1`] = `
{
"deprecated": undefined,
"description": "<p>Test with a Record parameter.</p>
",
"examples": "<div class=\\"language-ts\\"><button title=\\"Copy Code\\" class=\\"copy\\"></button><span class=\\"lang\\">ts</span><pre v-pre class=\\"shiki material-theme-palenight\\"><code><span class=\\"line\\"><span style=\\"color:#82AAFF\\">recordParamMethod</span><span style=\\"color:#BABED8\\">(object: Record</span><span style=\\"color:#89DDFF\\">&lt;</span><span style=\\"color:#BABED8\\">string</span><span style=\\"color:#89DDFF\\">,</span><span style=\\"color:#BABED8\\"> number</span><span style=\\"color:#89DDFF\\">&gt;</span><span style=\\"color:#BABED8\\">): number</span></span></code></pre>
</div>",
"name": "recordParamMethod",
"parameters": [
{
"default": undefined,
"description": "<p>The Record parameter.</p>
",
"name": "object",
"type": "Record<string, number>",
},
],
"returns": "number",
"seeAlsos": [],
"since": "",
"sourcePath": "test/scripts/apidoc/signature.example.ts#L182",
"throws": undefined,
}
`;
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/apidoc/signature.debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { loadExampleMethods } from './utils';
const methods = loadExampleMethods();

initMarkdownRenderer()
.then(() => {
.then(async () => {
for (const [name, method] of Object.entries(methods)) {
console.log('Analyzing:', name);
const result = analyzeSignature(method, '', method.name);
const result = await analyzeSignature(method, '', method.name);
console.log('Result:', result);
}
})
Expand Down
13 changes: 11 additions & 2 deletions test/scripts/apidoc/signature.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,18 @@ export class SignatureTest {
}

/**
* Test with a function parameters.
* Test with a Record parameter.
*
* @param options The function parameter.
* @param object The Record parameter.
*/
recordParamMethod(object: Record<string, number>): number {
return object.a;
}

/**
* Test with an options parameter.
*
* @param options The options parameter.
* @param options.a The number parameter.
* @param options.b The string parameter.
* @param options.c The boolean parameter.
Expand Down

0 comments on commit 5abbee6

Please sign in to comment.