Eslint 團隊統一規範

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint',
    sourceType: 'module'
  },
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  // extends: ["plugin:vue/essential"],
  extends: ['plugin:vue/recommended', 'eslint:recommended'],

  // add your custom rules here
  //it is base on https://github.com/vuejs/eslint-config-vue
  rules: {
    "vue/max-attributes-per-line": [2, {
      "singleline": 10,
      "multiline": {
        "max": 1,
        "allowFirstLine": false
      }
    }],
    "vue/html-self-closing": ["error", {
      "html": {
        "void": "any",
        "normal": "any",
        "component": "any"
      },
      "svg": "any",
      "math": "any"
    }],
    "vue/singleline-html-element-content-newline": "off",
    'vue/no-parsing-error': [2, { "invalid-first-character-of-tag-name": false }],
    "vue/no-use-v-if-with-v-for": "off",
    "vue/multiline-html-element-content-newline": "off",
    "vue/name-property-casing": [0, "PascalCase"],
    "vue/html-closing-bracket-newline": [0, {
      "singleline": "never",
      "multiline": "always"
    }],
    "vue/no-side-effects-in-computed-properties": 0,
    'accessor-pairs': 2, //在對象中使用getter/setter
    'arrow-spacing': [2, {
      'before': true,
      'after': true
    }], //=>的前/後括號
    'block-spacing': [2, 'always'], //塊是否需要空格
    // if while function 後面的{必須與if在同一行,java風格。
    'brace-style': [2, '1tbs', {
      'allowSingleLine': true
    }],
    //強制駝峯法命名
    'camelcase': [0, {
      'properties': 'always'
    }],
    // 數組和對象鍵值對最後一個逗號, never參數:不能帶末尾的逗號, always參數:必須帶末尾的逗號,  
    // always-multiline:多行模式必須帶逗號,單行模式不能帶逗號  
    'comma-dangle': [2, 'never'],
    // 控制逗號前後的空格
    'comma-spacing': [2, {
      'before': false,
      'after': true
    }],
    'comma-style': [2, 'last'], // 控制逗號在行尾出現還是在行首出現  
    // 強制在子類構造函數中用super()調用父類構造函數,TypeScrip的編譯器也會提示 
    'constructor-super': 2,
    // 強制object.key 中 . 的位置,參數:  
    // property,'.'號應與屬性在同一行  
    // object, '.' 號應與對象名在同一行
    'dot-location': [2, 'property'],
    'eol-last': 2, // 文件末尾強制換行
    'eqeqeq': [2, 'allow-null'], // 使用 === 替代 ==
    'generator-star-spacing': 0, //生成器函數*的前後空格
    'handle-callback-err': 0, //nodejs 處理錯誤
    'indent': [2, 2, { //縮進風格
      'SwitchCase': 1
    }],
    // JSX 屬性中一致使用雙引號或單引號
    'jsx-quotes': [2, 'prefer-single'],
    //對象字面量中冒號的前後空格
    'key-spacing': [2, {
      'beforeColon': false,
      'afterColon': true
    }],
    'keyword-spacing': [2, {
      'before': true,
      'after': true
    }],
    //函數名首行大寫必須使用new方式調用,首行小寫必須用不帶new方式調用
    'new-cap': [2, {
      'newIsCap': true,
      'capIsNew': false
    }],
    'new-parens': 2, //new時必須加小括號
    'no-array-constructor': 2, //禁止使用數組構造器
    'no-caller': 2, //禁止使用arguments.caller或arguments.callee
    'no-console': 0, //禁止使用console
    'no-class-assign': 2, //禁止給類賦值
    'no-cond-assign': 2, //禁止在條件表達式中使用賦值語句
    'no-const-assign': 2, //禁止修改const聲明的變量
    'no-control-regex': 0, //禁止在正則表達式中使用控制字符
    'no-delete-var': 2, //不能對var聲明的變量使用delete操作符
    'no-dupe-args': 2, //函數參數不能重複
    'no-dupe-class-members': 2, //不允許類中出現重複的聲明
    'no-dupe-keys': 2, //在創建對象字面量時不允許鍵重複 {a:1,a:1}
    'no-duplicate-case': 2, //switch中的case標籤不能重複
    'no-empty-character-class': 0, //正則表達式中的[]內容不能爲空
    'no-empty-pattern': 0,
    'no-eval': 0, //禁止使用eval
    'no-ex-assign': 2, //禁止給catch語句中的異常參數賦值
    'no-extend-native': 2, //禁止擴展native對象
    'no-extra-bind': 2, //禁止不必要的函數綁定
    'no-extra-boolean-cast': 2, //禁止不必要的bool轉換
    'no-extra-parens': [2, 'functions'], //禁止非必要的括號
    'no-fallthrough': 2, //禁止switch穿透
    'no-floating-decimal': 2, //禁止省略浮點數中的0 .5 3.
    'no-func-assign': 2, //禁止重複的函數聲明
    'no-implied-eval': 2, //禁止使用隱式eval
    'no-inner-declarations': [2, 'functions'], //禁止在塊語句中使用聲明(變量或函數)
    'no-invalid-regexp': 2, //禁止無效的正則表達式
    'no-irregular-whitespace': 2, //不能有不規則的空格
    'no-iterator': 2, //禁止使用__iterator__ 屬性
    'no-label-var': 2, //label名不能與var聲明的變量名相同
    'no-labels': [2, { //禁止標籤聲明
      'allowLoop': false,
      'allowSwitch': false
    }],
    'no-lone-blocks': 2, //禁止不必要的嵌套塊
    'no-mixed-spaces-and-tabs': 2, //禁止混用tab和空格
    'no-multi-spaces': 2, //不能用多餘的空格
    'no-multi-str': 2, //字符串不能用\換行
    'no-multiple-empty-lines': [0, {
      'max': 1
    }], //空行最多不能超過1行
    'no-native-reassign': 2, //不能重寫native對象
    'no-negated-in-lhs': 2, //in 操作符的左邊不能有!
    'no-new-object': 2, //禁止使用new Object()
    'no-new-require': 2, //禁止使用new require
    'no-new-symbol': 2, //禁止使用new symbol
    'no-new-wrappers': 2, //禁止使用new創建包裝實例,new String new Boolean new Number
    'no-obj-calls': 0, //不能調用內置的全局對象,比如Math() JSON()
    'no-octal': 2, //禁止使用八進制數字
    'no-octal-escape': 2, //禁止使用八進制轉義序列
    'no-path-concat': 2, //node中不能使用__dirname或__filename做路徑拼接
    'no-proto': 2, //禁止使用__proto__屬性
    'no-redeclare': 2, //禁止重複聲明變量
    'no-regex-spaces': 2, //禁止在正則表達式字面量中使用多個空格 /foo bar/
    'no-return-assign': [2, 'except-parens'], //return 語句中不能有賦值表達式
    'no-self-assign': 2, //自我分配
    'no-self-compare': 2, //不能比較自身
    'no-sequences': 2, //禁止使用逗號運算符
    'no-shadow-restricted-names': 2, //嚴格模式中規定的限制標識符不能作爲聲明時的變量名使用
    'no-spaced-func': 2, //函數調用時 函數名與()之間不能有空格
    'no-sparse-arrays': 2, //禁止稀疏數組, [1,,2]
    'no-this-before-super': 2, //在調用super()之前不能使用this或super
    'no-throw-literal': 2, //禁止拋出字面量錯誤 throw "error";
    'no-trailing-spaces': 0, //一行結束後面不要有空格
    'no-undef': 2, //不能有未定義的變量
    'no-undef-init': 2, //變量初始化時不能直接給它賦值爲undefined
    'no-unexpected-multiline': 0, //避免多行表達式
    'no-unmodified-loop-condition': 0, //檢查引用是否在循環中被修改
    'no-unneeded-ternary': 0, //禁止不必要的嵌套 var isYes = answer === 1 ? true : false;
    'no-unreachable': 2, //不能有無法執行的代碼
    'no-unsafe-finally': 0,
    'no-unused-vars': [2, {
      'vars': 'all',
      'args': 'none'
    }], //不能有聲明後未被使用的變量或參數
    'no-useless-call': 2, //禁止不必要的call和apply
    'no-useless-computed-key': 0, //沒有必要使用帶文字的計算屬性
    'no-useless-constructor': 2, //可以在不改變類的工作方式的情況下安全地移除的類構造函數
    'no-useless-escape': 0,
    'no-whitespace-before-property': 0,
    'no-with': 2, //禁用with
    'one-var': 0, //連續聲明
    'operator-linebreak': [2, 'after', {
      'overrides': {
        '?': 'before',
        ':': 'before'
      }
    }], //換行時運算符在行尾還是行首
    'padded-blocks': 0, //塊語句內行首行尾是否要空行
    'quotes': [2, 'single', {
      'avoidEscape': true,
      'allowTemplateLiterals': true
    }], //引號類型 `` "" ''
    'semi': [2, 'never'], //語句強制分號結尾
    'semi-spacing': [2, {
      'before': false,
      'after': true
    }], //分號前後空格
    'space-before-blocks': [2, 'always'], //不以新行開始的塊{前面要不要有空格
    'space-before-function-paren': [2, 'never'], //函數定義時括號前面要不要有空格
    'space-in-parens': [2, 'never'], //小括號裏面要不要有空格
    'space-infix-ops': 2, //中綴操作符周圍要不要有空格
    'space-unary-ops': [2, {
      'words': true,
      'nonwords': false
    }], //一元運算符的前/後要不要加空格
    'spaced-comment': 0, //註釋風格不要有空格什麼的
    'template-curly-spacing': [2, 'never'],
    'use-isnan': 2, //禁止比較時使用NaN,只能用isNaN()
    'valid-typeof': 2, //必須使用合法的typeof的值
    'wrap-iife': [2, 'any'], //立即執行函數表達式的小括號風格
    'yield-star-spacing': 0,
    'yoda': [2, 'never'], //禁止尤達條件
    'prefer-const': 2, //首選const
    'no-debugger': 0, //禁止使用debugger
    'object-curly-spacing': [2, 'always', {
      objectsInObjects: false
    }], //大括號內是否允許不必要的空格
    'array-bracket-spacing': [2, 'never'] //是否允許非空數組裏面有多餘的空格
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章