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: turn on padding-line-between-statements #1691

Merged
merged 3 commits into from
Dec 31, 2022
Merged
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
27 changes: 14 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ module.exports = defineConfig({
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
format: ['PascalCase'],
selector: ['class', 'interface', 'typeAlias', 'enumMember'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
],
'@typescript-eslint/no-inferrable-types': [
'error',
{ ignoreParameters: true },
Expand All @@ -43,23 +52,15 @@ module.exports = defineConfig({
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/restrict-template-expressions': [
'@typescript-eslint/padding-line-between-statements': [
'error',
{
allowNumber: true,
allowBoolean: true,
},
{ blankLine: 'always', prev: 'block-like', next: '*' },
],
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/naming-convention': [
'@typescript-eslint/restrict-template-expressions': [
'error',
{
format: ['PascalCase'],
selector: ['class', 'interface', 'typeAlias', 'enumMember'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid',
},
{ allowNumber: true, allowBoolean: true },
],
'@typescript-eslint/unbound-method': 'off',
},
overrides: [
{
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/apiDocsWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function writeApiSearchIndex(project: ProjectReflection): void {
},
];
}

return apiSection;
})
.sort((a, b) => a.text.localeCompare(b.text));
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/moduleMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function extractModuleName(module: DeclarationReflection): string {
} else if (name === 'NameModule') {
return 'Person';
}

return name.replace(/Module$/, '');
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/apidoc/parameterDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function cleanParameterDefault(value?: string): string | undefined {
if (value == null) {
return undefined;
}

// Strip type casts: "'foobar' as unknown as T" => "'foobar'"
return value.replace(/ as unknown as [A-Za-z<>]+/, '');
}
Expand Down Expand Up @@ -124,6 +125,7 @@ function patchSignatureParameterDefaults(
if (signatureParameters.length !== parameterDefaults.length) {
throw new Error('Unexpected parameter length mismatch');
}

signatureParameters.forEach(
(param, index) =>
(param.defaultValue = parameterDefaults[index] || param.defaultValue)
Expand Down
10 changes: 10 additions & 0 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export function analyzeSignature(
if (signatureTypeParameters.length !== 0) {
signatureTypeParametersString = `<${signatureTypeParameters.join(', ')}>`;
}

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

let examples: string;
Expand All @@ -150,6 +151,7 @@ export function analyzeSignature(
} else {
examples = `faker.${methodName}${signatureTypeParametersString}(${signatureParametersString}): ${signature.type?.toString()}\n`;
}

faker.seed(0);
if (moduleName) {
try {
Expand Down Expand Up @@ -230,6 +232,7 @@ function analyzeParameterOptions(
if (!parameterType) {
return [];
}

if (parameterType.type === 'union') {
return parameterType.types.flatMap((type) =>
analyzeParameterOptions(name, type)
Expand Down Expand Up @@ -261,6 +264,7 @@ function typeToText(type_?: Type, short = false): string {
if (!type_) {
return '?';
}

const type = type_ as SomeType;
switch (type.type) {
case 'array':
Expand All @@ -283,6 +287,7 @@ function typeToText(type_?: Type, short = false): string {
.map((t) => typeToText(t, short))
.join(', ')}>`;
}

case 'reflection':
return declarationTypeToText(type.declaration, short);
case 'indexedAccess':
Expand Down Expand Up @@ -335,6 +340,7 @@ function signatureTypeToText(signature?: SignatureReflection): string {
if (!signature) {
return '(???) => ?';
}

return `(${signature.parameters
?.map((p) => `${p.name}: ${typeToText(p.type)}`)
.join(', ')}) => ${typeToText(signature.type)}`;
Expand All @@ -350,18 +356,22 @@ function extractDefaultFromComment(comment?: Comment): string | undefined {
if (!comment) {
return;
}

const summary = comment.summary;
const text = joinTagParts(summary).trim();
if (!text) {
return;
}

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

if (result[3].trim()) {
throw new Error(`Found description text after the default value:\n${text}`);
}

summary.splice(summary.length - 2, 2);
const lastSummaryPart = summary[summary.length - 1];
lastSummaryPart.text = lastSummaryPart.text.replace(/[ \n]Defaults to $/, '');
Expand Down
1 change: 1 addition & 0 deletions scripts/apidoc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function extractSeeAlsos(signature?: SignatureReflection): string[] {
if (link.startsWith('-')) {
link = link.slice(1).trim();
}

return link;
})
.filter((link) => link)
Expand Down
1 change: 1 addition & 0 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const target = ['ES2019', 'node14.17'];
if (existsSync(localeDir)) {
rmSync(localeDir, { recursive: true, force: true });
}

mkdirSync(localeDir);
for (const locale of Object.keys(locales)) {
writeFileSync(
Expand Down
3 changes: 3 additions & 0 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function removeIndexTs(files: string[]): string[] {
if (index !== -1) {
files.splice(index, 1);
}

return files;
}

Expand Down Expand Up @@ -152,6 +153,7 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
console.error(`Failed to load ${pathModules} or manually parse it.`, e);
}
}

return localeDef;
}

Expand All @@ -177,6 +179,7 @@ function generateLocalesIndexFile(
)}';`
);
}

content.push(
...modules.map((m) => `import ${escapeImport(m)} from './${m}';`)
);
Expand Down
2 changes: 2 additions & 0 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Faker {
`Locale ${locale} is not supported. You might want to add the requested locale first to \`faker.locales\`.`
);
}

this._locale = locale;
}

Expand All @@ -75,6 +76,7 @@ export class Faker {
`Locale ${localeFallback} is not supported. You might want to add the requested locale first to \`faker.locales\`.`
);
}

this._localeFallback = localeFallback;
}

Expand Down
4 changes: 4 additions & 0 deletions src/internal/mersenne/twister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default class MersenneTwister19937 {
sum = this.addition32(sum, this.unsigned32(n2 << i));
}
}

return sum;
}

Expand Down Expand Up @@ -194,10 +195,12 @@ export default class MersenneTwister19937 {
this.mt[0] = this.mt[this.N - 1];
i = 1;
}

if (j >= keyLength) {
j = 0;
}
}

for (k = this.N - 1; k; k--) {
// mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941)) - i
this.mt[i] = this.subtraction32(
Expand All @@ -218,6 +221,7 @@ export default class MersenneTwister19937 {
i = 1;
}
}

this.mt[0] = 0x80000000; // MSB is 1; assuring non-zero initial array
}

Expand Down
1 change: 1 addition & 0 deletions src/modules/animal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class AnimalModule {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}

this[name] = this[name].bind(this);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/modules/color/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ function formatHexColor(
hexColor = hexColor.toLowerCase();
break;
}

if (options?.prefix) {
hexColor = options.prefix + hexColor;
}

return hexColor;
}

Expand All @@ -78,6 +80,7 @@ function toBinary(values: number[]): string {
const bytes = new Uint8Array(buffer);
return toBinary(Array.from(bytes)).split(' ').join('');
}

return (value >>> 0).toString(2).padStart(8, '0');
});
return binary.join(' ');
Expand Down Expand Up @@ -161,6 +164,7 @@ export class ColorModule {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}

this[name] = this[name].bind(this);
}
}
Expand Down Expand Up @@ -320,11 +324,13 @@ export class ColorModule {
color = formatHexColor(color, options);
return color;
}

color = Array.from({ length: 3 }, () => this.faker.number.int(255));
if (includeAlpha) {
color.push(this.faker.number.float());
cssFunction = 'rgba';
}

return toColorFormat(color, format, cssFunction);
}

Expand Down Expand Up @@ -460,6 +466,7 @@ export class ColorModule {
for (let i = 0; i < (options?.includeAlpha ? 3 : 2); i++) {
hsl.push(this.faker.number.float());
}

return toColorFormat(
hsl,
options?.format || 'decimal',
Expand Down Expand Up @@ -537,6 +544,7 @@ export class ColorModule {
for (let i = 0; i < 2; i++) {
hsl.push(this.faker.number.float());
}

return toColorFormat(hsl, options?.format || 'decimal', 'hwb');
}

Expand Down Expand Up @@ -598,6 +606,7 @@ export class ColorModule {
this.faker.number.float({ min: -100, max: 100, precision: 0.0001 })
);
}

return toColorFormat(lab, options?.format || 'decimal', 'lab');
}

Expand Down Expand Up @@ -669,6 +678,7 @@ export class ColorModule {
for (let i = 0; i < 2; i++) {
lch.push(this.faker.number.float({ max: 230, precision: 0.1 }));
}

return toColorFormat(lch, options?.format || 'decimal', 'lch');
}

Expand Down Expand Up @@ -742,6 +752,7 @@ export class ColorModule {
if (options?.format === 'css' && !options?.space) {
options = { ...options, space: 'sRGB' };
}

const color = Array.from({ length: 3 }, () =>
this.faker.number.float({ precision: 0.0001 })
);
Expand Down
1 change: 1 addition & 0 deletions src/modules/commerce/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class CommerceModule {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}

this[name] = this[name].bind(this);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/company/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class CompanyModule {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}

this[name] = this[name].bind(this);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class DatabaseModule {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}

this[name] = this[name].bind(this);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/modules/datatype/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class DatatypeModule {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}

this[name] = this[name].bind(this);
}
}
Expand Down Expand Up @@ -211,14 +212,17 @@ export class DatatypeModule {
probability: options,
};
}

const { probability = 0.5 } = options;
if (probability <= 0) {
return false;
}

if (probability >= 1) {
// This check is required to avoid returning false when float() returns 1
return true;
}

return this.faker.number.float() < probability;
}

Expand Down
1 change: 1 addition & 0 deletions src/modules/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class DateModule {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}

this[name] = this[name].bind(this);
}
}
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 @@ -1401,6 +1401,7 @@ const iban: Iban = {
for (let i = 0; i < digitStr.length; i++) {
m = (m * 10 + +digitStr[i]) % 97;
}

return m;
},
pattern10: ['01', '02', '03', '04', '05', '06', '07', '08', '09'],
Expand Down
Loading