在项目中使用eslint

官网地址:http://eslint.cn/docs/user-guide/command-line-interface

配置示例

module.exports = {
  root: true,
  parserOptions: {
    ecmaVersion: 8,
    sourceType: 'module'
  },
  globals: {
    "$": false,
    "moment": false,
    "echarts": false,
  },
  extends: "airbnb-base",
  env: {
    browser: true
  },
  rules: {
    "no-console": ["error"],
    "no-constant-condition": ["error"],
    "max-len": ["warn", 120, 2],
    "padded-blocks": ["error", "never"],
    "import/no-unresolved": ["error",  { ignore: ['/config/environment$'] }],
    "import/extensions": ["error", "never"],
    "arrow-parens": ["error", "as-needed"],
    "no-plusplus": ["off", { "allowForLoopAfterthoughts": true }],
    "no-unused-expressions": ["error", { "allowShortCircuit": true }],
    "no-underscore-dangle": ["off", { "allowAfterThis": true }],
    "new-cap": ["error", {"newIsCapExceptions": ["Ember.String.htmlSafe"]}],
    "comma-dangle": ["warn", "only-multiline"]
  },
  settings: {
    "import/core-modules": [ "ember", "npm:mockjs" ],
  }
};

忽略某些文件

# /node_modules/* and /bower_components/* ignored by default
/server/**
/tests/**
/config/**
/pubic/**
/tmp/**
/vendor/**
/dist/**
testem.js
ember-cli-build.js

执行检查

eslint /app

推荐的第三规范

airbnb: https://www.npmjs.com/package/eslint-config-airbnb

中文翻译的规范: https://github.com/OrangeBao/javascript

results matching ""

    No results matching ""