Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/typescript-eslint/typescr…
…ipt-eslint into feature/635-add-readonlyArray-option
- Loading branch information
Showing
26 changed files
with
1,672 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/eslint-plugin/docs/rules/strict-boolean-expressions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Boolean expressions are limited to booleans (strict-boolean-expressions) | ||
|
||
Requires that any boolean expression is limited to true booleans rather than | ||
casting another primitive to a boolean at runtime. | ||
|
||
It is useful to be explicit, for example, if you were trying to check if a | ||
number was defined. Doing `if (number)` would evaluate to `false` if `number` | ||
was defined and `0`. This rule forces these expressions to be explicit and to | ||
strictly use booleans. | ||
|
||
The following nodes are checked: | ||
|
||
- Arguments to the `!`, `&&`, and `||` operators | ||
- The condition in a conditional expression `(cond ? x : y)` | ||
- Conditions for `if`, `for`, `while`, and `do-while` statements. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```ts | ||
const number = 0; | ||
if (number) { | ||
return; | ||
} | ||
|
||
let foo = bar || 'foobar'; | ||
|
||
let undefinedItem; | ||
let foo = undefinedItem ? 'foo' : 'bar'; | ||
|
||
let str = 'foo'; | ||
while (str) { | ||
break; | ||
} | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```ts | ||
const number = 0; | ||
if (typeof number !== 'undefined') { | ||
return; | ||
} | ||
|
||
let foo = typeof bar !== 'undefined' ? bar : 'foobar'; | ||
|
||
let undefinedItem; | ||
let foo = typeof undefinedItem !== 'undefined' ? 'foo' : 'bar'; | ||
|
||
let str = 'foo'; | ||
while (typeof str !== 'undefined') { | ||
break; | ||
} | ||
``` | ||
|
||
## Related To | ||
|
||
- TSLint: [strict-boolean-expressions](https://palantir.github.io/tslint/rules/strict-boolean-expressions) |
58 changes: 58 additions & 0 deletions
58
packages/eslint-plugin/docs/rules/triple-slash-reference.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Sets preference level for triple slash directives versus ES6-style import declarations. (triple-slash-reference) | ||
|
||
Use of triple-slash reference type directives is discouraged in favor of the newer `import` style. This rule allows you to ban use of `/// <reference path="" />`, `/// <reference types="" />`, or `/// <reference lib="" />` directives. | ||
|
||
Consider using this rule in place of [`no-triple-slash-reference`](./no-triple-slash-reference.md) which has been deprecated. | ||
|
||
## Rule Details | ||
|
||
With `{ "path": "never", "types": "never", "lib": "never" }` options set, the following will all be **incorrect** usage: | ||
|
||
```ts | ||
/// <reference path="foo" /> | ||
/// <reference types="bar" /> | ||
/// <reference lib="baz" /> | ||
``` | ||
|
||
Examples of **incorrect** code for the `{ "types": "prefer-import" }` option. Note that these are only errors when **both** stlyes are used for the **same** module: | ||
|
||
```ts | ||
/// <reference types="foo" /> | ||
import * as foo from 'foo'; | ||
``` | ||
|
||
```ts | ||
/// <reference types="foo" /> | ||
import foo = require('foo'); | ||
``` | ||
|
||
With `{ "path": "always", "types": "always", "lib": "always" }` options set, the following will all be **correct** usage: | ||
|
||
```ts | ||
/// <reference path="foo" /> | ||
/// <reference types="bar" /> | ||
/// <reference lib="baz" /> | ||
``` | ||
|
||
Examples of **correct** code for the `{ "types": "prefer-import" }` option: | ||
|
||
```ts | ||
import * as foo from 'foo'; | ||
``` | ||
|
||
```ts | ||
import foo = require('foo'); | ||
``` | ||
|
||
## When To Use It | ||
|
||
If you want to ban use of one or all of the triple slash reference directives, or any time you might use triple-slash type reference directives and ES6 import declarations in the same file. | ||
|
||
## When Not To Use It | ||
|
||
If you want to use all flavors of triple slash reference directives. | ||
|
||
## Compatibility | ||
|
||
- TSLint: [no-reference](http://palantir.github.io/tslint/rules/no-reference/) | ||
- TSLint: [no-reference-import](https://palantir.github.io/tslint/rules/no-reference-import/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.