eslint-config-imweb
Version:
IMWeb团队eslint配置规则
302 lines (301 loc) • 8.67 kB
JavaScript
module.exports = {
extends: [
'eslint-config-airbnb',
'plugin:react-hooks/recommended',
'eslint-config-imweb-t',
],
parser: 'babel-eslint',
root: true,
rules: {
// 0 = off, 1 = warn, 2 = error
'array-callback-return': ['warn', { allowImplicit: true }],
'arrow-body-style': 'off',
'arrow-parens': 'off',
'arrow-spacing': ['error', { before: true, after: true }],
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
camelcase: ['error', { properties: 'never', ignoreDestructuring: true, ignoreImports: true, allow: ['^UNSAFE_'] }],
'class-methods-use-this': 'off',
'consistent-return': 'off',
'comma-dangle': [
'error',
{
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'always-multiline',
},
],
'computed-property-spacing': ['error', 'never'],
'dot-notation': ['error', { allowKeywords: true }],
eqeqeq: ['error', 'always', { null: 'ignore' }],
'func-names': ['warn', 'as-needed'],
'func-style': ['off', 'expression'],
indent: ['error', 2, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
FunctionDeclaration: {
parameters: 1,
body: 1,
},
FunctionExpression: {
parameters: 1,
body: 1,
},
CallExpression: {
arguments: 1,
},
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
ignoredNodes: ['TSXElement', 'JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXFragment', 'JSXOpeningFragment', 'JSXClosingFragment', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild'],
ignoreComments: false,
}],
'max-len': [
'error',
{
code: 120,
ignoreStrings: true,
ignoreUrls: true,
ignoreRegExpLiterals: true,
ignoreTemplateLiterals: true,
ignoreComments: true,
},
],
'no-await-in-loop': 'off',
'no-async-promise-executor': 'warn',
'no-confusing-arrow': [
'error',
{
allowParens: true,
},
],
'no-continue': 'warn',
'no-dupe-class-members': 'error',
'no-else-return': ['error', { allowElseIf: false }],
'no-empty-function': [
'error',
{
allow: ['arrowFunctions', 'functions', 'methods'],
},
],
'no-iterator': 'error',
'no-magic-numbers': [
'off',
{
ignore: [],
ignoreArrayIndexes: true,
enforceConst: true,
detectObjects: false,
},
],
'no-new-wrappers': 'warn',
'no-param-reassign': [
'warn',
{
props: true,
ignorePropertyModificationsFor: [
'acc', // for reduce accumulators
'accumulator', // for reduce accumulators
'e', // for e.returnvalue
'ctx', // for Koa routing
'context', // for Koa routing
'req', // for Express requests
'request', // for Express requests
'res', // for Express responses
'response', // for Express responses
'$scope', // for Angular 1 scopes
'staticContext', // for ReactRouter context
],
},
],
'no-unused-vars': [
'error',
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true },
],
'no-unused-expressions': 'off',
'no-restricted-properties': [
'error',
{
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
},
{
object: 'global',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'self',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'window',
property: 'isFinite',
message: 'Please use Number.isFinite instead',
},
{
object: 'global',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
object: 'self',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
object: 'window',
property: 'isNaN',
message: 'Please use Number.isNaN instead',
},
{
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
},
{
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
},
{
object: 'Math',
property: 'pow',
message: 'Use the exponentiation operator (**) instead.',
},
],
'no-shadow': 'warn',
'no-script-url': 'off',
'no-useless-constructor': 'error',
'newline-per-chained-call': ['error', { ignoreChainWithDepth: 4 }],
'no-nested-ternary': 'error',
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
'no-underscore-dangle': 'off',
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
'no-whitespace-before-property': 'error',
'no-plusplus': 'off',
'object-curly-spacing': ['error', 'always'],
'object-curly-newline': 'off',
'object-shorthand': [
'error',
'always',
{
ignoreConstructors: false,
avoidQuotes: true,
},
],
'one-var': ['error', 'never'],
'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }],
quotes: ['error', 'single', { avoidEscape: true }],
'spaced-comment': ['error', 'always', {
line: {
markers: ['/'],
exceptions: ['-', '+'],
},
block: {
markers: ['!'],
exceptions: ['*'],
balanced: true,
},
}],
'space-before-function-paren': [
'error',
{
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
},
],
'prefer-const': ['error', {
destructuring: 'all',
ignoreReadBeforeAssign: true,
}],
'prefer-destructuring': [
'error',
{
VariableDeclarator: {
array: false,
object: true,
},
AssignmentExpression: {
array: false,
object: false,
},
},
{
enforceForRenamedProperties: false,
},
],
'prefer-rest-params': 'error',
'prefer-spread': 'error',
radix: 'error',
'template-curly-spacing': 'error',
// import
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': 'off',
'import/extensions': 'off',
'import/first': 'off',
// react
'react/destructuring-assignment': 'off',
'react/forbid-prop-types': 'off',
'react/jsx-closing-tag-location': 'warn',
'react/jsx-filename-extension': [
'error', {
extensions: [
'.jsx',
'.tsx',
],
},
],
'react/jsx-one-expression-per-line': 'off',
'react/jsx-props-no-spreading': 'off',
'react/jsx-no-script-url': [
'error',
[
{
name: 'Link',
props: ['to'],
},
{
name: 'Foo',
props: ['href', 'to'],
},
],
],
'react/require-default-props': 'off',
'react/no-danger': 'warn',
'react/no-did-mount-set-state': 'off',
'react/prop-types': 'off',
'react/sort-comp': 'off',
'react/static-property-placement': 'off',
// jsx
'jsx-a11y/media-has-caption': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-element-to-interactive-role': 'off',
'jsx-a11y/no-noninteractive-element-interactions': 'off',
'jsx-a11y/mouse-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
'jsx-a11y/anchor-is-valid': 'off',
},
};