Skip to content

pe8ter/pslint

Repository files navigation

pslint

A collection of useful TSLint rules.

Rules

  • no-catch-expect: Prevent calling Jasmine's expect and expectAsync functions within a catch block. If your tested code should throw an exception and you check that by calling expect within a catch block, then your test might incorrectly succeed if your tested code does not throw an exception. Using this rule forces you to move the expect after the catch block.
  • no-empty-imports: Prevent import statements 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 pslint

Then 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 gulp

To run an individual task, for example, to transpile the TypeScript:

$ npm run gulp -- transpile

Test

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.tsno-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 test

Debug

To debug a rule, set a breakpoint using the debugger statement then run

$ npm run test-debug

In Chrome, navigate to chrome://inspect where you'll see the app listed as available for debugging.

About

A collection of useful TSLint rules.

Resources

Stars

Watchers

Forks

Packages

No packages published