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

Commit

Permalink
Fix README to correctly show example of using tslint as library (#2043)
Browse files Browse the repository at this point in the history
Explicitly call `findConfiguration` before calling `lint` API so that `extends` key is resolved correctly.
  • Loading branch information
kratiahuja authored and nchen63 committed Jan 21, 2017
1 parent 8fbcf3e commit 176afbe
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,21 @@ tslint accepts the following command-line options:
#### Library

```js
import { Linter } from "tslint";
import { Linter, Configuration } from "tslint";
import * as fs from "fs";

const fileName = "Specify file name";
const configuration = {
rules: {
"variable-name": true,
"quotemark": [true, "double"]
}
};
const fileName = "Specify input file name";
const configurationFilename = "Specify configuration file name";
const options = {
formatter: "json",
configuration: configuration,
rulesDirectory: "customRules/",
formattersDirectory: "customFormatters/"
};

const fileContents = fs.readFileSync(fileName, "utf8");
const linter = new Linter(fileName, fileContents, options);
const result = linter.lint();
const linter = new Linter(options);
const configLoad = Configuration.findConfiguration(configurationFilename, filename);
const result = linter.lint(fileName, fileContents, configLoad.results);
```

#### Type Checking
Expand Down Expand Up @@ -315,10 +310,10 @@ TSLint ships with a set of core rules that can be configured. However, users are

Let us take the example of how to write a new rule to forbid all import statements (you know, *for science*). Let us name the rule file `noImportsRule.ts`. Rules are referenced in `tslint.json` with their kebab-cased identifer, so `"no-imports": true` would configure the rule.

__Important conventions__:
__Important conventions__:
* Rule identifiers are always kebab-cased.
* Rule files are always camel-cased (`camelCasedRule.ts`).
* Rule files *must* contain the suffix `Rule`.
* Rule files *must* contain the suffix `Rule`.
* The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`.

Now, let us first write the rule in TypeScript:
Expand Down

0 comments on commit 176afbe

Please sign in to comment.