Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
Autogenerated new docs and demo at Fri May 27 2016 12:00:27
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed May 27, 2016
1 parent 509994b commit 5357e63
Show file tree
Hide file tree
Showing 18 changed files with 1,686 additions and 761 deletions.
74 changes: 74 additions & 0 deletions _posts/2016-05-27-eslint-v2.11.0-released.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
layout: post
title: ESLint v2.11.0 released
tags:
- release
- minor
---
# ESLint v2.11.0 released

We just pushed ESLint v2.11.0, which is a minor release upgrade of ESLint. This release adds some new features and fixes several bugs found in the previous release.






## Features


* [fea8fe6](https://github.com/eslint/eslint/commit/fea8fe6) New: no-useless-rename (fixes [#6058](https://github.com/eslint/eslint/issues/6058)) ([#6249](https://github.com/eslint/eslint/issues/6249)) (Kai Cataldo)
* [088bda9](https://github.com/eslint/eslint/commit/088bda9) New: `unicode-bom` rule to allow or disallow BOM (fixes [#5502](https://github.com/eslint/eslint/issues/5502)) ([#6230](https://github.com/eslint/eslint/issues/6230)) (Andrew Johnston)
* [04bd586](https://github.com/eslint/eslint/commit/04bd586) New: Disallow use of Object.prototype methods on objects (fixes [#2693](https://github.com/eslint/eslint/issues/2693)) ([#6107](https://github.com/eslint/eslint/issues/6107)) (Andrew Levine)




## Enhancements


* [74c458d](https://github.com/eslint/eslint/commit/74c458d) Update: key-spacing rule whitespace fixer (fixes [#6167](https://github.com/eslint/eslint/issues/6167)) ([#6169](https://github.com/eslint/eslint/issues/6169)) (Ruurd Moelker)
* [53754ec](https://github.com/eslint/eslint/commit/53754ec) Update: max in `max-statements-per-line` should be >=0 (fixes [#6171](https://github.com/eslint/eslint/issues/6171)) ([#6172](https://github.com/eslint/eslint/issues/6172)) (alberto)
* [54d1201](https://github.com/eslint/eslint/commit/54d1201) Update: Add treatUndefinedAsUnspecified option (fixes [#6026](https://github.com/eslint/eslint/issues/6026)) ([#6194](https://github.com/eslint/eslint/issues/6194)) (Kenneth Williams)
* [18152dd](https://github.com/eslint/eslint/commit/18152dd) Update: Add checkLoops option to no-constant-condition (fixes [#5477](https://github.com/eslint/eslint/issues/5477)) ([#6202](https://github.com/eslint/eslint/issues/6202)) (Kai Cataldo)




## Bug Fixes


* [77dd2b4](https://github.com/eslint/eslint/commit/77dd2b4) Fix: On --init, print message when package.json is invalid (fixes [#6257](https://github.com/eslint/eslint/issues/6257)) ([#6261](https://github.com/eslint/eslint/issues/6261)) (Kai Cataldo)
* [7f60186](https://github.com/eslint/eslint/commit/7f60186) Fix: `--ignore-pattern` can't uningnore files (fixes [#6127](https://github.com/eslint/eslint/issues/6127)) ([#6253](https://github.com/eslint/eslint/issues/6253)) (alberto)
* [b4cff9d](https://github.com/eslint/eslint/commit/b4cff9d) Fix: Incorrect object-property-newline behavior (fixes [#6207](https://github.com/eslint/eslint/issues/6207)) ([#6213](https://github.com/eslint/eslint/issues/6213)) (Rafał Ruciński)
* [ee0cd58](https://github.com/eslint/eslint/commit/ee0cd58) Fix: `newline-before-return` shouldn't disallow newlines (fixes [#6176](https://github.com/eslint/eslint/issues/6176)) ([#6217](https://github.com/eslint/eslint/issues/6217)) (alberto)
* [d4f5526](https://github.com/eslint/eslint/commit/d4f5526) Fix: `vars-on-top` crashs at export declarations (fixes [#6210](https://github.com/eslint/eslint/issues/6210)) ([#6220](https://github.com/eslint/eslint/issues/6220)) (Toru Nagashima)
* [14bfc03](https://github.com/eslint/eslint/commit/14bfc03) Fix: `comma-dangle` wrong autofix (fixes [#6233](https://github.com/eslint/eslint/issues/6233)) ([#6235](https://github.com/eslint/eslint/issues/6235)) (Toru Nagashima)
* [c10c07f](https://github.com/eslint/eslint/commit/c10c07f) Fix: lost code in autofixing (refs [#6233](https://github.com/eslint/eslint/issues/6233)) ([#6234](https://github.com/eslint/eslint/issues/6234)) (Toru Nagashima)
* [7644908](https://github.com/eslint/eslint/commit/7644908) Fix: no-multiple-empty-lines BOF and EOF defaults (fixes [#6179](https://github.com/eslint/eslint/issues/6179)) ([#6180](https://github.com/eslint/eslint/issues/6180)) (Ruurd Moelker)
* [72335eb](https://github.com/eslint/eslint/commit/72335eb) Fix: `max-statements-per-line` false positive (fixes [#6173](https://github.com/eslint/eslint/issues/6173), fixes [#6153](https://github.com/eslint/eslint/issues/6153)) ([#6192](https://github.com/eslint/eslint/issues/6192)) (Toru Nagashima)
* [9fce04e](https://github.com/eslint/eslint/commit/9fce04e) Fix: `generator-star-spacing` false positive (fixes [#6135](https://github.com/eslint/eslint/issues/6135)) ([#6168](https://github.com/eslint/eslint/issues/6168)) (Toru Nagashima)




## Documentation


* [35b4656](https://github.com/eslint/eslint/commit/35b4656) Docs: Edit arrow-parens.md to show correct output value ([#6245](https://github.com/eslint/eslint/issues/6245)) (Adam Terlson)
* [cdd65d7](https://github.com/eslint/eslint/commit/cdd65d7) Docs: added examples for arrow-body-style (refs [#5498](https://github.com/eslint/eslint/issues/5498)) ([#6242](https://github.com/eslint/eslint/issues/6242)) (Tieme van Veen)
* [e6d5b1f](https://github.com/eslint/eslint/commit/e6d5b1f) Docs: Add rule deprecation section to user guide (fixes [#5845](https://github.com/eslint/eslint/issues/5845)) ([#6201](https://github.com/eslint/eslint/issues/6201)) (Kai Cataldo)




## Dependency Upgrades


* [777941e](https://github.com/eslint/eslint/commit/777941e) Upgrade: doctrine to 1.2.2 (fixes [#6121](https://github.com/eslint/eslint/issues/6121)) ([#6231](https://github.com/eslint/eslint/issues/6231)) (alberto)






3 changes: 3 additions & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ These rules relate to possible syntax or logic errors in JavaScript code:
* [no-irregular-whitespace](no-irregular-whitespace.md): disallow irregular whitespace outside of strings and comments (recommended)
* [no-negated-in-lhs](no-negated-in-lhs.md): disallow negating the left operand in `in` expressions (recommended)
* [no-obj-calls](no-obj-calls.md): disallow calling global object properties as functions (recommended)
* [no-prototype-builtins](no-prototype-builtins.md): Disallow use of `Object.prototypes` builtins directly
* [no-regex-spaces](no-regex-spaces.md): disallow multiple spaces in regular expression literals (recommended)
* [no-sparse-arrays](no-sparse-arrays.md): disallow sparse arrays (recommended)
* [no-unexpected-multiline](no-unexpected-multiline.md): disallow confusing multiline expressions (recommended)
Expand Down Expand Up @@ -219,6 +220,7 @@ These rules relate to style guidelines, and are therefore quite subjective:
* [space-infix-ops](space-infix-ops.md): require spacing around operators (fixable)
* [space-unary-ops](space-unary-ops.md): enforce consistent spacing before or after unary operators (fixable)
* [spaced-comment](spaced-comment.md): enforce consistent spacing after the `//` or `/*` in a comment (fixable)
* [unicode-bom](unicode-bom.md): require or disallow the Unicode BOM (fixable)
* [wrap-regex](wrap-regex.md): require parenthesis around regex literals

## ECMAScript 6
Expand All @@ -240,6 +242,7 @@ These rules relate to ES6, also known as ES2015:
* [no-this-before-super](no-this-before-super.md): disallow `this`/`super` before calling `super()` in constructors (recommended)
* [no-useless-computed-key](no-useless-computed-key.md): disallow unnecessary computed property keys in object literals
* [no-useless-constructor](no-useless-constructor.md): disallow unnecessary constructors
* [no-useless-rename](no-useless-rename.md): disallow renaming import, export, and destructured assignments to the same name
* [no-var](no-var.md): require `let` or `const` instead of `var`
* [object-shorthand](object-shorthand.md): require or disallow method and property shorthand syntax for object literals
* [prefer-arrow-callback](prefer-arrow-callback.md): require arrow functions as callbacks
Expand Down
14 changes: 14 additions & 0 deletions docs/rules/arrow-body-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ When the rule is set to `"as-needed"` the following patterns are considered prob
let foo = () => {
return 0;
};
let foo = () => {
return {
bar: {
foo: 1,
bar: 2,
}
};
};
```

The following patterns are not considered problems:
Expand All @@ -69,6 +77,12 @@ let foo = (retv, name) => {
retv[name] = true;
return retv;
};
let foo = () => ({
bar: {
foo: 1,
bar: 2,
}
});
let foo = () => { bar(); };
let foo = () => {};
let foo = () => { /* do nothing */ };
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/arrow-parens.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if ((a) => b) {
} else {
console.log('falsey value returned');
};
// outputs 'falsey value returned'
// outputs 'truthy value returned'
```

The following is another example of this behavior:
Expand Down
105 changes: 84 additions & 21 deletions docs/rules/consistent-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ layout: doc
---
<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->

# Require Consistent Returns (consistent-return)
# require `return` statements to either always or never specify values (consistent-return)

One of the confusing aspects of JavaScript is that any function may or may not return a value at any point in time. When a function exits without any `return` statement executing, the function returns `undefined`. Similarly, calling `return` without specifying any value will cause the function to return `undefined`. Only when `return` is called with a value is there a change in the function's return value.
Unlike statically-typed languages which enforce that a function returns a specified type of value, JavaScript allows different code paths in a function to return different types of values.

Unlike statically-typed languages that will catch when a function doesn't return the type of data expected, JavaScript has no such checks, meaning that it's easy to make mistakes such as this:
A confusing aspect of JavaScript is that a function returns `undefined` if any of the following are true:

* it does not execute a `return` statement before it exits
* it executes `return` which does not specify a value explicitly
* it executes `return undefined`
* it executes `return void` followed by an expression (for example, a function call)
* it executes `return` followed by any other expression which evaluates to `undefined`

If any code paths in a function return a value explicitly but some code path do not return a value explicitly, it might be a typing mistake, especially in a large function. In the following example:

* a code path through the function returns a Boolean value `true`
* another code path does not return a value explicitly, therefore returns `undefined` implicitly

```js
function doSomething(condition) {

if (condition) {
return true;
} else {
Expand All @@ -21,21 +31,16 @@ function doSomething(condition) {
}
```

Here, one branch of the function returns `true`, a Boolean value, while the other exits without specifying any value (and so returns `undefined`). This may be an indicator of a coding error, especially if this pattern is found in larger functions.

## Rule Details

This rule is aimed at ensuring all `return` statements either specify a value or don't specify a value.

It excludes constructors which, when invoked with the `new` operator, return the instantiated object if another object is not explicitly returned. This rule treats a function as a constructor if its name starts with an uppercase letter.
This rule requires `return` statements to either always or never specify values. This rule ignores function definitions where the name begins with an uppercase letter, because constructors (when invoked with the `new` operator) return the instantiated object implicitly if they do not return another object explicitly.

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

```js
/*eslint consistent-return: "error"*/

function doSomething(condition) {

if (condition) {
return true;
} else {
Expand All @@ -44,16 +49,6 @@ function doSomething(condition) {
}

function doSomething(condition) {

if (condition) {
return;
} else {
return true;
}
}

function doSomething(condition) {

if (condition) {
return true;
}
Expand All @@ -66,7 +61,6 @@ Examples of **correct** code for this rule:
/*eslint consistent-return: "error"*/

function doSomething(condition) {

if (condition) {
return true;
} else {
Expand All @@ -83,6 +77,75 @@ function Foo() {
}
```

## Options

This rule has an object option:

* `"treatUndefinedAsUnspecified": false` (default) always either specify values or return `undefined` implicitly only.
* `"treatUndefinedAsUnspecified": true` always either specify values or return `undefined` explicitly or implicitly.

### treatUndefinedAsUnspecified

Examples of **incorrect** code for this rule with the default `{ "treatUndefinedAsUnspecified": false }` option:

```js
/*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": false }]*/

function foo(callback) {
if (callback) {
return void callback();
}
// no return statement
}

function bar(condition) {
if (condition) {
return undefined;
}
// no return statement
}
```

Examples of **incorrect** code for this rule with the `{ "treatUndefinedAsUnspecified": true }` option:

```js
/*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/

function foo(callback) {
if (callback) {
return void callback();
}
return true;
}

function bar(condition) {
if (condition) {
return undefined;
}
return true;
}
```

Examples of **correct** code for this rule with the `{ "treatUndefinedAsUnspecified": true }` option:

```js
/*eslint consistent-return: ["error", { "treatUndefinedAsUnspecified": true }]*/

function foo(callback) {
if (callback) {
return void callback();
}
// no return statement
}

function bar(condition) {
if (condition) {
return undefined;
}
// no return statement
}
```

## When Not To Use It

If you want to allow functions to have different `return` behavior depending on code branching, then it is safe to disable this rule.
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ These rules relate to possible syntax or logic errors in JavaScript code:
* [no-irregular-whitespace](no-irregular-whitespace): disallow irregular whitespace outside of strings and comments (recommended)
* [no-negated-in-lhs](no-negated-in-lhs): disallow negating the left operand in `in` expressions (recommended)
* [no-obj-calls](no-obj-calls): disallow calling global object properties as functions (recommended)
* [no-prototype-builtins](no-prototype-builtins): Disallow use of `Object.prototypes` builtins directly
* [no-regex-spaces](no-regex-spaces): disallow multiple spaces in regular expression literals (recommended)
* [no-sparse-arrays](no-sparse-arrays): disallow sparse arrays (recommended)
* [no-unexpected-multiline](no-unexpected-multiline): disallow confusing multiline expressions (recommended)
Expand Down Expand Up @@ -225,6 +226,7 @@ These rules relate to style guidelines, and are therefore quite subjective:
* [space-infix-ops](space-infix-ops): require spacing around operators (fixable)
* [space-unary-ops](space-unary-ops): enforce consistent spacing before or after unary operators (fixable)
* [spaced-comment](spaced-comment): enforce consistent spacing after the `//` or `/*` in a comment (fixable)
* [unicode-bom](unicode-bom): require or disallow the Unicode BOM (fixable)
* [wrap-regex](wrap-regex): require parenthesis around regex literals

## ECMAScript 6
Expand All @@ -246,6 +248,7 @@ These rules relate to ES6, also known as ES2015:
* [no-this-before-super](no-this-before-super): disallow `this`/`super` before calling `super()` in constructors (recommended)
* [no-useless-computed-key](no-useless-computed-key): disallow unnecessary computed property keys in object literals
* [no-useless-constructor](no-useless-constructor): disallow unnecessary constructors
* [no-useless-rename](no-useless-rename): disallow renaming import, export, and destructured assignments to the same name
* [no-var](no-var): require `let` or `const` instead of `var`
* [object-shorthand](object-shorthand): require or disallow method and property shorthand syntax for object literals
* [prefer-arrow-callback](prefer-arrow-callback): require arrow functions as callbacks
Expand Down
36 changes: 18 additions & 18 deletions docs/rules/newline-before-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,13 @@ Examples of **incorrect** code for this rule:
```js
/*eslint newline-before-return: "error"*/

function foo() {

return;
}

function foo(bar) {
if (!bar) {

return;
}
}

function foo(bar) {
if (!bar) {
return;
}
return bar;
}

function foo() {

// comment
return;
}

function foo(bar) {
if (!bar) {
return;
Expand All @@ -88,6 +70,11 @@ function foo() {
return;
}

function foo() {

return;
}

function foo(bar) {
if (!bar) return;
}
Expand All @@ -109,6 +96,19 @@ function foo(bar) {

return bar;
}

function foo(bar) {
if (!bar) {

return;
}
}

function foo() {

// comment
return;
}
```

## When Not To Use It
Expand Down
Loading

0 comments on commit 5357e63

Please sign in to comment.