0

I want to run tslint fix in a script on a string. I imagine something like this:

import { fixer } from 'tslint'

const stringToFormatAndFix = // some typescript file content

const formatted = fixer(tslintJson, 'file/path/to/tslint.json')

Background: I'm using tsquery to find the last PropertySignature of an Interface and append a string to it. Afterwards I want to autoformat that file based on the tslint.json. Because I am using angular schematics and all changes are made in a virtual file system, I can't just run tslint via its cli.

snd
  • 131
  • 1
  • 6
  • 1
    You should probably look at the function `doLinting`: https://github.com/palantir/tslint/blob/e493270e314541e2f14b35bddbe9b74ea50cbfa9/src/runner.ts#L221 as well as `Linter.lint`: https://github.com/palantir/tslint/blob/e493270e314541e2f14b35bddbe9b74ea50cbfa9/src/linter.ts#L133 Edit: [this page](https://palantir.github.io/tslint/usage/library/) shows some usage of `Linter.prototype.lint` – Chris Yungmann Oct 17 '19 at 16:30
  • Thank you @ChrisYungmann This looks exactly like what I need. Well I'm a bit embarrassed because I did not see the sub navigation when I was visiting the site the other day ^^ – snd Oct 18 '19 at 05:43
  • I tried it and it works kind of. Tslint always wants to write to some file ^^ Well I could point it to a tmp file but this is a bit hacky – snd Oct 19 '19 at 20:05

0 Answers0