From e6b9ab099f8eab4f384fde02d6274aced192e642 Mon Sep 17 00:00:00 2001 From: Raccoon Date: Sun, 13 Jun 2021 16:12:40 +0800 Subject: [PATCH] lint lib/config Signed-off-by: Raccoon --- lib/config/dockerSecret.ts | 4 +++- lib/config/index.ts | 4 +++- lib/config/utils.ts | 14 +++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/config/dockerSecret.ts b/lib/config/dockerSecret.ts index 593fe7a2..ee442761 100644 --- a/lib/config/dockerSecret.ts +++ b/lib/config/dockerSecret.ts @@ -9,7 +9,9 @@ function getSecret(secret) { return undefined } -let dockerSecretConfig: any = {} +// eslint-disable-next-line +let dockerSecretConfig: Record = {} + if (fs.existsSync(basePath)) { dockerSecretConfig = { dbURL: getSecret('dburl'), diff --git a/lib/config/index.ts b/lib/config/index.ts index 53b3ef28..460d5f11 100644 --- a/lib/config/index.ts +++ b/lib/config/index.ts @@ -34,7 +34,7 @@ const configFilePath = path.resolve(appRootPath, process.env.CMD_CONFIG_FILE || // eslint-disable-next-line @typescript-eslint/no-var-requires const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] : undefined -// eslint-disable-next-line @typescript-eslint/no-var-requires +// eslint-disable-next-line let config: any = require('./default') // eslint-disable-next-line @typescript-eslint/no-var-requires merge(config, require('./defaultSSL')) @@ -214,7 +214,9 @@ config.defaultNotePath = path.resolve(appRootPath, config.defaultNotePath) config.docsPath = path.resolve(appRootPath, config.docsPath) config.uploadsPath = path.resolve(appRootPath, config.uploadsPath) config.env = env + // make config readonly +// eslint-disable-next-line config = deepFreeze(config) as any export = config diff --git a/lib/config/utils.ts b/lib/config/utils.ts index 20d8dcf8..e026b1fb 100644 --- a/lib/config/utils.ts +++ b/lib/config/utils.ts @@ -1,28 +1,28 @@ import * as fs from "fs"; import * as path from "path"; -export function toBooleanConfig(configValue) { +export function toBooleanConfig(configValue: string | boolean): boolean { if (configValue && typeof configValue === 'string') { return (configValue === 'true') } - return configValue + return configValue as boolean } -export function toArrayConfig(configValue, separator = ',', fallback ?: any) { +export function toArrayConfig(configValue: string | [], separator = ',', fallback ?: string[]): string[] { if (configValue && typeof configValue === 'string') { return (configValue.split(separator).map(arrayItem => arrayItem.trim())) } return fallback } -export function toIntegerConfig(configValue) { +export function toIntegerConfig(configValue: string | number): number { if (configValue && typeof configValue === 'string') { return parseInt(configValue) } - return configValue + return configValue as number } -export function getGitCommit(repodir) { +export function getGitCommit(repodir: string): string { if (!fs.existsSync(repodir + '/.git/HEAD')) { return undefined } @@ -35,7 +35,7 @@ export function getGitCommit(repodir) { return reference } -export function getGitHubURL(repo, reference) { +export function getGitHubURL(repo: string, reference: string): string { // if it's not a github reference, we handle handle that anyway if (!repo.startsWith('https://github.com') && !repo.startsWith('git@github.com')) { return repo