Skip to content

Commit

Permalink
refactor(util): Fix lint warnings (#7114)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Aug 27, 2020
1 parent 0ae8cc2 commit 095f2f8
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/util/cache/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function get<T = any>(key: string): T {
return repoCache?.[key];
}

export function set(key: string, value: any): void {
export function set(key: string, value: unknown): void {
if (repoCache) {
repoCache[key] = value;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/cache/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function get<T = any>(namespace: string, key: string): Promise<T> {
export function set(
namespace: string,
key: string,
value: any,
value: unknown,
minutes: number
): Promise<void> {
if (!cacheProxy) {
Expand Down
4 changes: 2 additions & 2 deletions lib/util/exec/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function getContainerName(image: string): string {
return image.replace(/\//g, '_');
}

export async function removeDockerContainer(image): Promise<void> {
export async function removeDockerContainer(image: string): Promise<void> {
const containerName = getContainerName(image);
let cmd = `docker ps --filter name=${containerName} -aq`;
try {
Expand Down Expand Up @@ -208,7 +208,7 @@ export async function generateDockerCommand(
result.push(`-w "${cwd}"`);
}

let tag;
let tag: string;
if (options.tag) {
tag = options.tag;
} else if (tagConstraint) {
Expand Down
5 changes: 3 additions & 2 deletions lib/util/exec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ export async function exec(
logger.trace({ err }, 'rawExec err');
clearTimeout(timer);
if (useDocker) {
await removeDockerContainer(docker.image).catch((removeErr) => {
await removeDockerContainer(docker.image).catch((removeErr: Error) => {
const message: string = err.message;
throw new Error(
`Error: "${removeErr.message}" - Original Error: "${err.message}"`
`Error: "${removeErr.message}" - Original Error: "${message}"`
);
});
}
Expand Down
6 changes: 3 additions & 3 deletions lib/util/fs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ export async function deleteLocalFile(fileName: string): Promise<void> {
}

// istanbul ignore next
export async function ensureDir(dirName): Promise<void> {
export async function ensureDir(dirName: string): Promise<void> {
await fs.ensureDir(dirName);
}

// istanbul ignore next
export async function ensureLocalDir(dirName): Promise<void> {
export async function ensureLocalDir(dirName: string): Promise<void> {
const localDirName = join(localDir, dirName);
await fs.ensureDir(localDirName);
}

export async function ensureCacheDir(
dirName,
dirName: string,
envPathVar?: string
): Promise<string> {
const envCacheDirName = envPathVar ? process.env[envPathVar] : null;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/fs/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function writeFile(
// istanbul ignore next
export function outputFile(
file: string,
data: any,
data: unknown,
options?: WriteFileOptions | string
): Promise<void> {
return fs.outputFile(file, data, options ?? {});
Expand Down
2 changes: 1 addition & 1 deletion lib/util/http/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class GithubHttp extends Http<GithubHttpOptions, GithubHttpOptions> {

const { paginate = true } = options;
let count = options.count || 100;
let cursor = null;
let cursor: string = null;

let isIterating = true;
while (isIterating) {
Expand Down
2 changes: 1 addition & 1 deletion lib/util/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface HttpPostOptions extends HttpOptions {
}

export interface InternalHttpOptions extends HttpOptions {
json?: object;
json?: Record<string, unknown>;
responseType?: 'json';
method?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util/package-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function matchesRule(inputConfig: Config, packageRule: PackageRule): boolean {
: packagePattern
);
if (packageRegex.test(depName)) {
logger.trace(`${depName} matches against ${packageRegex}`);
logger.trace(`${depName} matches against ${String(packageRegex)}`);
isMatch = true;
}
}
Expand All @@ -171,7 +171,7 @@ function matchesRule(inputConfig: Config, packageRule: PackageRule): boolean {
pattern === '^*$' || pattern === '*' ? '.*' : pattern
);
if (packageRegex.test(depName)) {
logger.trace(`${depName} matches against ${packageRegex}`);
logger.trace(`${depName} matches against ${String(packageRegex)}`);
isMatch = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function regEx(pattern: string, flags?: string): RegExp {
} catch (err) {
const error = new Error(CONFIG_VALIDATION);
error.configFile = pattern;
error.validationError = 'Invalid regular expression: ' + err.toString();
error.validationError = `Invalid regular expression: ${pattern}`;
throw error;
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/util/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export const allowedFields = {
versions: 'An array of ChangeLogRelease objects in the upgrade',
};

function getFilteredObject(input: any): any {
type CompileInput = Record<string, unknown>;

function getFilteredObject(input: CompileInput): any {
const obj = clone(input);
const res = {};
const allAllowed = [
Expand All @@ -94,8 +96,10 @@ function getFilteredObject(input: any): any {
for (const field of allAllowed) {
const value = obj[field];
if (is.array(value)) {
res[field] = value.map((element) => getFilteredObject(element));
} else if (is.object(value)) {
res[field] = value.map((element) =>
getFilteredObject(element as CompileInput)
);
} else if (is.plainObject(value)) {
res[field] = getFilteredObject(value);
} else if (!is.undefined(value)) {
res[field] = value;
Expand All @@ -106,7 +110,7 @@ function getFilteredObject(input: any): any {

export function compile(
template: string,
input: any,
input: CompileInput,
filterFields = true
): string {
const filteredInput = filterFields ? getFilteredObject(input) : input;
Expand Down

0 comments on commit 095f2f8

Please sign in to comment.