Open xyzdata opened 6 years ago
// 菜单管理
const MENU_CHECK = 'MENU_CHECK';
const MENU_ADD = 'MENU_ADD';
const MENU_MODEFY = 'MENU_MODEFY';
const MENU_ASSOCIATE = 'MENU_ASSOCIATE';
const OBJ_CONSTANTS = Object.assign({}, {
MENU_CHECK,
MENU_ADD,
MENU_MODEFY,
MENU_ASSOCIATE
});
// OBJ_CONSTANTS.MENU_CHECK;
export default OBJ_CONSTANTS;
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code
with the goal of making code more consistent and avoiding bugs
In many ways, it is similar to JSLint and JSHint with a few exceptions:
$ eslint --init
$ eslint test1.js test2.js
In .eslintrc.*:
{
"env": {
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"warn",
"double"
],
"semi": [
"error",
"always"
]
}
}
ESLint will not lint your code unless you extend from a shared configuration or explicitly turn rules on in your configuration
find eslint config file
find configuration list
ESLint 主要有以下特点:
三种方式:
.eslintrc.*
{
"env": {
"browser": true,
},
"globals": {
"angular": true,
},
"rules": {
"camelcase": 2,
"curly": 2,
"brace-style": [2, "1tbs"],
"quotes": [2, "single"],
"semi": [2, "always"],
"space-in-brackets": [2, "never"],
"space-infix-ops": 2,
}
}
package.json 中添加 eslintConfig 配置模块
{
"name": "mypackage",
"version": "0.0.1",
"eslintConfig": {
"env": {
"browser": true,
"node": true
}
}
}
直接在代码文件中定义
// 禁用 ESLint
/* eslint-disable */
var obj = { key: 'value', }; // I don't care about IE8
/* eslint-enable */
// 禁用一条规则
/*eslint-disable no-alert */
alert('doing awful things');
/* eslint-enable no-alert */
// 调整规则
/* eslint no-comma-dangle:1 */
// Make this just a warning, not an error
var obj = { key: 'value', }
ESLint 可以集成到主流的编辑器和构建工具中, 以便我们在编写的代码的同时进行 lint.
var gulp = require('gulp');
var eslint = require('gulp-eslint');
gulp.task('lint', function() {
return gulp.src('client/app/**/*.js')
.pipe(eslint())
.pipe(eslint.format());
});
在 NPM 上以 eslintplugin 为关键词, 可以搜索到很多插件:
precommit & eslint
github git commit error