Skip to content

Commit

Permalink
Docs: Distinguish examples in rules under Stylistic Issues part 5 (es…
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptdaemon authored and pedrottimark committed Jun 2, 2016
1 parent 1313804 commit 89580a4
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 160 deletions.
10 changes: 5 additions & 5 deletions docs/rules/no-lonely-if.md
@@ -1,6 +1,6 @@
# Disallow `if` as the Only Statement in an `else` Block (no-lonely-if)
# disallow `if` statements as the only statement in `else` blocks (no-lonely-if)

If an `if` statement is the only statement in the `else` block of a parent `if` statement, it is often clearer to combine the two to using `else if` form.
If an `if` statement is the only statement in the `else` block, it is often clearer to use an `else if` form.

```js
if (foo) {
Expand All @@ -24,9 +24,9 @@ if (foo) {

## Rule Details

This rule warns when an `if` statement's `else` block contains only another `if` statement.
This rule disallows `if` statements as the only statement in `else` blocks.

The following patterns are considered problems:
Examples of **incorrect** code for this rule:

```js
/*eslint no-lonely-if: "error"*/
Expand All @@ -50,7 +50,7 @@ if (condition) {
}
```

The following patterns are not considered problems:
Examples of **correct** code for this rule:

```js
/*eslint no-lonely-if: "error"*/
Expand Down
30 changes: 13 additions & 17 deletions docs/rules/no-mixed-spaces-and-tabs.md
@@ -1,24 +1,12 @@
# Disallow mixed spaces and tabs for indentation (no-mixed-spaces-and-tabs)
# disallow mixed spaces and tabs for indentation (no-mixed-spaces-and-tabs)

Most code conventions require either tabs or spaces be used for indentation. As such, it's usually an error if a single line of code is indented with both tabs and spaces.

## Rule Details

The `no-mixed-spaces-and-tabs` rule is aimed at flagging any lines of code that are indented with a mixture of tabs and spaces.
This rule disallows mixed spaces and tabs for indentation.

## Options

### smart-tabs

This option suppresses warnings about mixed tabs and spaces when the latter are used for alignment only. This technique is called [SmartTabs](http://www.emacswiki.org/emacs/SmartTabs). The option is turned off by default.

You can enable this option by using the following configuration:

```json
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"]
```

The following patterns are considered problems:
Examples of **incorrect** code for this rule:

```js
/*eslint no-mixed-spaces-and-tabs: "error"*/
Expand All @@ -38,7 +26,7 @@ function main() {
}
```

The following patterns are not considered problems:
Examples of **correct** code for this rule:

```js
/*eslint no-mixed-spaces-and-tabs: "error"*/
Expand All @@ -49,7 +37,15 @@ function add(x, y) {
}
```

When the SmartTabs option is enabled the following does not produce a warning:
## Options

This rule has a string option.

* `"smart-tabs"` allows mixed spaces and tabs when the latter are used for alignment.

### smart-tabs

Examples of **correct** code for this rule with the `"smart-tabs"` option:

```js
/*eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/
Expand Down
66 changes: 18 additions & 48 deletions docs/rules/no-multiple-empty-lines.md
@@ -1,72 +1,50 @@
# Disallows multiple blank lines (no-multiple-empty-lines)
# disallow multiple empty lines (no-multiple-empty-lines)

Some developers prefer to have multiple blank lines removed, while others feel that it helps improve readability. Whitespace is useful for separating logical sections of code, but excess whitespace takes up more of the screen.


## Rule Details

This rule aims to reduce the scrolling required when reading through your code. It will warn when the maximum amount of empty lines has been exceeded.

## Options

The second argument can be used to configure this rule:
This rule has an object option:

* `max` sets the maximum number of consecutive blank lines.
* `maxEOF` can be used to set a different number for the end of file. The last
blank lines will then be treated differently. If omitted, the `max` option is
applied at the end of the file.
* `maxBOF` can be used to set a different number for the beginning of the file.
If omitted, the 'max' option is applied at the beginning of the file.
* `"max"` (default: `2`) enforces a maximum number of consecutive empty lines.
* `"maxEOF"` enforces a maximum number of consecutive empty lines at the end of files.
* `"maxBOF"` enforces a maximum number of consecutive empty lines at the beginning of files.

### max

In the following example, the `error` is the severity of the rule, and the
`max` property is the maximum number of empty lines (2 in this example).

```json
"no-multiple-empty-lines": ["error", {"max": 2}]
```

The following patterns are considered problems:
Examples of **incorrect** code for this rule with the default `{ "max": 2 }` option:

```js
/*eslint no-multiple-empty-lines: ["error", {max: 2}]*/

/*eslint no-multiple-empty-lines: "error"*/

var foo = 5;



var bar = 3;


```

The following patterns are not considered problems:
Examples of **correct** code for this rule with the default `{ "max": 2 }` option:

```js
/*eslint no-multiple-empty-lines: ["error", {max: 2}]*/

/*eslint no-multiple-empty-lines: "error"*/

var foo = 5;


var bar = 3;


```

### maxEOF

```json
"no-multiple-empty-lines": ["error", {"max": 2, "maxEOF": 1}]
```

The following patterns are considered problems:
Examples of **incorrect** code for this rule with the `{ max: 2, maxEOF: 1 }` options:

```js
/*eslint no-multiple-empty-lines: ["error", {max: 2, maxEOF: 1}]*/

/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 1 }]*/

var foo = 5;

Expand All @@ -76,11 +54,10 @@ var bar = 3;

```

The following patterns are not considered problems:
Examples of **correct** code for this rule with the `{ max: 2, maxEOF: 1 }` options:

```js
/*eslint no-multiple-empty-lines: ["error", {max: 2, maxEOF: 1}]*/

/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 1 }]*/

var foo = 5;

Expand All @@ -91,34 +68,27 @@ var bar = 3;

### maxBOF

```json
"no-multiple-empty-lines": ["error", {"max": 2, "maxBOF": 0}]
```

The following patterns are considered problems:
Examples of **incorrect** code for this rule with the `{ max: 2, maxBOF: 1 }` options:

```js
/*eslint no-multiple-empty-lines: ["error", {max: 2, maxBOF: 0}]*/
/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/


var foo = 5;


var bar = 3;


```

The following patterns are not considered problems:
Examples of **correct** code for this rule with the `{ max: 2, maxBOF: 1 }` options:

```js
/*eslint no-multiple-empty-lines: ["error", {max: 2, maxBOF: 0}]*/
/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/

var foo = 5;


var bar = 3;


```

## When Not To Use It
Expand Down
41 changes: 9 additions & 32 deletions docs/rules/no-negated-condition.md
@@ -1,34 +1,15 @@
# Disallow use of negated expressions in conditions (no-negated-condition)
# disallow negated conditions (no-negated-condition)

Checks against the use of a negated expression in an if condition when the else branch is not empty or in a ternary operator. Negated conditions are more difficult to understand. Code can be made more readable by inverting the condition instead.

For example:

```js
if (!a) {
doSomething();
}
else {
doSomethingElse();
}
```

should instead be written as:

```js
if (a) {
doSomethingElse();
}
else {
doSomething();
}
```
Negated conditions are more difficult to understand. Code can be made more readable by inverting the condition instead.

## Rule Details

The rule is aimed at preventing the use of a negated expression in a condition.
This rule disallows negated conditions in either of the following:

The following patterns are considered warnings:
* `if` statements which have an `else` branch
* ternary expressions

Examples of **incorrect** code for this rule:

```js
/*eslint no-negated-condition: "error"*/
Expand All @@ -51,13 +32,10 @@ if (a !== b) {
doSomethingElse();
}


!a ? b : c

!a ? c : b
```

The following patterns are not warnings:

Examples of **correct** code for this rule:

```js
/*eslint no-negated-condition: "error"*/
Expand All @@ -77,5 +55,4 @@ if (a != b) {
}

a ? b : c

```
12 changes: 7 additions & 5 deletions docs/rules/no-nested-ternary.md
@@ -1,16 +1,16 @@
# Disallow Nested Ternaries (no-nested-ternary)
# disallow nested ternary expressions (no-nested-ternary)

Nesting ternary expressions makes code unclear. The `no-nested-ternary` rule disallows the use of nested ternary expressions.
Nesting ternary expressions can make code more difficult to understand.

```js
var foo = bar ? baz : qux === quxx ? bing : bam;
```

## Rule Details

The `no-nested-ternary` rule aims to increase the clarity and readability of code by disallowing the use of nested ternary expressions.
The `no-nested-ternary` rule disallows nested ternary expressions.

The following patterns are considered problems:
Examples of **incorrect** code for this rule:

```js
/*eslint no-nested-ternary: "error"*/
Expand All @@ -20,11 +20,13 @@ var thing = foo ? bar : baz === qux ? quxx : foobar;
foo ? baz === qux ? quxx() : foobar() : bar();
```

The following patterns are considered okay and could be used alternatively:
Examples of **correct** code for this rule:

```js
/*eslint no-nested-ternary: "error"*/

var thing = foo ? bar : foobar;

var thing;

if (foo) {
Expand Down
8 changes: 4 additions & 4 deletions docs/rules/no-new-object.md
@@ -1,4 +1,4 @@
# Disallow the use of the Object constructor (no-new-object)
# disallow `Object` constructors (no-new-object)

The `Object` constructor is used to create new generic objects in JavaScript, such as:

Expand All @@ -18,9 +18,9 @@ While there are no performance differences between the two approaches, the byte

## Rule Details

This rule aims to eliminate use of the `Object` constructor. As such, it warns whenever `new Object` is found in code.
This rule disallows `Object` constructors.

The following patterns are considered problems:
Examples of **incorrect** code for this rule:

```js
/*eslint no-new-object: "error"*/
Expand All @@ -30,7 +30,7 @@ var myObject = new Object();
var myObject = new Object;
```

The following patterns are not considered problems:
Examples of **correct** code for this rule:

```js
/*eslint no-new-object: "error"*/
Expand Down

0 comments on commit 89580a4

Please sign in to comment.