pslint v1.3.0
pslint
A collection of useful TSLint rules.
Rules
no-catch-expect: Prevent calling Jasmine'sexpectandexpectAsyncfunctions within acatchblock. If your tested code should throw an exception and you check that by callingexpectwithin acatchblock, then your test might incorrectly succeed if your tested code does not throw an exception. Using this rule forces you to move theexpectafter thecatchblock.no-empty-imports: Preventimportstatements from not importing any symbols.require-component-view-encapsulation: Require Angular components to declare view encapsulation. When using ahead-of-time compilation, you cannot override the default Emulated encapsulation option. If you want ShadowDom encapsulation you must remember to add this option to each component. This rule forces you to add a specific encapsulation option.
Prerequisites
This package is an extension of TSLint, therefore you must already have TSLint installed in your project. See https://github.com/palantir/tslint.
Usage
To consume these rules in your project, first install the module:
$ npm install --save-dev pslintThen add the rules' location and configurations to your tslint.json:
{
"rulesDirectory": [
"./node_modules/pslint"
],
"rules": {
"no-catch-expect": true,
"no-empty-imports": true,
"require-component-view-encapsulation": [true, "ShadowDom"]
}
}Note the peerDependencies in package.json.
Development
Build
pslint uses Gulp as its task runner. There's no need to install Gulp globally, since it appears in the package.json as a script. All Gulp tasks are written in TypeScript and you can find them in gulpfile.ts.
To fully build the project, use the default Gulp task:
$ npm run gulpTo run an individual task, for example, to transpile the TypeScript:
$ npm run gulp -- transpileTest
Each rule gets its own directory within test/rules. Name the directory the same as the rule file, except drop Rule from the end and convert camel case to kebab case. Example: noCatchExpectRule.ts → no-catch-expect. Each directory for rules-under-test needs test.ts.lint to contain the tests and tslint.json to configure TSLint. Test directories can contain arbitrary nesting of sub-test directories so long as each sub-directory has these two files. This is useful for testing multiple configurations of the same rule.
Run the tests:
$ npm run testDebug
To debug a rule, set a breakpoint using the debugger statement then run
$ npm run test-debugIn Chrome, navigate to chrome://inspect where you'll see the app listed as available for debugging.