-
This packgae requires
tslint@5.1.0
or higher andtypescript@2.2.2
-
Add Following dependency in your project's
package.json
file and runnpm install
git+ssh://git@github.com/causecode/ts-rules.git#version
- (e.g.
git+ssh://git@github.com/causecode/ts-rules.git#v0.0.1
)
-
Add following in your project's
tslint.json
file."rulesDirectory": ["./node_modules/ts-rules/public"]
-
Add following custom rules to
rules
block"new-line-indent": [true,"spaces", 4, 2], "no-index-import": true, "no-import-spaces": true, "empty-line-before-return": true, "no-anchor-href": { "severity": "warning" }, "model-resource-name": true
- for e.g. your tslint.json will look something like this.
{ "rulesDirectory": ["./node_modules/ts-rules/public"], "rules": { "new-line-indent": [true,"spaces", 4, 2], "no-index-import": true, "no-import-spaces": true, "empty-line-before-return": true, "no-anchor-href": { "severity": "warning" }, "model-resource-name": true } }
-
Now when you run
npm run lint-ts
(it is assumed that this command is preconfigured in your project), it will show appropriate error/warning along with line no. -
If you get this
error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type '{ <T>(path: string): T; (paths: string[], callback: (...modules: any[]) => void): void; ensure: (...', but here has type 'NodeRequire'
compile time error, then check you project'sambientInterfaces.d.ts
, remove existing type declaration forrequire
and then add following type forrequire
.
declare interface NodeRequire {
<T>(path: string): T;
(paths: string[], callback: (...modules: any[]) => void): void;
ensure: (paths: string[], callback: (require: <T>(path: string) => T) => void) => void;
}
declare var require: NodeRequire;
- Clone the repo
git clone git@github.com:causecode/ts-rules.git
npm run install
- Add new custom rules to
rules
directory. Guideline for developing rules - Add test cases to
test
directory Guideline for developing test cases for tslint rules - Run
npm run test
for testing