Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: blank line before block-like #1703

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = defineConfig({
'@typescript-eslint/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'block-like', next: '*' },
{ blankLine: 'always', prev: '*', next: 'block-like' },
],
'@typescript-eslint/restrict-template-expressions': [
'error',
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/apiDocsWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export function writeApiSearchIndex(project: ProjectReflection): void {
link: moduleName.toLowerCase(),
headers: [],
};

if (module.kind !== ReflectionKind.Property) {
apiSection.headers = module
.getChildrenByKind(ReflectionKind.Method)
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function processModuleMethods(project: ProjectReflection): PageIndex {

export function extractModuleName(module: DeclarationReflection): string {
const { name } = module;

// TODO @ST-DDT 2022-10-16: Remove in v10.
// Typedoc prefers the name of the module that is exported first.
if (name === 'AddressModule') {
Expand Down
4 changes: 4 additions & 0 deletions scripts/apidoc/parameterDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const parameterDefaultReader: EventCallback = (
symbol.declarations?.length
) {
const lastDeclaration = symbol.declarations[symbol.declarations.length - 1];

if (TypeScript.isFunctionLike(lastDeclaration)) {
(reflection as ParameterDefaultsAware).implementationDefaultParameters =
lastDeclaration.parameters.map((param) =>
Expand Down Expand Up @@ -90,6 +91,7 @@ export function patchProjectParameterDefaults(
const functionOrMethods = project.getReflectionsByKind(
reflectionKindFunctionOrMethod
) as DeclarationReflection[];

for (const functionOrMethod of functionOrMethods) {
patchMethodParameterDefaults(functionOrMethod);
}
Expand All @@ -105,6 +107,7 @@ function patchMethodParameterDefaults(method: DeclarationReflection): void {
const signature = signatures?.[signatures.length - 1];
const parameterDefaults = (method as unknown as ParameterDefaultsAware)
.implementationDefaultParameters;

if (signature && parameterDefaults) {
patchSignatureParameterDefaults(signature, parameterDefaults);
}
Expand All @@ -122,6 +125,7 @@ function patchSignatureParameterDefaults(
): void {
const signatureParameters =
signature.parameters ?? Array.from({ length: parameterDefaults.length });

if (signatureParameters.length !== parameterDefaults.length) {
throw new Error('Unexpected parameter length mismatch');
}
Expand Down
13 changes: 13 additions & 0 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function mdToHtml(md: string, inline: boolean = false): string {
const rawHtml = inline ? markdown.renderInline(md) : markdown.render(md);

const safeHtml: string = sanitizeHtml(rawHtml, htmlSanitizeOptions);

// Revert some escaped characters for comparison.
if (comparableSanitizedHtml(rawHtml) === comparableSanitizedHtml(safeHtml)) {
return safeHtml;
Expand All @@ -113,6 +114,7 @@ export function analyzeSignature(
// Collect Type Parameters
const typeParameters = signature.typeParameters || [];
const signatureTypeParameters: string[] = [];

for (const parameter of typeParameters) {
signatureTypeParameters.push(parameter.name);
parameters.push({
Expand All @@ -124,6 +126,7 @@ export function analyzeSignature(

// Collect Parameters
const signatureParameters: string[] = [];

for (
let index = 0;
signature.parameters && index < signature.parameters.length;
Expand All @@ -139,23 +142,27 @@ export function analyzeSignature(
// Generate usage section

let signatureTypeParametersString = '';

if (signatureTypeParameters.length !== 0) {
signatureTypeParametersString = `<${signatureTypeParameters.join(', ')}>`;
}

const signatureParametersString = signatureParameters.join(', ');

let examples: string;

if (moduleName) {
examples = `faker.${moduleName}.${methodName}${signatureTypeParametersString}(${signatureParametersString}): ${signature.type?.toString()}\n`;
} else {
examples = `faker.${methodName}${signatureTypeParametersString}(${signatureParametersString}): ${signature.type?.toString()}\n`;
}

faker.seed(0);

if (moduleName) {
try {
let example = JSON.stringify(faker[moduleName][methodName]());

if (example.length > 50) {
example = `${example.substring(0, 47)}...`;
}
Expand All @@ -168,6 +175,7 @@ export function analyzeSignature(
}

const exampleTags = extractRawExamples(signature);

if (exampleTags.length > 0) {
examples += `${exampleTags.join('\n').trim()}\n`;
}
Expand Down Expand Up @@ -203,6 +211,7 @@ function analyzeParameter(parameter: ParameterReflection): {
const defaultValue = parameter.defaultValue ?? commentDefault;

let signatureText = '';

if (defaultValue) {
signatureText = ` = ${defaultValue}`;
}
Expand Down Expand Up @@ -266,6 +275,7 @@ function typeToText(type_?: Type, short = false): string {
}

const type = type_ as SomeType;

switch (type.type) {
case 'array':
return `${typeToText(type.elementType, short)}[]`;
Expand All @@ -274,6 +284,7 @@ function typeToText(type_?: Type, short = false): string {
.map((t) => typeToText(t, short))
.sort()
.join(' | ');

case 'reference':
if (!type.typeArguments || !type.typeArguments.length) {
return type.name;
Expand Down Expand Up @@ -359,11 +370,13 @@ function extractDefaultFromComment(comment?: Comment): string | undefined {

const summary = comment.summary;
const text = joinTagParts(summary).trim();

if (!text) {
return;
}

const result = /^(.*)[ \n]Defaults to `([^`]+)`\.(.*)$/s.exec(text);

if (!result) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function extractSeeAlsos(signature?: SignatureReflection): string[] {
.split('\n')
.map((link) => {
link = link.trim();

if (link.startsWith('-')) {
link = link.slice(1).trim();
}
Expand Down
1 change: 1 addition & 0 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if (existsSync(localeDir)) {
}

mkdirSync(localeDir);

for (const locale of Object.keys(locales)) {
writeFileSync(
`${localeDir}/${locale}.js`,
Expand Down
5 changes: 5 additions & 0 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const autoGeneratedCommentHeader = `/*

function removeIndexTs(files: string[]): string[] {
const index = files.indexOf('index.ts');

if (index !== -1) {
files.splice(index, 1);
}
Expand Down Expand Up @@ -130,6 +131,7 @@ function generateLocaleFile(locale: string): void {

function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
let localeDef: LocaleDefinition;

// This call might fail, if the module setup is broken.
// Unfortunately, we try to fix it with this script
// Thats why have a fallback logic here, we only need the title and separator anyway
Expand Down Expand Up @@ -171,6 +173,7 @@ function generateLocalesIndexFile(

const content = [autoGeneratedCommentHeader];
let fieldType = '';

if (type !== 'any') {
fieldType = `: ${type}`;
content.push(
Expand Down Expand Up @@ -208,9 +211,11 @@ function generateRecursiveModuleIndexes(

let submodules = readdirSync(path);
submodules = removeIndexTs(submodules);

for (const submodule of submodules) {
const pathModule = resolve(path, submodule);
updateLocaleFile(pathModule);

// Only process sub folders recursively
if (lstatSync(pathModule).isDirectory()) {
let moduleDefinition =
Expand Down
1 change: 1 addition & 0 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class Faker {
}

let result = target[module];

if (result) {
return result;
} else if (metadataKeys.includes(module)) {
Expand Down
5 changes: 5 additions & 0 deletions src/internal/mersenne/twister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default class MersenneTwister19937 {
*/
private multiplication32(n1: number, n2: number): number {
let sum = 0;

for (let i = 0; i < 32; ++i) {
if ((n1 >>> i) & 0x1) {
sum = this.addition32(sum, this.unsigned32(n2 << i));
Expand All @@ -140,6 +141,7 @@ export default class MersenneTwister19937 {
*/
initGenrand(seed: number): void {
this.mt[0] = this.unsigned32(seed & 0xffffffff);

for (this.mti = 1; this.mti < this.N; this.mti++) {
this.mt[this.mti] =
//(1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
Expand Down Expand Up @@ -172,6 +174,7 @@ export default class MersenneTwister19937 {
let i = 1;
let j = 0;
let k = this.N > keyLength ? this.N : keyLength;

for (; k; k--) {
// mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525)) + init_key[j] + j;
this.mt[i] = this.addition32(
Expand All @@ -191,6 +194,7 @@ export default class MersenneTwister19937 {
this.mt[i] = this.unsigned32(this.mt[i] & 0xffffffff);
i++;
j++;

if (i >= this.N) {
this.mt[0] = this.mt[this.N - 1];
i = 1;
Expand All @@ -216,6 +220,7 @@ export default class MersenneTwister19937 {
// mt[i] &= 0xffffffff; for WORDSIZE > 32 machines
this.mt[i] = this.unsigned32(this.mt[i] & 0xffffffff);
i++;

if (i >= this.N) {
this.mt[0] = this.mt[this.N - 1];
i = 1;
Expand Down
8 changes: 8 additions & 0 deletions src/modules/color/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function formatHexColor(
function toBinary(values: number[]): string {
const binary: string[] = values.map((value) => {
const isFloat = value % 1 !== 0;

if (isFloat) {
const buffer = new ArrayBuffer(4);
new DataView(buffer).setFloat32(0, value);
Expand All @@ -99,6 +100,7 @@ function toCSS(
space: CSSSpace = 'sRGB'
): string {
const percentage = (value: number) => Math.round(value * 100);

switch (cssFunction) {
case 'rgba':
return `rgba(${values[0]}, ${values[1]}, ${values[2]}, ${values[3]})`;
Expand Down Expand Up @@ -316,6 +318,7 @@ export class ColorModule {
options = { format, includeAlpha, prefix, casing };
let color: string | number[];
let cssFunction: CSSFunction = 'rgb';

if (format === 'hex') {
color = this.faker.string.hexadecimal({
length: includeAlpha ? 8 : 6,
Expand All @@ -326,6 +329,7 @@ export class ColorModule {
}

color = Array.from({ length: 3 }, () => this.faker.number.int(255));

if (includeAlpha) {
color.push(this.faker.number.float());
cssFunction = 'rgba';
Expand Down Expand Up @@ -463,6 +467,7 @@ export class ColorModule {
includeAlpha?: boolean;
}): string | number[] {
const hsl: number[] = [this.faker.number.int(360)];

for (let i = 0; i < (options?.includeAlpha ? 3 : 2); i++) {
hsl.push(this.faker.number.float());
}
Expand Down Expand Up @@ -541,6 +546,7 @@ export class ColorModule {
*/
hwb(options?: { format?: ColorFormat }): string | number[] {
const hsl: number[] = [this.faker.number.int(360)];

for (let i = 0; i < 2; i++) {
hsl.push(this.faker.number.float());
}
Expand Down Expand Up @@ -601,6 +607,7 @@ export class ColorModule {
lab(options?: { format?: ColorFormat }): string | number[];
lab(options?: { format?: ColorFormat }): string | number[] {
const lab = [this.faker.number.float({ precision: 0.000001 })];

for (let i = 0; i < 2; i++) {
lab.push(
this.faker.number.float({ min: -100, max: 100, precision: 0.0001 })
Expand Down Expand Up @@ -675,6 +682,7 @@ export class ColorModule {
lch(options?: { format?: ColorFormat }): string | number[];
lch(options?: { format?: ColorFormat }): string | number[] {
const lch = [this.faker.number.float({ precision: 0.000001 })];

for (let i = 0; i < 2; i++) {
lch.push(this.faker.number.float({ max: 230, precision: 0.1 }));
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/datatype/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export class DatatypeModule {
}

const { probability = 0.5 } = options;

if (probability <= 0) {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions src/modules/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { deprecated } from '../../internal/deprecated';
*/
function toDate(date?: string | Date | number): Date {
date = new Date(date);

if (isNaN(date.valueOf())) {
date = new Date();
}
Expand Down Expand Up @@ -643,6 +644,7 @@ export class DateModule {

const source = this.faker.definitions.date.month;
let type: keyof DateEntryDefinition;

if (abbr) {
if (context && source['abbr_context'] != null) {
type = 'abbr_context';
Expand Down Expand Up @@ -678,6 +680,7 @@ export class DateModule {

const source = this.faker.definitions.date.weekday;
let type: keyof DateEntryDefinition;

if (abbr) {
if (context && source['abbr_context'] != null) {
type = 'abbr_context';
Expand Down Expand Up @@ -733,6 +736,7 @@ export class DateModule {
// Convert to epoch timestamps
let min: number;
let max: number;

if (mode === 'age') {
min = new Date(refDate).setUTCFullYear(refYear - (options.max ?? 80) - 1);
max = new Date(refDate).setUTCFullYear(refYear - (options.min ?? 18));
Expand Down
1 change: 1 addition & 0 deletions src/modules/finance/iban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,7 @@ const iban: Iban = {
],
mod97: (digitStr) => {
let m = 0;

for (let i = 0; i < digitStr.length; i++) {
m = (m * 10 + +digitStr[i]) % 97;
}
Expand Down
Loading