Skip to content

Commit

Permalink
[#37] upgrade eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreezag committed Jul 6, 2024
1 parent 6a0b443 commit 5e4cdd6
Show file tree
Hide file tree
Showing 96 changed files with 3,399 additions and 659 deletions.
408 changes: 408 additions & 0 deletions .eslint/airbnb/best-practices.js

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions .eslint/airbnb/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
export default {
rules: {
// Enforce “for” loop update clause moving the counter in the right direction
// https://eslint.org/docs/rules/for-direction
'for-direction': 'error',

// Enforces that a return statement is present in property getters
// https://eslint.org/docs/rules/getter-return
'getter-return': ['error', { allowImplicit: true }],

// disallow using an async function as a Promise executor
// https://eslint.org/docs/rules/no-async-promise-executor
'no-async-promise-executor': 'error',

// Disallow await inside of loops
// https://eslint.org/docs/rules/no-await-in-loop
'no-await-in-loop': 'error',

// Disallow comparisons to negative zero
// https://eslint.org/docs/rules/no-compare-neg-zero
'no-compare-neg-zero': 'error',

// disallow assignment in conditional expressions
'no-cond-assign': ['error', 'always'],

// disallow use of console
'no-console': 'warn',

// disallow use of constant expressions in conditions
'no-constant-condition': 'warn',

// disallow control characters in regular expressions
'no-control-regex': 'error',

// disallow use of debugger
'no-debugger': 'error',

// disallow duplicate arguments in functions
'no-dupe-args': 'error',

// Disallow duplicate conditions in if-else-if chains
// https://eslint.org/docs/rules/no-dupe-else-if
'no-dupe-else-if': 'error',

// disallow duplicate keys when creating object literals
'no-dupe-keys': 'error',

// disallow a duplicate case label.
'no-duplicate-case': 'error',

// disallow empty statements
'no-empty': 'error',

// disallow the use of empty character classes in regular expressions
'no-empty-character-class': 'error',

// disallow assigning to the exception in a catch block
'no-ex-assign': 'error',

// disallow double-negation boolean casts in a boolean context
// https://eslint.org/docs/rules/no-extra-boolean-cast
'no-extra-boolean-cast': 'error',

// disallow unnecessary parentheses
// https://eslint.org/docs/rules/no-extra-parens
'no-extra-parens': ['off', 'all', {
conditionalAssign: true,
nestedBinaryExpressions: false,
returnAssign: false,
ignoreJSX: 'all', // delegate to eslint-plugin-react
enforceForArrowConditionals: false,
}],

// disallow unnecessary semicolons
'no-extra-semi': 'error',

// disallow overwriting functions written as function declarations
'no-func-assign': 'error',

// https://eslint.org/docs/rules/no-import-assign
'no-import-assign': 'error',

// disallow function or variable declarations in nested blocks
'no-inner-declarations': 'error',

// disallow invalid regular expression strings in the RegExp constructor
'no-invalid-regexp': 'error',

// disallow irregular whitespace outside of strings and comments
'no-irregular-whitespace': 'error',

// Disallow Number Literals That Lose Precision
// https://eslint.org/docs/rules/no-loss-of-precision
'no-loss-of-precision': 'error',

// Disallow characters which are made with multiple code points in character class syntax
// https://eslint.org/docs/rules/no-misleading-character-class
'no-misleading-character-class': 'error',

// disallow the use of object properties of the global object (Math and JSON) as functions
'no-obj-calls': 'error',

// Disallow returning values from Promise executor functions
// https://eslint.org/docs/rules/no-promise-executor-return
'no-promise-executor-return': 'error',

// disallow use of Object.prototypes builtins directly
// https://eslint.org/docs/rules/no-prototype-builtins
'no-prototype-builtins': 'error',

// disallow multiple spaces in a regular expression literal
'no-regex-spaces': 'error',

// Disallow returning values from setters
// https://eslint.org/docs/rules/no-setter-return
'no-setter-return': 'error',

// disallow sparse arrays
'no-sparse-arrays': 'error',

// Disallow template literal placeholder syntax in regular strings
// https://eslint.org/docs/rules/no-template-curly-in-string
'no-template-curly-in-string': 'error',

// Avoid code that looks like two expressions but is actually one
// https://eslint.org/docs/rules/no-unexpected-multiline
'no-unexpected-multiline': 'error',

// disallow unreachable statements after a return, throw, continue, or break statement
'no-unreachable': 'error',

// Disallow loops with a body that allows only one iteration
// https://eslint.org/docs/rules/no-unreachable-loop
'no-unreachable-loop': ['error', {
ignore: [], // WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement
}],

// disallow return/throw/break/continue inside finally blocks
// https://eslint.org/docs/rules/no-unsafe-finally
'no-unsafe-finally': 'error',

// disallow negating the left operand of relational operators
// https://eslint.org/docs/rules/no-unsafe-negation
'no-unsafe-negation': 'error',

// disallow use of optional chaining in contexts where the undefined value is not allowed
// https://eslint.org/docs/rules/no-unsafe-optional-chaining
'no-unsafe-optional-chaining': ['error', { disallowArithmeticOperators: true }],

// Disallow Unused Private Class Members
// https://eslint.org/docs/rules/no-unused-private-class-members
// TODO: enable once eslint 7 is dropped (which is semver-major)
'no-unused-private-class-members': 'off',

// Disallow useless backreferences in regular expressions
// https://eslint.org/docs/rules/no-useless-backreference
'no-useless-backreference': 'error',

// disallow negation of the left operand of an in expression
// deprecated in favor of no-unsafe-negation
'no-negated-in-lhs': 'off',

// Disallow assignments that can lead to race conditions due to usage of await or yield
// https://eslint.org/docs/rules/require-atomic-updates
// note: not enabled because it is very buggy
'require-atomic-updates': 'off',

// disallow comparisons with the value NaN
'use-isnan': 'error',

// ensure JSDoc comments are valid
// https://eslint.org/docs/rules/valid-jsdoc
'valid-jsdoc': 'off',

// ensure that the results of typeof are compared against a valid string
// https://eslint.org/docs/rules/valid-typeof
'valid-typeof': ['error', { requireStringLiterals: true }],
},
};
185 changes: 185 additions & 0 deletions .eslint/airbnb/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
export default {
env: {
es6: true,
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: {
generators: false,
objectLiteralDuplicateProperties: false,
},
},

rules: {
// enforces no braces where they can be omitted
// https://eslint.org/docs/rules/arrow-body-style
// TODO: enable requireReturnForObjectLiteral?
'arrow-body-style': ['error', 'as-needed', {
requireReturnForObjectLiteral: false,
}],

// require parens in arrow function arguments
// https://eslint.org/docs/rules/arrow-parens
'arrow-parens': ['error', 'always'],

// require space before/after arrow function's arrow
// https://eslint.org/docs/rules/arrow-spacing
'arrow-spacing': ['error', { before: true, after: true }],

// verify super() callings in constructors
'constructor-super': 'error',

// enforce the spacing around the * in generator functions
// https://eslint.org/docs/rules/generator-star-spacing
'generator-star-spacing': ['error', { before: false, after: true }],

// disallow modifying variables of class declarations
// https://eslint.org/docs/rules/no-class-assign
'no-class-assign': 'error',

// disallow arrow functions where they could be confused with comparisons
// https://eslint.org/docs/rules/no-confusing-arrow
'no-confusing-arrow': ['error', {
allowParens: true,
}],

// disallow modifying variables that are declared using const
'no-const-assign': 'error',

// disallow duplicate class members
// https://eslint.org/docs/rules/no-dupe-class-members
'no-dupe-class-members': 'error',

// disallow importing from the same path more than once
// https://eslint.org/docs/rules/no-duplicate-imports
// replaced by https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
'no-duplicate-imports': 'off',

// disallow symbol constructor
// https://eslint.org/docs/rules/no-new-symbol
'no-new-symbol': 'error',

// Disallow specified names in exports
// https://eslint.org/docs/rules/no-restricted-exports
'no-restricted-exports': ['error', {
restrictedNamedExports: [
'default', // use `export default` to provide a default export
'then', // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
],
}],

// disallow specific imports
// https://eslint.org/docs/rules/no-restricted-imports
'no-restricted-imports': ['off', {
paths: [],
patterns: [],
}],

// disallow to use this/super before super() calling in constructors.
// https://eslint.org/docs/rules/no-this-before-super
'no-this-before-super': 'error',

// disallow useless computed property keys
// https://eslint.org/docs/rules/no-useless-computed-key
'no-useless-computed-key': 'error',

// disallow unnecessary constructor
// https://eslint.org/docs/rules/no-useless-constructor
'no-useless-constructor': 'error',

// disallow renaming import, export, and destructured assignments to the same name
// https://eslint.org/docs/rules/no-useless-rename
'no-useless-rename': ['error', {
ignoreDestructuring: false,
ignoreImport: false,
ignoreExport: false,
}],

// require let or const instead of var
'no-var': 'error',

// require method and property shorthand syntax for object literals
// https://eslint.org/docs/rules/object-shorthand
'object-shorthand': ['error', 'always', {
ignoreConstructors: false,
avoidQuotes: true,
}],

// suggest using arrow functions as callbacks
'prefer-arrow-callback': ['error', {
allowNamedFunctions: false,
allowUnboundThis: true,
}],

// suggest using of const declaration for variables that are never modified after declared
'prefer-const': ['error', {
destructuring: 'any',
ignoreReadBeforeAssign: true,
}],

// Prefer destructuring from arrays and objects
// https://eslint.org/docs/rules/prefer-destructuring
'prefer-destructuring': ['error', {
VariableDeclarator: {
array: false,
object: true,
},
AssignmentExpression: {
array: true,
object: false,
},
}, {
enforceForRenamedProperties: false,
}],

// disallow parseInt() in favor of binary, octal, and hexadecimal literals
// https://eslint.org/docs/rules/prefer-numeric-literals
'prefer-numeric-literals': 'error',

// suggest using Reflect methods where applicable
// https://eslint.org/docs/rules/prefer-reflect
'prefer-reflect': 'off',

// use rest parameters instead of arguments
// https://eslint.org/docs/rules/prefer-rest-params
'prefer-rest-params': 'error',

// suggest using the spread syntax instead of .apply()
// https://eslint.org/docs/rules/prefer-spread
'prefer-spread': 'error',

// suggest using template literals instead of string concatenation
// https://eslint.org/docs/rules/prefer-template
'prefer-template': 'error',

// disallow generator functions that do not have yield
// https://eslint.org/docs/rules/require-yield
'require-yield': 'error',

// enforce spacing between object rest-spread
// https://eslint.org/docs/rules/rest-spread-spacing
'rest-spread-spacing': ['error', 'never'],

// import sorting
// https://eslint.org/docs/rules/sort-imports
'sort-imports': ['off', {
ignoreCase: false,
ignoreDeclarationSort: false,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
}],

// require a Symbol description
// https://eslint.org/docs/rules/symbol-description
'symbol-description': 'error',

// enforce usage of spacing in template strings
// https://eslint.org/docs/rules/template-curly-spacing
'template-curly-spacing': 'error',

// enforce spacing around the * in yield* expressions
// https://eslint.org/docs/rules/yield-star-spacing
'yield-star-spacing': ['error', 'after'],
},
};
Loading

0 comments on commit 5e4cdd6

Please sign in to comment.