lint lib/config

Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
Raccoon 2021-06-13 16:12:40 +08:00
parent d19908d46f
commit e6b9ab099f
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
3 changed files with 13 additions and 9 deletions

View File

@ -9,7 +9,9 @@ function getSecret(secret) {
return undefined
}
let dockerSecretConfig: any = {}
// eslint-disable-next-line
let dockerSecretConfig: Record<string, any> = {}
if (fs.existsSync(basePath)) {
dockerSecretConfig = {
dbURL: getSecret('dburl'),

View File

@ -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

View File

@ -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