Skip to content

Instantly share code, notes, and snippets.

@bitzip
Created September 5, 2015 15:43
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bitzip/8669fc060831c0f3d563 to your computer and use it in GitHub Desktop.
Save bitzip/8669fc060831c0f3d563 to your computer and use it in GitHub Desktop.
个人偏好的eslint配置,带中文注释
# 建议:官方文档对每个规则有简单易懂的例子说明,有时间的同学可以查阅一遍。
# 官方文档 http://eslint.org/docs/rules/
extends: 'eslint:recommended'
# 规则按照首字母在字母表升序排序
rules:
# 单行代码块大括号后需要一个空格
block-spacing: 2
# 不使用外部块定义的变量
block-scoped-var: 2
# 大括号位置
brace-style: [2, "1tbs"]
# 变量命名规则
camelcase: [2, { properties: "never" }]
# 逗号后使用空格
comma-spacing: 2
# 逗号位置
comma-style: [2, "last"]
# 代码块返回一致性
consistent-return: 2
# 使用语句大括号
curly: [2, "all"]
# 需要default在SwitchCase
default-case: 2
# 属性读取方式
# `foo['bar'] -> foo.bar`
dot-notation: [2, { allowKeywords: true }]
# EOL
eol-last: 2
# 相等判断
# 尽可能使用`===`
eqeqeq: 2
# 使用函数声明,而不是函数表达式
func-style: [2, "declaration"]
# 缩进空格
# `SwitchCase`时需要一个空格
indent: [2, 4, {SwitchCase: 1}]
# 分号之间的空格
key-spacing: [2, { beforeColon: false, afterColon: true }]
# 换行符格式
linebreak-style: [2, 'unix']
# 类命名首字母大写
new-cap: 2
# 类构建函数需要括号
new-parens: 2
# 不允许使用`alert`函数
no-alert: 2
# 数组尽量不使用构造函数
no-array-constructor: 2
# 不使用`console`
no-console: 0
# 不使用`var x; delete x;`
no-delete-var: 2
# 不使用非遍历情况的label
no-empty-label: 2
# 不使用`eval`
no-eval: 2
# 不允许扩展原生类型
no-extend-native: 2
# 不使用不必要的bind
no-extra-bind: 2
# 不允许不停止SwitchCase的
no-fallthrough: 2
# 使用显式的浮点数定义
# `.5 -> 0.5`
no-floating-decimal: 2
# 不使用非显式的函数执行
# `setTimeout("alert('Hi!');", 100);`
no-implied-eval: 2
# 不使用非显式this关键字
no-invalid-this: 2
# 不使用和变量同名的便签名
no-label-var: 2
# 循环内不定义非执行的函数
# 防止必包产生的作用域问题
no-loop-func: 2
# 不允许缩进不统一
no-mixed-spaces-and-tabs: [2, false]
# 不允许重复使用分隔空格
no-multi-spaces: 2
# 不允许转义换行符连接字符串
no-multi-str: 2
# 不允许赋值到关键字
no-native-reassign: 2
# 不嵌套ternary
# `var foo = bar ? baz : qux === quxx ? bing : bam;`
no-nested-ternary: 2
# 使用`new`需要赋值
no-new: 2
# 不使用类构建函数
# `var x = new Function("a", "b", "return a + b");`
no-new-func: 2
# 不使用Object构造函数
no-new-object: 2
# 原始类型不使用`new`
# `typeof new String('foo') == 'object'`
# `typeof String('foo') == 'string'`
no-new-wrappers: 2
# 不使用八进制数字
# `var num = 071; -> 57`
no-octal: 2
no-octal-escape: 2
# 不使用被废弃的`__proto__`
no-proto: 2
# 不重复声明变量
no-redeclare: 2
# 返回语句不赋值
no-return-assign: 2
# 不使用不加括号的逗号运算符
no-sequences: 2
# 嵌套块代码不重复变量名
no-shadow: 2
no-shadow-restricted-names: 2
no-spaced-func: 2
no-trailing-spaces: 2
no-undef: 2
no-undef-init: 2
no-undefined: 2
no-underscore-dangle: 2
no-unused-expressions: 2
no-unused-vars: [2, {vars: "all", args: "after-used"}]
no-use-before-define: 2
no-useless-concat: 2
no-with: 2
# 引号
quotes: [2, 'single']
radix: 2
# 分号
semi: [2, 'never']
semi-spacing: [2, {before: false, after: true}]
space-after-keywords: [2, "always"]
space-before-blocks: 2
space-before-function-paren: [2, "never"]
space-infix-ops: 2
space-return-throw-case: 2
space-unary-ops: [2, {words: true, nonwords: false}]
spaced-comment: [2, "always", { exceptions: ["-"]}]
wrap-iife: 2
yoda: [2, "never"]
env:
browser: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment