1.0.1 • Published 6 years ago

tslint-strict-null-checks v1.0.1

Weekly downloads
676
License
MIT
Repository
github
Last release
6 years ago

npm version Build Status Coverage Status

TsLint rules preventing undefined leaks in strictNullChecks mode

TypeScript (latest release 2.4.1) strictNullChecks is not reliable. It does not work as it should at least in two basic cases. It does not enforce initialization of varaiables and properties, so they will be undefined, even if undefined is not in the domian.

Code that (should not) compiles in strictNullChecks:

class X {
    public x: number;
}

let x: number;
function f(): number {
    return x;
}

let m: number = f();
let c: X = new X();
console.log(`m: ${m}`);
console.log(`c.x: ${c.x}`);

results in:

m: undefined
c.x: undefined

With ts-strict-null-checks You will be warned about not initialized variables and properties.

Installation

Install from npm to your devDependencies:

npm install --save-dev tslint-strict-null-checks

Configure tslint to use the tslint-strict-null-checks folder. Add the following path to the rulesDirectory setting in your tslint.json file:

{
   "rulesDirectory": [
     "node_modules/tslint-strict-null-checks/rules"
   ],
   "rules": {
     ...
   }
}

Usage

Rule: no-uninitialized

Enforces initialization of variables and properties, when undefined is not in their domain.

"no-uninitialized": [true, "variables", "properties"]

Support

If You find any gap where undefined can be smuggled please open an issue.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

1.0.1

6 years ago

1.0.0

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago