Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Add "ban-types" to tslint:latest. #2271

Merged
merged 4 commits into from Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/configs/latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 4 additions & 11 deletions src/formatterLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}