Skip to content

Commit

Permalink
Merge pull request palantir#693 from palantir/fix-typings
Browse files Browse the repository at this point in the history
Fix typing bug and make Readme clearer
  • Loading branch information
adidahiya committed Sep 28, 2015
2 parents b7e1273 + 0d06332 commit c37443a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ TSLint ships with a set of core rules that can be configured. However, users are

Rule names are always camel-cased and *must* contain the suffix `Rule`. 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 can be referenced in `tslint.json` in their dasherized forms, so `"no-imports": true` would turn on the rule.

Now, let us first write the rule in TypeScript. At the top, we reference TSLint's [definition](https://github.com/palantir/tslint/blob/master/lib/tslint.d.ts) file. The exported class name must always be named `Rule` and extend from `Lint.Rules.AbstractRule`.
Now, let us first write the rule in TypeScript. At the top, we reference TSLint's [definition file](https://github.com/palantir/tslint/blob/master/lib/tslint.d.ts) and the [definition file](https://github.com/palantir/tslint/blob/master/typings/typescriptServices.d.ts) for TypeScript's language services. The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`.

```typescript
/// <reference path='tslint.d.ts' />
/// <reference path='typings/typescriptServices.d.ts' />
/// <reference path='lib/tslint.d.ts' />

export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "import statement forbidden";
Expand Down Expand Up @@ -316,7 +317,7 @@ Custom Formatters
Just like rules, additional formatters can also be supplied to TSLint via `--formatters-dir` on the CLI or `formattersDirectory` option on the library or `grunt-tslint`. Writing a new formatter is simpler than writing a new rule, as shown in the JSON formatter's code.

```javascript
/// <reference path='tslint.d.ts' />
/// <reference path='lib/tslint.d.ts' />

export class Formatter extends Lint.Formatters.AbstractFormatter {
public format(failures: Lint.RuleFailure[]): string {
Expand Down
3 changes: 2 additions & 1 deletion lib/tslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,6 @@ declare module Lint {
}
}
declare module "tslint" {
export = Lint;
import Linter = Lint.Linter;
export = Linter;
}
3 changes: 2 additions & 1 deletion src/tslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@ module.exports = Lint.Linter;
module.exports.findConfiguration = Lint.Configuration.findConfiguration;

declare module "tslint" {
export = Lint;
import Linter = Lint.Linter;
export = Linter;
}

0 comments on commit c37443a

Please sign in to comment.