{"action":"created","issue":{"url":"https://api.github.com/repos/palantir/tslint/issues/1427","repository_url":"https://api.github.com/repos/palantir/tslint","labels_url":"https://api.github.com/repos/palantir/tslint/issues/1427/labels{/name}","comments_url":"https://api.github.com/repos/palantir/tslint/issues/1427/comments","events_url":"https://api.github.com/repos/palantir/tslint/issues/1427/events","html_url":"https://github.com/palantir/tslint/issues/1427","id":167320836,"number":1427,"title":"Wrong Options \"formatter\" type?","user":{"login":"GiedriusGrabauskas","id":5236988,"avatar_url":"https://avatars.githubusercontent.com/u/5236988?v=3","gravatar_id":"","url":"https://api.github.com/users/GiedriusGrabauskas","html_url":"https://github.com/GiedriusGrabauskas","followers_url":"https://api.github.com/users/GiedriusGrabauskas/followers","following_url":"https://api.github.com/users/GiedriusGrabauskas/following{/other_user}","gists_url":"https://api.github.com/users/GiedriusGrabauskas/gists{/gist_id}","starred_url":"https://api.github.com/users/GiedriusGrabauskas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GiedriusGrabauskas/subscriptions","organizations_url":"https://api.github.com/users/GiedriusGrabauskas/orgs","repos_url":"https://api.github.com/users/GiedriusGrabauskas/repos","events_url":"https://api.github.com/users/GiedriusGrabauskas/events{/privacy}","received_events_url":"https://api.github.com/users/GiedriusGrabauskas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-25T09:14:58Z","updated_at":"2016-07-28T16:48:08Z","closed_at":null,"body":"### Bug Report\r\n\r\n- __TSLint version__: `3.13.0`\r\n- __TypeScript version__: `1.8.10`\r\n- __Running TSLint via__: Node.js API\r\n\r\n`ILinterOptionsRaw` and `ILinterOptions` param `formatter` accept only `string`. But in code, it's possible to use `Function`.\r\n\r\n#### Usage sample:\r\n```ts\r\nimport * as Lint from \"tslint/lib/lint\";\r\nimport tslint from \"gulp-tslint\";\r\n\r\n// Custom formatter class\r\nexport class Formatter extends Lint.Formatters.AbstractFormatter {\r\n    public format(failures: Lint.RuleFailure[]): string {\r\n        var failuresJSON = failures.map((failure: Lint.RuleFailure) => failure.toJson());\r\n        return JSON.stringify(failuresJSON);\r\n    }\r\n}\r\n\r\n\r\ngulp.task(\"tslint\", () =>\r\n    gulp.src(\"source.ts\")\r\n        .pipe(tslint({\r\n            formatter: Formatter  // Custom formatter\r\n        }))\r\n        .pipe(tslint.report())\r\n);\r\n```\r\nP.S. I using `gulp-tslint`, but param `options` is the same.\r\n\r\n#### `tslint` code:\r\n* `lint` function take `formatter` from options: https://github.com/palantir/tslint/blob/master/src/tslint.ts#L123\r\n\r\n* Calling function `findFormatter` and return same function:\r\nhttps://github.com/palantir/tslint/blob/master/src/formatterLoader.ts#L27\r\n\r\n* Creating `formatter` instance:\r\nhttps://github.com/palantir/tslint/blob/master/src/tslint.ts#L125\r\n\r\n\r\n\r\n* But interface accept only `string`:\r\nhttps://github.com/palantir/tslint/blob/master/src/lint.ts#L51\r\nhttps://github.com/palantir/tslint/blob/master/src/lint.ts#L58\r\n"},"comment":{"url":"https://api.github.com/repos/palantir/tslint/issues/comments/235954435","html_url":"https://github.com/palantir/tslint/issues/1427#issuecomment-235954435","issue_url":"https://api.github.com/repos/palantir/tslint/issues/1427","id":235954435,"user":{"login":"DovydasNavickas","id":7989797,"avatar_url":"https://avatars.githubusercontent.com/u/7989797?v=3","gravatar_id":"","url":"https://api.github.com/users/DovydasNavickas","html_url":"https://github.com/DovydasNavickas","followers_url":"https://api.github.com/users/DovydasNavickas/followers","following_url":"https://api.github.com/users/DovydasNavickas/following{/other_user}","gists_url":"https://api.github.com/users/DovydasNavickas/gists{/gist_id}","starred_url":"https://api.github.com/users/DovydasNavickas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DovydasNavickas/subscriptions","organizations_url":"https://api.github.com/users/DovydasNavickas/orgs","repos_url":"https://api.github.com/users/DovydasNavickas/repos","events_url":"https://api.github.com/users/DovydasNavickas/events{/privacy}","received_events_url":"https://api.github.com/users/DovydasNavickas/received_events","type":"User","site_admin":false},"created_at":"2016-07-28T16:48:08Z","updated_at":"2016-07-28T16:48:08Z","body":"I've updated `findFormatter` method definition here:\r\nhttps://github.com/palantir/tslint/blob/master/src/formatterLoader.ts#L25\r\nPR: https://github.com/palantir/tslint/pull/1443\r\n\r\nAs @GiedriusGrabauskas stated, this code [here](https://github.com/palantir/tslint/blob/master/src/formatterLoader.ts#L27):\r\n```TypeScript\r\nexport function findFormatter(name: string, formattersDirectory?: string) {\r\n    if (typeof name === \"function\") {\r\n        return name;\r\n    }\r\n    <...>\r\n}\r\n```\r\naccepts the function and returns it immediately instead of looking for formatter by name, but the parameter type is constrained to string only.\r\n\r\nIt should accept a `Function` in addition to string as so:\r\n```TypeScript\r\nexport function findFormatter(name: string | Function, formattersDirectory?: string)\r\n```\r\n\r\nFor now it was not possible to pass custom formatter function (class) properly (except by casting the class to a `<string>` explicitly, which is a hacky way)."}}
{"actor":{"display_login":"DovydasNavickas"}}