2016-03-31 17 views
26

Visual Studioコードを使用してbabel/ES7 stage-0ルールに基づいてJavaScriptファイルをリントする方法はありますか?VSCode Linter ES6 ES7 Babel linter

私はコードをlintする必要があります。私はすでにwebpackをJsファイルに変換しています。私は進む方法

答えて

51

npm install -g eslint

  • はバベル-eslintをインストールします:npm install --save-dev babel-eslint
  • はバベル-eslintをインストール:npm install --save-dev eslint-plugin-react
  • あなたのルートディレクトリに.eslintrcファイルを作成

    • は、グローバルeslintをインストールします。 、その後、 "eslint" を書いて、検証し、 "拡張機能をインストール" を選択し、 "拡張" を書くVSCで

    { 
    "env": { 
         "browser": true, 
         "node": true, 
         "es6": true, 
         "jest": true, 
         "jquery": true 
        }, 
        "parser": "babel-eslint", 
        "parserOptions": { 
         "ecmaVersion": 6, 
         "sourceType": "module", 
         "ecmaFeatures": { 
          "arrowFunctions": true, 
          "binaryLiterals": true, 
          "blockBindings": true, 
          "classes": true, 
          "defaultParams": true, 
          "destructuring": true, 
          "forOf": true, 
          "generators": true, 
          "modules": true, 
          "objectLiteralComputedProperties": true, 
          "objectLiteralDuplicateProperties": true, 
          "objectLiteralShorthandMethods": true, 
          "objectLiteralShorthandProperties": true, 
          "octalLiterals": true, 
          "regexUFlag": true, 
          "regexYFlag": true, 
          "spread": true, 
          "superInFunctions": true, 
          "templateStrings": true, 
          "unicodeCodePointEscapes": true, 
          "globalReturn": true, 
          "jsx": true, 
          "experimentalObjectRestSpread": true 
         } 
        }, 
        "plugins": [ 
         "react" 
        ], 
        "rules": { 
         "strict": 0 
        } 
    } 
    
    • 、F1を押してください:ここに私の設定です。あなたES7コードを望んでいたように糸くず必要があり、

    { 
        //disable default javascript validator replaced by eslint 
        "javascript.validate.enable" : false 
    } 
    

    を今:あなたはユーザパラメータ(settings.json)を開き、書き込み、VSCコードでVSC

  • を再起動する必要があります。 VSC reading eslint configに問題がある場合は、VSCコンソール(ctrl-shift-U)で確認できます。その結果、ES7コード(例えばオブジェクトの広がり演算子は)うまくLINTEDさ

    enter image description here

    PS:私の.eslintrcはので、それを削除すること自由に感じ毛羽立ちES7のためのいくつかの役に立たない余分なデータを使用していますことがあります)

  • +0

    どこに.eslintrcファイルを置くべきですか?私のホームディレクトリに?または "ルート"ディレクトリ –

    +1

    プロジェクトのルートディレクトリには、 'openFolder'を使用するときにVSCodeで選択したディレクトリがあります。 –

    +0

    ありがとうございます。これはまだそれについて行くための最善の方法ですか? githubのVSCodeスレッドが閉じられていない –

    関連する問題