refactor: Prevent default parameters for objects

This commit is contained in:
Joachim Van Herwegen 2023-10-30 17:09:04 +01:00
parent 98f5d8fb73
commit c2a84b6592
4 changed files with 10 additions and 11 deletions

View File

@ -238,6 +238,7 @@ const configs = antfu(
'unicorn/no-lonely-if': 'error', 'unicorn/no-lonely-if': 'error',
'unicorn/no-negated-condition': 'error', 'unicorn/no-negated-condition': 'error',
'unicorn/no-nested-ternary': 'error', 'unicorn/no-nested-ternary': 'error',
'unicorn/no-object-as-default-parameter': 'error',
'unicorn/no-process-exit': 'error', 'unicorn/no-process-exit': 'error',
'unicorn/no-thenable': 'error', 'unicorn/no-thenable': 'error',
'unicorn/no-useless-fallback-in-spread': 'error', 'unicorn/no-useless-fallback-in-spread': 'error',
@ -269,9 +270,6 @@ const configs = antfu(
'unicorn/require-array-join-separator': 'error', 'unicorn/require-array-join-separator': 'error',
'unicorn/require-number-to-fixed-digits-argument': 'error', 'unicorn/require-number-to-fixed-digits-argument': 'error',
// Might want to enable these
'unicorn/no-object-as-default-parameter': 'off',
'unused-imports/no-unused-vars': [ 'unused-imports/no-unused-vars': [
'error', 'error',
{ args: 'after-used', vars: 'all', ignoreRestSiblings: true }, { args: 'after-used', vars: 'all', ignoreRestSiblings: true },

View File

@ -38,9 +38,9 @@ export class BaseServerFactory implements HttpServerFactory {
private readonly configurator: ServerConfigurator; private readonly configurator: ServerConfigurator;
private readonly options: BaseServerFactoryOptions; private readonly options: BaseServerFactoryOptions;
public constructor(configurator: ServerConfigurator, options: BaseServerFactoryOptions = { https: false }) { public constructor(configurator: ServerConfigurator, options?: BaseServerFactoryOptions) {
this.configurator = configurator; this.configurator = configurator;
this.options = { ...options }; this.options = { https: false, ...options };
} }
/** /**

View File

@ -19,7 +19,7 @@ const PREFIX_LOCK = '__L__';
export interface RedisSettings { export interface RedisSettings {
/* Override default namespacePrefixes (used to prefix keys in Redis) */ /* Override default namespacePrefixes (used to prefix keys in Redis) */
namespacePrefix: string; namespacePrefix?: string;
/* Username used for AUTH on the Redis server */ /* Username used for AUTH on the Redis server */
username?: string; username?: string;
/* Password used for AUTH on the Redis server */ /* Password used for AUTH on the Redis server */
@ -74,12 +74,13 @@ export class RedisLocker implements ReadWriteLocker, ResourceLocker, Initializab
public constructor( public constructor(
redisClient = '127.0.0.1:6379', redisClient = '127.0.0.1:6379',
attemptSettings: AttemptSettings = {}, attemptSettings: AttemptSettings = {},
redisSettings: RedisSettings = { namespacePrefix: '' }, redisSettings?: RedisSettings,
) { ) {
redisSettings = { namespacePrefix: '', ...redisSettings };
const { namespacePrefix, ...options } = redisSettings; const { namespacePrefix, ...options } = redisSettings;
this.redis = this.createRedisClient(redisClient, options); this.redis = this.createRedisClient(redisClient, options);
this.attemptSettings = { ...attemptDefaults, ...attemptSettings }; this.attemptSettings = { ...attemptDefaults, ...attemptSettings };
this.namespacePrefix = namespacePrefix; this.namespacePrefix = namespacePrefix!;
// Register lua scripts // Register lua scripts
for (const [ name, script ] of Object.entries(REDIS_LUA_SCRIPTS)) { for (const [ name, script ] of Object.entries(REDIS_LUA_SCRIPTS)) {

View File

@ -23,10 +23,10 @@ export function getTemplateFilePath(template?: Template): string | undefined {
/** /**
* Reads the template and returns it as a string. * Reads the template and returns it as a string.
*/ */
export async function readTemplate(template: Template = { templateString: '' }): Promise<string> { export async function readTemplate(template?: Template): Promise<string> {
// The template has already been given as a string // The template has already been given as a string
if (typeof template === 'object' && 'templateString' in template) { if (typeof template === 'undefined' || (typeof template === 'object' && 'templateString' in template)) {
return template.templateString; return template?.templateString ?? '';
} }
// The template needs to be read from disk // The template needs to be read from disk
return fsPromises.readFile(getTemplateFilePath(template)!, 'utf8'); return fsPromises.readFile(getTemplateFilePath(template)!, 'utf8');