Skip to content

Commit

Permalink
Enable noImplicitAny ts setting for cli, common and validator
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Sep 27, 2021
1 parent af8e603 commit 785770c
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/controller/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface ProcessedField {
isJsonInterface: boolean;
}

export async function generateJsonInterfaces(projectPath, schema: string) {
export async function generateJsonInterfaces(projectPath: string, schema: string) {
const typesDir = path.join(projectPath, TYPE_ROOT_DIR);
const jsonObjects = getAllJsonObjects(schema);
const jsonInterfaces = jsonObjects.map((r) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/controller/init-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import path from 'path';
import {createProject} from './init-controller';

// async
const fileExists = async (file) => {
return new Promise((resolve, reject) => {
const fileExists = async (file: string): Promise<boolean> => {
return new Promise<boolean>((resolve, reject) => {
fs.access(file, fs.constants.F_OK, (err) => {
err ? reject(err) : resolve(true);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"importHelpers": true,
"rootDir": "src",
"tsBuildInfoFile": "lib/.tsbuildinfo",
"outDir": "lib"
"outDir": "lib",
"noImplicitAny": true
},
"references": [
{"path": "../common"},
Expand Down
16 changes: 16 additions & 0 deletions packages/common/src/logger/colors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2020-2021 OnFinality Limited authors & contributors
// SPDX-License-Identifier: Apache-2.0

import {colorizeLevel} from './colors';

describe('LoggerColorLevel', () => {
it('returns default for an unsupported level number', () => {
const level = colorizeLevel(5);
expect(level).toBe('\x1b[37mUSERLVL\x1b[39m');
});

it('returns the correct level for a level number', () => {
const level = colorizeLevel(60);
expect(level).toBe('\x1b[41mFATAL\x1b[49m');
});
});
14 changes: 8 additions & 6 deletions packages/common/src/logger/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chalk from 'chalk';
import {LEVELS} from './constants';

export const ctx = new chalk.Instance({level: 3});
const colored = {
const colored: Record<keyof typeof LEVELS | 'message', chalk.Chalk> = {
default: ctx.white,
60: ctx.bgRed,
50: ctx.red,
Expand All @@ -16,11 +16,13 @@ const colored = {
message: ctx.cyan,
};

export function colorizeLevel(level: number) {
if (Number.isInteger(+level)) {
return Object.prototype.hasOwnProperty.call(LEVELS, level)
? colored[level](LEVELS[level])
: colored.default(LEVELS.default);
function isColouredValue(level: number | string): level is keyof typeof LEVELS {
return Number.isInteger(+level) && level in colored;
}

export function colorizeLevel(level: number): string {
if (isColouredValue(level) && Object.prototype.hasOwnProperty.call(LEVELS, level)) {
return colored[level](LEVELS[level]);
}
return colored.default(LEVELS.default);
}
4 changes: 2 additions & 2 deletions packages/common/src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Logger {
}
: {},
prettyPrint: outputFormat !== 'json',
prettifier: function (options) {
prettifier: function (options: unknown) {
// `this` is bound to the pino instance
// Deal with whatever options are supplied.
return function prettifier(inputData: string | object) {
Expand All @@ -68,7 +68,7 @@ export class Logger {
return `${time} <${ctx.magentaBright(category)}> ${colorizeLevel(level)} ${message} ${error}\n`;
};

function isObject(input) {
function isObject(input: unknown): boolean {
return Object.prototype.toString.apply(input) === '[object Object]';
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/logger/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import {LevelWithSilent} from 'pino';
import {LEVELS_MAP} from './constants';

export function levelFilter(test: LevelWithSilent, target: LevelWithSilent): boolean {
return LEVELS_MAP[test?.toLowerCase()] >= LEVELS_MAP[target.toLowerCase()];
return LEVELS_MAP[<LevelWithSilent>test?.toLowerCase()] >= LEVELS_MAP[<LevelWithSilent>target.toLowerCase()];
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const SUPPORTED_VERSIONS = {
'0.0.2': ProjectManifestV0_0_2Impl,
};

type ProjectManifestImpls = InstanceType<typeof SUPPORTED_VERSIONS[keyof typeof SUPPORTED_VERSIONS]>;
type Versions = keyof typeof SUPPORTED_VERSIONS;

type ProjectManifestImpls = InstanceType<typeof SUPPORTED_VERSIONS[Versions]>;

export function manifestIsV0_0_1(manifest: IProjectManifest): manifest is ProjectManifestV0_0_1Impl {
return manifest.specVersion === '0.0.1';
Expand All @@ -28,11 +30,11 @@ export class ProjectManifestVersioned implements IProjectManifest {
private _impl: ProjectManifestImpls;

constructor(projectManifest: VersionedProjectManifest) {
const klass = SUPPORTED_VERSIONS[projectManifest.specVersion];
const klass = SUPPORTED_VERSIONS[projectManifest.specVersion as Versions];
if (!klass) {
throw new Error('specVersion not supported for project manifest file');
}
this._impl = plainToClass(klass, projectManifest);
this._impl = plainToClass<ProjectManifestImpls, VersionedProjectManifest>(klass, projectManifest);
}

get asImpl(): IProjectManifest {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"rootDir": "src",
"tsBuildInfoFile": "dist/.tsbuildinfo",
"outDir": "dist"
"outDir": "dist",
"noImplicitAny": true,
},
"include": ["src/**/*"]
}
3 changes: 2 additions & 1 deletion packages/validator/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"tsBuildInfoFile": "dist/.tsbuildinfo",
"rootDir": "src",
"outDir": "dist"
"outDir": "dist",
"noImplicitAny": true
},
"include": ["src/**/*"],
"references": [
Expand Down

0 comments on commit 785770c

Please sign in to comment.