代码检查
jest
Jest是由Facebook发布的开源的、基于Jasmine的JavaScript单元测试框架。
eslint
"off" 或 0 - 关闭规则
"warn" 或 1 - 开启规则,使用警告级别的错误:warn (不会导致程序退出)
"error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出)
常用规则
rules: {
['eqeqeq']: 'off', // 关闭===代替==的告警
['default-case']: 'off', // 关闭switch没有default的告警
['array-callback-return']: 'off', // 关闭数组函数没有return的告警
['no-script-url']: 'off', // 关闭a标签href无url的告警
['jsx-a11y/anchor-is-valid']: 'off', // 关闭jsx a标签无效的告警
['jsx-a11y/anchor-has-content']: 'off' // 关闭jsx a标签无内容的告警
}
eslint-loader
webpack的eslint加载器
- npm安装地址:https://www.npmjs.com/package/eslint-loader
- webpack使用:https://webpack.docschina.org/loaders/eslint-loader/
module.exports = {
// ...
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
// eslint options (if necessary)
}
},
],
},
// ...
}
eslint-plugin-flowtype
让eslint识别flow类型声明的语法
{
"parser": "babel-eslint",
"plugins": [
"flowtype"
],
"rules": {
"flowtype/boolean-style": [
2,
"boolean"
],
}
}
eslint-plugin-import
这个插件打算支持linting的ES2015+ (ES6+)导入/导出语法,并防止文件路径和导入名称拼写错误的问题。
// .eslintrc.js
module.exports = {
settings: {
'import/resolver': {
foo: { someConfig: value }
}
}
}
eslint-plugin-jsx-a11y
用于JSX元素上的可访问性规则的静态AST检查器。
{
"rules": {
"jsx-a11y/rule-name": 2
}
}
eslint-plugin-react
为React提供特定的eslint代码检测
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
}
babel-eslint
Babel - ESLint允许您将所有有效的Babel代码与奇妙的ESLint结合在一起。
{
"parser": "babel-eslint",
"rules": {
"strict": 0
}
}