UNPKG

4.78 kBJavaScriptView Raw
1/**
2 * eslint规则配置,用于被业务工程引用
3 * Created by liuzhengdong on 2018/4/3.
4 */
5// 定义
6const ignoreMethods = [
7 // Vue
8 'render',
9 'renderError',
10 'export',
11 // Lifecycle Hooks
12 'beforeCreate',
13 'created',
14 'beforeMount',
15 'mounted',
16 'beforeUpdate',
17 'updated',
18 'activated',
19 'deactivated',
20 'beforeDestroy',
21 'destroyed',
22 // Options
23 'computed',
24 'components',
25 'mixins',
26 // Vue directives
27 'bind',
28 'unbind',
29 // Vue Router
30 '$route',
31 'beforeRouteEnter',
32 'beforeRouteUpdate',
33 'beforeRouteLeave',
34]
35
36module.exports = {
37 root: true,
38 env: {
39 // 环境定义了预定义的全局变量。
40 browser: true,
41 node: true,
42 es6: true,
43 mocha: true
44 },
45 // 使用babel-eslint来作为eslint的解析器
46 parser: 'babel-eslint',
47 parserOptions: {
48 // ECMAScript 版本
49 ecmaVersion: 6,
50 sourceType: 'module',
51 // // 想使用的额外的语言特性:
52 ecmaFeatures: {
53 experimentalObjectRestSpread: true,
54 }
55 },
56 extends: 'standard',
57 plugins: [
58 'html',
59 'import',
60 'promise',
61 '@sweetui/sweet-mobile-sdk/object-literal-jsdoc',
62 ],
63 // add your custom rules here 0忽略 1warn 2 error
64 rules: {
65 'valid-jsdoc': [1, {
66 requireReturn: false,
67 }],
68 'require-jsdoc': [1, {
69 require: {
70 FunctionDeclaration: true,
71 MethodDefinition: true,
72 ClassDeclaration: true,
73 },
74 }],
75 '@sweetui/sweet-mobile-sdk/object-literal-jsdoc/obj-doc': [1, {
76 ignoreMethods,
77 }],
78 // 缩进4空格 禁用2
79 'indent': [1, 4],
80 // 禁止条件表达式中出现赋值操作符
81 'no-cond-assign': 2,
82 // 允许console语句
83 'no-console': 1,
84 // 允许 debugger
85 'no-debugger': 1,
86 // var声明
87 'no-var': 2,
88 // 禁止 function 定义中出现重名参数
89 'no-dupe-args': 2,
90 // 禁止重复的函数声明
91 'no-func-assign': 2,
92 // 忽略分号;
93 'semi': [1, "never"],
94 // 使用 === 和 !==
95 'eqeqeq': [2, 'allow-null'],
96 // warn alert、
97 'no-alert': 1,
98 // 禁用 eval()
99 'no-eval': 2,
100 // 禁用 with 语句
101 'no-with': 2,
102 // 要求或禁止使用严格模式指令
103 'strict': 2,
104 // 要求或禁止 var 声明中的初始化(初值)
105 'init-declarations': 2,
106 // 不允许 catch 子句的参数与外层作用域中的变量同名
107 'no-catch-shadow': 0,
108 // 禁止删除变量
109 'no-delete-var': 2,
110 // 不允许标签与变量同名
111 'no-label-var': 2,
112 // 禁用特定的全局变量
113 'no-restricted-globals': 2,
114 // 禁止 var 声明 与外层作用域的变量同名
115 'no-shadow': 0,
116 // 禁止覆盖受限制的标识符
117 'no-shadow-restricted-names': 2,
118 // 禁用未声明的变量,除非它们在 /*global */ 注释中被提到
119 'no-undef': 2,
120 // 禁止将变量初始化为 undefined
121 'no-undef-init': 2,
122 // 禁止将 undefined 作为标识符
123 'no-undefined': 2,
124 // 禁止出现未使用过的变量
125 'no-unused-vars': [1, {'vars': 'all', 'args': 'none'}],
126 // 不允许在变量定义之前使用它们
127 'no-use-before-define': 1,
128 // 强制一行的最大长度
129 'max-len': [1, 160],
130 // 文件末尾强制换行
131 'eol-last': 0,
132 // 强制使用单引号
133 'quotes': [2, 'single'],
134 // 禁止修改 const 声明的变量
135 'no-const-assign': 2,
136 // 禁止标识符中有悬空下划线_bar,这里忽略
137 'no-underscore-dangle': 0,
138 // 禁用行尾空格
139 'no-trailing-spaces': 2,
140 // 禁用不必要的嵌套块
141 'no-lone-blocks': 2,
142 // 强制在 JSX 属性中一致地使用双引号或单引号
143 'jsx-quotes': 0,
144 // 函数定义时括号前面要不要有空格
145 'space-before-function-paren': [1, `never`],
146 //对象字面量项尾不能有逗号 这里忽略
147 'comma-dangle': [0, 'always'],
148 // 在对象字面量属性中实现键和值之间的一致间隔 {key: value}
149 'key-spacing': [1, {'mode': 'strict'}],
150 // 允许对象所有键和值在同一行上
151 'object-property-newline': [0, {'allowMultiplePropertiesPerLine': true}],
152 // promise reject 参数设置为 * 任意类型
153 'prefer-promise-reject-errors': [0, {'allowEmptyReject': true}]
154 },
155}