mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
164 lines
6.6 KiB
YAML
164 lines
6.6 KiB
YAML
root: true
|
|
|
|
parser: '@typescript-eslint/parser'
|
|
|
|
parserOptions:
|
|
project:
|
|
- ./tsconfig.json
|
|
|
|
extends:
|
|
- eslint:recommended
|
|
- airbnb-base
|
|
- plugin:@typescript-eslint/recommended
|
|
- plugin:@typescript-eslint/recommended-requiring-type-checking
|
|
|
|
plugins: ["@typescript-eslint"]
|
|
|
|
settings:
|
|
import/resolver:
|
|
node:
|
|
extensions:
|
|
- .js
|
|
- .jsx
|
|
- .ts
|
|
- .tsx
|
|
- .d.ts
|
|
|
|
env:
|
|
browser: true
|
|
node: true
|
|
es6: true
|
|
jest: true
|
|
|
|
globals:
|
|
cc: false
|
|
wx: false
|
|
Editor: false
|
|
_Scene: false
|
|
_ccsg: false
|
|
|
|
rules:
|
|
|
|
# https://eslint.org/docs/rules/
|
|
# https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
|
|
|
|
# !!!!!!!!!!!!!!!!!!!!!!!!!
|
|
# BEFORE ADDING ANY RULES
|
|
# PLEASE EXPLAIN THE REASON IN THE COMMENT.
|
|
|
|
##### RECOMMENDED RULE OVERRIDES #####
|
|
|
|
camelcase: off # underscores may come in handy in some cases
|
|
eqeqeq: warn # important check missing from recommended
|
|
keyword-spacing: warn # we require this explicitly
|
|
no-multi-spaces: off # useful for manually align some expression across lines
|
|
prefer-rest-params: off # we need ES5 to be fast too
|
|
prefer-spread: off # we need ES5 to be fast too
|
|
space-before-function-paren: [warn, always] # we require this explicitly
|
|
radix: off # we sometimes do not need to pass a second parameter
|
|
# allow underscores, we still widely use pre-dangle naming in our naming convention
|
|
# e.g. private properties, private functions, module scope shared variables etc.
|
|
no-underscore-dangle: off
|
|
quotes: [warn, single, { allowTemplateLiterals: true }] # force single, but allow template literal
|
|
no-else-return: off # else-return is a common pattern which clearly expresses the control flow
|
|
no-unused-expressions: off # taken over by '@typescript-eslint/no-unused-expressions'
|
|
no-empty-function: off # taken over by '@typescript-eslint/no-empty-function'
|
|
|
|
##### AIRBNB-SPECIFIC RULE OVERRIDES #####
|
|
|
|
class-methods-use-this: off # so empty functions could work
|
|
guard-for-in: off # for-in is a efficient choice for plain objects
|
|
import/export: off # so export declare namespace could work
|
|
import/extensions: off # typescript doesn't support this
|
|
import/no-unresolved: off # TODO: fix internal modules
|
|
import/prefer-default-export: off # prefer named exports
|
|
indent: [error, 4, {
|
|
SwitchCase: 0,
|
|
ignoredNodes: [ # https://stackoverflow.com/a/72897089
|
|
"FunctionExpression > .params[decorators.length > 0]",
|
|
"FunctionExpression > .params > :matches(Decorator, :not(:first-child))",
|
|
"ClassBody.body > PropertyDefinition[decorators.length > 0] > .key",
|
|
]
|
|
}]
|
|
|
|
lines-between-class-members: off # be more lenient on member declarations
|
|
max-classes-per-file: off # helper classes are common
|
|
max-len: [warn, 150] # more lenient on max length per line
|
|
no-console: error # prefer the uniform logging methods
|
|
no-plusplus: off # allow increment/decrement operators
|
|
no-continue: off # allow unlabeled continues
|
|
no-mixed-operators: off # this is just cumbersome
|
|
no-multi-assign: off # it is handy sometimes
|
|
no-nested-ternary: off # it is handy sometimes
|
|
no-param-reassign: off # the output object is passed as parameters all the time
|
|
no-restricted-syntax: off # for-in is a efficient choice for plain objects
|
|
no-return-assign: off # it is handy sometimes
|
|
no-shadow: off # TODO: this throws false-positives?
|
|
no-sequences: off # it is handy sometimes
|
|
no-bitwise: off # we use this extensively
|
|
no-use-before-define: off # just too much work
|
|
no-useless-constructor: off # gives false-positives for empty constructor with parameter properties
|
|
object-curly-newline: off # we want manual control over this
|
|
one-var-declaration-per-line: off # auto-fix has order issues with `one-var`
|
|
prefer-destructuring: off # auto-fix is not smart enough to merge different instances
|
|
linebreak-style: off # we don't enforce this on everyone's dev environment for now
|
|
spaced-comment: off # for license declarations
|
|
default-case-last: off # Place default case clause to first make it more clear that this switch statement has handled all cases
|
|
|
|
##### TYPESCRIPT-SPECIFIC RULE OVERRIDES #####
|
|
|
|
'@typescript-eslint/ban-ts-comment': [error, {
|
|
'ts-expect-error': true,
|
|
'ts-ignore': true,
|
|
'ts-nocheck': true,
|
|
'ts-check': false,
|
|
}]
|
|
'@typescript-eslint/no-unused-expressions': warn
|
|
|
|
# TODO: this is just too much work
|
|
'@typescript-eslint/explicit-module-boundary-types': off
|
|
|
|
# NOTE: We don't want to rely on TS automatic type inference
|
|
'@typescript-eslint/no-inferrable-types': off
|
|
|
|
# TODO: sadly we still rely heavily on legacyCC
|
|
'@typescript-eslint/no-unsafe-assignment': off
|
|
'@typescript-eslint/no-unsafe-call': off
|
|
'@typescript-eslint/no-unsafe-member-access': off
|
|
|
|
'@typescript-eslint/no-unsafe-enum-comparison': off
|
|
|
|
'@typescript-eslint/unbound-method': off # we exploit prototype methods sometimes to acheive better performace
|
|
'@typescript-eslint/no-explicit-any': off # still relevant for some heavily templated usages
|
|
|
|
'@typescript-eslint/no-empty-function': off # may become useful in some parent classes
|
|
|
|
'@typescript-eslint/no-unused-vars': off # may become useful in some parent classes
|
|
'@typescript-eslint/no-non-null-assertion': off # sometimes we just know better than the compiler
|
|
'@typescript-eslint/no-namespace': [warn, { # we need to declare static properties
|
|
allowDeclarations: true,
|
|
allowDefinitionFiles: true
|
|
}]
|
|
'@typescript-eslint/restrict-template-expressions': [warn, { # concatenations of different types are common, e.g. hash calculations
|
|
allowNumber: true,
|
|
allowBoolean: true
|
|
}]
|
|
|
|
'@typescript-eslint/type-annotation-spacing': warn
|
|
|
|
# We choose to use style `... as foo` since it's more common.
|
|
# In the other hand, angle bracket style can be ambiguous with j/tsx syntax.
|
|
# For example, https://babeljs.io/docs/en/babel-plugin-transform-typescript#istsx
|
|
# forbids angle bracket style if `isTSX` is enabled.
|
|
'@typescript-eslint/consistent-type-assertions': [error, {
|
|
assertionStyle: 'as'
|
|
}]
|
|
|
|
# Prefer the interface style.
|
|
'@typescript-eslint/consistent-type-definitions': [error, interface]
|
|
'@typescript-eslint/explicit-function-return-type': [error, {
|
|
allowIIFEs: true, # IIFEs are widely used, writing their signature twice is painful
|
|
}]
|
|
|
|
'@typescript-eslint/no-this-alias': off
|