LoginSignup
8
1

More than 5 years have passed since last update.

ESLint v3.12.0

Last updated at Posted at 2016-12-10

v3.11.0 | 次 v3.13.0

ESLint 3.12.0 がリリースされました。
いくつかの機能追加・バグ修正が行われています。

質問やバグ報告等ありましたら、お気軽にこちらまでお寄せください。


:star2: 本体への変更

#6525: 新しい Node API: getRules, version

linter.getRulesは、現在読み込まれている全ルールを取得する API です。
結果値はMapオブジェクトになります。

const {linter} = require("eslint")
const rules = linter.getRules()

console.log(Array.from(rules.keys()))    // → ["accessor-pairs", "array-bracket-spacing", ...]
console.log(rules.get("accessor-pairs")) // → {meta: {docs: {...}, schema: {...}}, create: ...}}

初期状態では、結果値にはすべてのコアルールが含まれます。
プラグインを利用した Linting を行った後に呼び出すと、そのプラグインのルールも含まれます。

linter.version, CLIEngine.version はそれぞれ ESLint のバージョン番号が文字列で入っています。
(require("eslint/package.json").versionと同じ)

#7699: airbnb-base

eslint --initコマンドで選択できる airbnb 設定は、React を利用することが前提の設定です。
React を使用しない場合は airbnb-base 設定を使うことになっています。
今回、eslint --initコマンドで airbnb-base 設定も選択できるようになりました。

  $ eslint --init
  ? How would you like to configure ESLint? Use a popular style guide
  ? Which style guide do you want to follow? Airbnb
+ ? Do you use React? (y/N)

:bulb: 新しいルール

#7563: no-await-in-loop

通常のループ内にawait式を書くと警告するルールです。
そのようなawait式は直列実行されるので並列化しましょう、という意図のようです。

/*eslint no-await-in-loop: error */

async function wrap() {

    //✔ GOOD
    await Promise.all(list.map(doSomething))

    //✘ BAD
    for (const value of list) {
        await doSomething(value)
    }

}

個人的には、非同期処理をループ文で直列化できる事も async/await の利点の1つだと思ってますが...

:wrench: オプションが追加されたルール

#7681: indent

オブジェクトリテラルと配列リテラルで、2番目以降のプロパティ/要素を1番目のプロパティ/要素に揃えるオプションが追加されました。

/*eslint indent: [error, 4, {ObjectExpression: first, ArrayExpression: first}] */

//✔ GOOD
const a = { foo: 1,
            bar: 2,
            baz: 3 }
const b = [ 1,
            2,
            3 ]

//✘ BAD
const a = { foo: 1,
    bar: 2,
    baz: 3 }
const b = [ 1,
    2,
    3 ]

:pencil: eslint --fix をサポートしたルール

#7701: capitalized-comments

// this is a pen.

// ↓↓↓

// This is a pen.
8
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
1