Skip to content

Commit

Permalink
switch to eslint (cocos#7727)
Browse files Browse the repository at this point in the history
* switch to eslint

* eslint: extends airbnb
  • Loading branch information
YunHsiao authored Nov 9, 2020
1 parent 676c267 commit 32598c2
Show file tree
Hide file tree
Showing 172 changed files with 5,729 additions and 4,718 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
trim_trailing_whitespace = true
173 changes: 0 additions & 173 deletions .eslintrc.json

This file was deleted.

104 changes: 104 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
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

##### 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

##### 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 # typescriptor doesn't support this
import/no-unresolved: off # TODO: fix internal modules
import/prefer-default-export: off # prefer seperate exports
indent: [warn, 4] # we use 4-space convention
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
new-cap: off # some class still doesn't follow this yet
no-underscore-dangle: off # allow underscores
no-plusplus: off # allow increment/decrement operators
no-console: off # allow console statements
no-continue: off # allow unlabeled continues
no-multi-assign: 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

##### TYPESCRIPT-SPECIFIC RULE OVERRIDES #####

# TODO: this is just too much work
'@typescript-eslint/explicit-module-boundary-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/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
}]
42 changes: 0 additions & 42 deletions .jshintrc

This file was deleted.

5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"eslint.validate": [
"javascript",
"typescript"
]
],
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
}
5 changes: 3 additions & 2 deletions @types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

declare const gfx: any;
declare const global: any;

interface Window {

Expand Down Expand Up @@ -62,7 +63,7 @@ interface HTMLElement{
}

type ActiveXObject = new (s: string) => any;
declare var ActiveXObject: ActiveXObject;
declare const ActiveXObject: ActiveXObject;

declare type CompareFunction<T> = (a: T, b: T) => number;

Expand All @@ -81,7 +82,7 @@ declare interface IWritableArrayLike<T> {
[index: number]: T;
}

declare type Constructor<T = {}> = new(...args: any[]) => T;
declare type Constructor<T = unknown> = new(...args: any[]) => T;

declare type Mutable<T> = { -readonly [P in keyof T]: T[P] };

Expand Down
Loading

0 comments on commit 32598c2

Please sign in to comment.