-
This packgae requires
[email protected]or higher and[email protected] -
Add Following dependency in your project's
package.jsonfile and runnpm installgit+ssh://[email protected]/causecode/ts-rules.git#version- (e.g.
git+ssh://[email protected]/causecode/ts-rules.git#v0.0.1)
-
Add following in your project's
tslint.jsonfile."rulesDirectory": ["./node_modules/ts-rules/public"]
-
Add following custom rules to
rulesblock"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 forrequireand 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 [email protected]:causecode/ts-rules.git npm run install- Add new custom rules to
rulesdirectory. Guideline for developing rules - Add test cases to
testdirectory Guideline for developing test cases for tslint rules - Run
npm run testfor testing