@wakamsha/eslint-config
Version:
wakamsha's ESLint rules as an extensible shared config.
278 lines (237 loc) • 8.64 kB
JavaScript
// @ts-check
/**
* @file
* Copyright (c) 2012 Airbnb
*
* Licensed under the MIT License: https://github.com/airbnb/javascript/blob/master/LICENSE.md
*
* This file is a copy of https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb-base/rules/style.js
* with the following modifications:
*
* - Enable `func-names` rule
* - Disable `no-nested-ternary` rule because there is no problem if you use line breaks and indentation properly.
* - Enable `no-plusplus` rule with `allowForLoopAfterthoughts` option
*/
export default {
rules: {
// require camel case names
// https://eslint.org/docs/rules/camelcase
camelcase: ['error', { properties: 'never', ignoreDestructuring: false }],
// enforce or disallow capitalization of the first letter of a comment
// https://eslint.org/docs/rules/capitalized-comments
'capitalized-comments': [
'off',
'never',
{
line: {
ignorePattern: '.*',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
block: {
ignorePattern: '.*',
ignoreInlineComments: true,
ignoreConsecutiveComments: true,
},
},
],
// enforces consistent naming when capturing the current execution context
// https://eslint.org/docs/rules/consistent-this
'consistent-this': ['off'],
// requires function names to match the name of the variable or property to which they are
// assigned
// https://eslint.org/docs/rules/func-name-matching
'func-name-matching': [
'off',
'always',
{
includeCommonJSModuleExports: false,
considerPropertyDescriptor: true,
},
],
// require function expressions to have a name
// https://eslint.org/docs/rules/func-names
'func-names': ['error'],
// enforces use of function declarations or expressions
// https://eslint.org/docs/rules/func-style
// TODO: enable
'func-style': ['off', 'expression'],
// disallow specified identifiers
// https://eslint.org/docs/rules/id-denylist
'id-denylist': ['off'],
// this option enforces minimum and maximum identifier lengths
// (variable names, property names etc.)
// https://eslint.org/docs/rules/id-length
'id-length': ['off'],
// require identifiers to match the provided regular expression
// https://eslint.org/docs/rules/id-match
'id-match': ['off'],
// deprecated in ESLint v9.3.0.
// enforce position of line comments
// https://eslint.org/docs/rules/line-comment-position
// TODO: enable?
'line-comment-position': [
'off',
{
position: 'above',
ignorePattern: '',
applyDefaultPatterns: true,
},
],
// Require or disallow logical assignment logical operator shorthand
// https://eslint.org/docs/latest/rules/logical-assignment-operators
// TODO, semver-major: enable
'logical-assignment-operators': [
'off',
'always',
{
enforceForIfStatements: true,
},
],
// specify the maximum depth that blocks can be nested
// https://eslint.org/docs/rules/max-depth
'max-depth': ['off', 4],
// specify the max number of lines in a file
// https://eslint.org/docs/rules/max-lines
'max-lines': [
'off',
{
max: 300,
skipBlankLines: true,
skipComments: true,
},
],
// enforce a maximum function length
// https://eslint.org/docs/rules/max-lines-per-function
'max-lines-per-function': [
'off',
{
max: 50,
skipBlankLines: true,
skipComments: true,
IIFEs: true,
},
],
// specify the maximum depth callbacks can be nested
// https://eslint.org/docs/rules/max-nested-callbacks
'max-nested-callbacks': ['off'],
// limits the number of parameters that can be used in the function declaration.
// https://eslint.org/docs/rules/max-params
'max-params': ['off', 3],
// specify the maximum number of statement allowed in a function
// https://eslint.org/docs/rules/max-statements
'max-statements': ['off', 10],
// enforce a particular style for multiline comments
// https://eslint.org/docs/rules/multiline-comment-style
'multiline-comment-style': ['off', 'starred-block'],
// require a capital letter for constructors
// https://eslint.org/docs/rules/new-cap
'new-cap': [
'error',
{
newIsCap: true,
newIsCapExceptions: [],
capIsNew: false,
capIsNewExceptions: [
'Immutable.Map',
'Immutable.Set',
'Immutable.List',
],
},
],
// disallow use of the Array constructor
// https://eslint.org/docs/rules/no-array-constructor
'no-array-constructor': ['error'],
// disallow use of bitwise operators
// https://eslint.org/docs/rules/no-bitwise
'no-bitwise': ['off'],
// disallow use of the continue statement
// https://eslint.org/docs/rules/no-continue
'no-continue': ['error'],
// disallow comments inline after code
// https://eslint.org/docs/rules/no-inline-comments
'no-inline-comments': ['off'],
// disallow if as the only statement in an else block
// https://eslint.org/docs/rules/no-lonely-if
'no-lonely-if': ['error'],
// disallow use of chained assignment expressions
// https://eslint.org/docs/rules/no-multi-assign
'no-multi-assign': ['error'],
// disallow negated conditions
// https://eslint.org/docs/rules/no-negated-condition
'no-negated-condition': ['off'],
// disallow nested ternary expressions
// https://eslint.org/docs/rules/no-nested-ternary
'no-nested-ternary': ['off'],
// disallow use of the Object constructor
// https://eslint.org/docs/rules/no-new-object
'no-new-object': ['error'],
// disallow use of unary operators, ++ and --
// https://eslint.org/docs/rules/no-plusplus
'no-plusplus': [
'error',
{
allowForLoopAfterthoughts: true,
},
],
// disallow certain syntax forms
// https://eslint.org/docs/rules/no-restricted-syntax
'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.',
},
],
// disallow the use of ternary operators
// https://eslint.org/docs/rules/no-ternary
'no-ternary': ['off'],
// disallow dangling underscores in identifiers
// https://eslint.org/docs/rules/no-underscore-dangle
'no-underscore-dangle': [
'error',
{
allow: [],
allowAfterThis: false,
allowAfterSuper: false,
enforceInMethodNames: true,
},
],
// disallow the use of Boolean literals in conditional expressions
// also, prefer `a || b` over `a ? a : b`
// https://eslint.org/docs/rules/no-unneeded-ternary
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
// allow just one var statement per function
// https://eslint.org/docs/rules/one-var
'one-var': ['error', 'never'],
// require assignment operator shorthand where possible or prohibit it entirely
// https://eslint.org/docs/rules/operator-assignment
'operator-assignment': ['error', 'always'],
// Disallow the use of Math.pow in favor of the ** operator
// https://eslint.org/docs/rules/prefer-exponentiation-operator
'prefer-exponentiation-operator': ['error'],
// Prefer use of an object spread over Object.assign
// https://eslint.org/docs/rules/prefer-object-spread
'prefer-object-spread': ['error'],
// requires object keys to be sorted
// https://eslint.org/docs/rules/sort-keys
'sort-keys': ['off', 'asc', { caseSensitive: false, natural: true }],
// sort variables within the same declaration block
// https://eslint.org/docs/rules/sort-vars
'sort-vars': ['off'],
// require or disallow the Unicode Byte Order Mark
// https://eslint.org/docs/rules/unicode-bom
'unicode-bom': ['error', 'never'],
},
};