eslint-config-mts
Version:
MLT ESLint 规则
127 lines (118 loc) • 4.99 kB
JavaScript
module.exports = {
// 换成 当前 项目 build 后的文件'./index.js', './react.js', './typescript.js',
// extends: ['alloy', 'alloy/react', 'alloy/typescript'],
env: {
browser: true
},
// plugins: ['react-hooks', 'jsdoc'],
plugins: ['prettier', 'react-hooks', 'jsdoc'],
globals: {
// 这里填入你的项目需要的全局变量
// 这里值为 false 表示这个全局变量不允许被重新赋值,比如:
// jQuery: false,
// $: false
},
rules: {
/**
* prettier
* 样式规则委托prettier进行管理
*/
'prettier/prettier': [
'error',
{},
{
fileInfoOptions: {
withNodeModules: true
}
}
],
/**
* ES基础配置
*/
// 禁用debugger模式
'no-debugger': 'off',
// 禁止未使用过的变量包括全局变量和函数中的最后一个参数必须使用
'no-unused-vars': [
'error',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
caughtErrors: 'none'
}
],
// 强制最大可嵌深度为3,alloy 默认为 5, eslint 建议为 4
'max-depth': ['error', 3],
// NodeJs rules, 9.0之后全部使用import
// 关闭require()强制在模块顶部调用
'global-require': 'off',
// 如果一个变量不会被重新赋值,则使用const声明
'prefer-const': 'error',
// 关闭强制在花括号内使用一致的换行符
'object-curly-newline': 'off',
// new 后面的类名必须首字母大写
'new-cap': ['error', { properties: false, capIsNew: false }],
// 关闭点击元素上强制增加onKey**事件
'click-events-have-key-events': 'off',
// parseInt 必须传入第二个参数, TS会自动校正,所以关闭
radix: 'off',
// 函数括号内换行
// consistent: 要求每对圆括号一致地使用换行符。如果该对中的一个括号内有换行符,而另一个括号中没有换行符,则会报告错误。
'function-paren-newline': ['error', 'consistent'],
// 使用void 0 代替 undefined
'no-void': 'off',
// 该规则旨在标记类型转换的较短符号,然后提供一个更加明了的符号。
// 允许使用简便的方式对值类型进行转换
'no-implicit-coercion': 'off',
// 此规则在对象文字的大括号内执行一致的间距,解构赋值和导入/导出说明符。
// 降维使用花括号
'object-curly-spacing': ['error', 'always'],
// 忽略错误回调,必须处理异常现象
'handle-callback-err': 'off',
// 支持 empty constructor
'no-useless-constructor': 'off',
// Project.reject 可以不使用 error
'prefer-promise-reject-errors': 'off',
/**
* React
*/
// 使用了jsx语法的js代码文件其扩展名可以使用js或jsx
'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }],
// 无状态和没有使用生命周期的组件使用函数组件声明
'react/prefer-stateless-function': ['error', { ignorePureComponents: false }],
// 组件内部换行
'react/jsx-one-expression-per-line': 'off',
// 组件内方法必须按照一定规则排序
'react/sort-comp': [
1,
{
order: ['static-methods', 'instance-variables', 'lifecycle', 'everything-else', 'render']
}
],
// 第一个属性必须换行
'react/jsx-first-prop-new-line': 'off',
// 禁止jsx中使用无用的引号
'react/jsx-curly-brace-presence': 'off',
// 禁止无意义的 Fragment 组件
'react/jsx-no-useless-fragment': 'off',
/**
* typescript-eslint
*/
// 是否检测空接口
'@typescript-eslint/no-empty-interface': 'off',
// 是否显示声明类成员的访问性, 使用React的成员顺序
'@typescript-eslint/explicit-member-accessibility': 'off',
// 将代码缩进管理,委托 prettier 进行管理
'@typescript-eslint/indent': 'off',
// 禁止出现没必要的 constructor, 自动模板生成的代码都是空的constructor
'@typescript-eslint/no-useless-constructor': 'off',
// no-unused-expressions 会跟typescript的链式可选链调用冲突(prefer-optional-chain)
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
/**
* React-hooks 插件
*/
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn'
}
};