Robust set of default rules covering all of the rules that exist in JSLint and JSHint, making a migration to this tool fairly easy.node
Configurable rules - including error levels, allowing you to decide what is a warning, error, or simply disabled.react
Rules for style checking, which can help keep the code format consistent across teams.webpack
The ability to write your own plugins and rules.es6
npm i --save-dev eslint babel-eslint eslint-plugin-babel eslint-plugin-react
npm i -g eslint babel-eslint eslint-plugin-babel eslint-plugin-react
eslint -c .eslintrc ./src
eslint -c .eslintrc ./src --fix
eslint -c .eslintrc ./
{
"parser": "babel-eslint", "plugins": [ "babel" ], "rules": { "indent": [2, 2, { "SwitchCase": 1, "VariableDeclarator": {"var": 2, "let": 2, "const": 3} }], "default-case": 2, "eqeqeq": 2, "curly": 2, "quotes": [2, "single"], "linebreak-style": [2, "unix"], "semi": [2, "always"], "no-console": 0, "comma-style": [2, "last"], "arrow-parens": 0, "handle-callback-err": 2, "no-lonely-if": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "babel/arrow-parens": 0, "space-infix-ops": 2, "generator-star-spacing": 1, "no-var": 2, "array-bracket-spacing": 1, "babel/object-shorthand": 0, "babel/no-await-in-loop": 0, "comma-dangle": 1, "react/prop-types": 0, "react/display-name": 0 }, "env": { "es6": true, "node": true, "browser": true }, "parserOptions": { "ecmaFeatures": { "jsx": true, "modules": true, "arrowFunctions":true, "classes":true }, "sourceType": "module" }, "extends": [ "plugin:react/recommended" ], "globals": { } }
node_modules/* src/interfaceUtil/node_modules/* snapshotKoa/node_modules/* dist/*
{
... "lint": "eslint -c .eslintrc ./ --fix" ... }
命令行運行:web
npm run lint
npm i --save-dev eslint-loader
npm
webpack.config.js
json
module: {
rules: [{
test: /\.js$/, use: ['babel-loader?cacheDirectory=true', 'eslint-loader'], include: path.join(__dirname, 'src'), exclude: [/dist/, /node_modules/, /src\/interfaceUtil\/node_modules/, /snapshotKoa\/node_modules/] }, { test: /\.(png|jpg|gif)$/, use: [{ loader: 'url-loader', options: { limit: 8192 } }] }] },
若是ESLint不一樣過的話,npm run build
會報錯。
babel
Command + ,