diff --git a/src/configs/latest.ts b/src/configs/latest.ts index 0a10c824dec..9e8e743f687 100644 --- a/src/configs/latest.ts +++ b/src/configs/latest.ts @@ -52,6 +52,17 @@ export const rules = { "arrow-return-shorthand": true, "no-unnecessary-initializer": true, "no-misused-new": true, + + // added in v4.5 + "ban-types": [ + true, + ["Object", "Avoid using the `Object` type. Did you mean `object`?"], + ["Function", "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."], + ["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"], + ["Number", "Avoid using the `Number` type. Did you mean `number`?"], + ["String", "Avoid using the `String` type. Did you mean `string`?"], + ["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"], + ], }; // tslint:enable object-literal-sort-keys diff --git a/src/formatterLoader.ts b/src/formatterLoader.ts index 942f40f8db9..5da7a24d56e 100644 --- a/src/formatterLoader.ts +++ b/src/formatterLoader.ts @@ -17,23 +17,16 @@ import * as fs from "fs"; import * as path from "path"; +import {FormatterFunction} from "./index"; import {camelize} from "./utils"; const moduleDirectory = path.dirname(module.filename); const CORE_FORMATTERS_DIRECTORY = path.resolve(moduleDirectory, ".", "formatters"); -function isFunction(variable: any): variable is Function { - return typeof variable === "function"; -} - -function isString(variable: any): variable is string { - return typeof variable === "string"; -} - -export function findFormatter(name: string | Function, formattersDirectory?: string) { - if (isFunction(name)) { +export function findFormatter(name: string | FormatterFunction, formattersDirectory?: string) { + if (typeof name === "function") { return name; - } else if (isString(name)) { + } else if (typeof name === "string") { name = name.trim(); const camelizedName = camelize(`${name}Formatter`); diff --git a/src/index.ts b/src/index.ts index faf6ede9279..835ac72fc15 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,13 +38,15 @@ export interface LintResult { failureCount: number; failures: RuleFailure[]; fixes?: RuleFailure[]; - format: string | Function; + format: string | FormatterFunction; output: string; } +export type FormatterFunction = (failures: RuleFailure[]) => string; + export interface ILinterOptions { fix: boolean; - formatter?: string | Function; + formatter?: string | FormatterFunction; formattersDirectory?: string; rulesDirectory?: string | string[]; }