Skip to content

Commit

Permalink
Use optional chaining and linter improvements (smogon#6422)
Browse files Browse the repository at this point in the history
This is mostly just a follow up to smogon#6342.

`prefer-optional-chaining` was turned on and fixed in every location it
complained in. The transformed function [0] looks expensive from a
glance but from skimming through the replaced sites it doesn't appear
to be ran in any important place, so it should be OK.

The linter improvements are:
- Increase linter performance
	- Make `full-lint` and `lint` write to different caches so we
	  avoid overwriting their caches since they're different configs
	- Change husky's hook to `npm run lint` so as to write to the
	  same cache
	- Remove `@typescript-eslint/eslint-plugin-tslint` which is
	  essentially a wrapper to TSLint because the rules aren't worth
	  running another linter
- Convert `.eslintrc.json` and `.eslintrc-syntax.json` to two spaces
  rather than four tabs to respect PS' `.editorconfig`
- Rename `fulllint` to `full-lint` to ease spelling it

[0] - https://pastie.io/mmtxpf.js (prettified)
  • Loading branch information
thejetou authored Mar 6, 2020
1 parent 242e9a3 commit 8aa4f05
Show file tree
Hide file tree
Showing 36 changed files with 471 additions and 476 deletions.
61 changes: 0 additions & 61 deletions .eslintrc

This file was deleted.

285 changes: 285 additions & 0 deletions .eslintrc-no-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "script",
"ecmaFeatures": {
"globalReturn": true
}
},
"env": {
"es6": true,
"node": true
},
"globals": {
"Config": false, "Monitor": false, "toID": false, "Dex": false, "LoginServer": false,
"Users": false, "Punishments": false, "Rooms": false, "Verifier": false, "Chat": false,
"Tournaments": false, "IPTools": false, "Sockets": false, "TeamValidator": false,
"TeamValidatorAsync": false, "Ladders": false
},
"ignorePatterns": [
"logs/",
"node_modules/",
".*-dist/",
"tools/set-import/importer.js",
"tools/set-import/sets",
"server/global-variables.d.ts",
"sim/global-variables.d.ts"
],
"extends": "eslint:recommended",
"rules": {
"no-cond-assign": ["error", "except-parens"],
"no-console": "off",
"no-control-regex": "off",
"no-empty": ["error", {"allowEmptyCatch": true}],
"no-inner-declarations": ["error", "functions"],
"require-atomic-updates": "off",
"valid-jsdoc": "off",

"eol-last": ["error", "always"],
"array-callback-return": "error",
"block-scoped-var": "error",
"comma-dangle": ["error", {"arrays": "always-multiline", "objects": "always-multiline", "imports": "always-multiline", "exports": "always-multiline", "functions": "ignore"}],
"complexity": "off",
"consistent-return": "off",
"curly": ["error", "multi-line", "consistent"],
"default-case": "off",
"dot-location": ["error", "property"],
"dot-notation": "off",
"eqeqeq": "error",
"guard-for-in": "off",
"no-caller": "error",
"no-case-declarations": "off",
"no-div-regex": "error",
"no-else-return": "off",
"no-labels": ["error", {"allowLoop": true, "allowSwitch": true}],
"no-eval": "off",
"no-implied-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "warn",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "error",
"no-implicit-coercion": "off",
"no-invalid-this": "off",
"no-iterator": "error",
"no-lone-blocks": "off",
"no-loop-func": "off",
"no-magic-numbers": "off",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-new": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-proto": "error",
"no-return-assign": ["error", "except-parens"],
"no-self-compare": "error",
"no-sequences": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-useless-call": "error",
"no-useless-concat": "off",
"no-void": "off",
"no-warning-comments": "off",
"no-with": "error",
"radix": ["warn", "as-needed"],
"vars-on-top": "off",
"wrap-iife": ["error", "inside"],
"yoda": ["error", "never", { "exceptRange": true }],

"strict": ["error", "global"],
"init-declarations": "off",
"no-shadow": "off",
"no-label-var": "error",
"no-restricted-globals": ["error", "Proxy", "Reflect", "Symbol", "WeakSet"],
"no-shadow-restricted-names": "error",
"no-undef": ["error", {"typeof": true}],
"no-undefined": "off",
"no-unused-vars": ["warn", {"args": "none"}],
"no-use-before-define": ["error", {"functions": false, "classes": false, "variables": false}],

"callback-return": [2, ["callback", "cb", "done"]],
"no-mixed-requires": "error",
"no-new-require": "error",
"no-path-concat": "off",
"no-process-env": "off",
"no-process-exit": "off",
"no-restricted-modules": ["error", "moment", "request", "sugar"],
"no-sync": "off",

"array-bracket-spacing": ["error", "never"],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", {"allowSingleLine": true}],
"camelcase": "off",
"comma-spacing": ["error", {"before": false, "after": true}],
"comma-style": ["error", "last"],
"computed-property-spacing": ["error", "never"],
"consistent-this": "off",
"func-names": "off",
"func-style": "off",
"id-length": "off",
"id-match": "off",
"indent": ["error", "tab"],
"key-spacing": "error",
"lines-around-comment": "off",
"max-nested-callbacks": "off",
"max-statements-per-line": "off",
"new-cap": ["error", {"newIsCap": true, "capIsNew": false}],
"new-parens": "error",
"padding-line-between-statements": "off",
"no-array-constructor": "error",
"no-continue": "off",
"no-inline-comments": "off",
"no-lonely-if": "off",
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"no-multiple-empty-lines": ["error", {"max": 2, "maxEOF": 1}],
"no-negated-condition": "off",
"no-nested-ternary": "off",
"no-new-object": "error",
"func-call-spacing": "error",
"no-ternary": "off",
"no-trailing-spaces": ["error", {"ignoreComments": false}],
"no-underscore-dangle": "off",
"no-unneeded-ternary": "error",
"object-curly-spacing": ["error", "never"],
"object-shorthand": ["error", "methods"],
"one-var": "off",
"operator-assignment": "off",
"operator-linebreak": ["error", "after"],
"padded-blocks": ["error", "never"],
"quote-props": "off",
"quotes": "off",
"require-jsdoc": "off",
"semi-spacing": ["error", {"before": false, "after": true}],
"semi": ["error", "always"],
"sort-vars": "off",
"keyword-spacing": ["error", {"before": true, "after": true}],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never"}],
"space-in-parens": ["error", "never"],
"space-infix-ops": "error",
"space-unary-ops": ["error", {"words": true, "nonwords": false}],
"wrap-regex": "off",

"arrow-parens": "off",
"arrow-spacing": ["error", {"before": true, "after": true}],
"no-confusing-arrow": "off",
"no-useless-computed-key": "error",
"no-useless-rename": "error",
"no-var": "error",
"prefer-arrow-callback": "off",
"rest-spread-spacing": ["error", "never"],
"template-curly-spacing": ["error", "never"],
"no-restricted-syntax": ["error", "WithStatement"],

"no-constant-condition": ["error", {"checkLoops": false}]
},
"overrides": [
{
"files": ["./lib/*.ts", "./server/**/*.ts", "./sim/**/*.ts", "./tools/set-import/*.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"tsconfigRootDir": ".",
"project": ["./tsconfig.json"]
},
"extends": [
"plugin:@typescript-eslint/recommended"
],
"plugins": [
"import",
"jsdoc"
],
"rules": {
"@typescript-eslint/indent": ["error", "tab", {"SwitchCase": 0, "flatTernaryExpressions": true}],
"@typescript-eslint/consistent-type-assertions": ["error", {"assertionStyle": "as"}],
"@typescript-eslint/no-dupe-class-members": "error",
"@typescript-eslint/prefer-regexp-exec": "off",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/prefer-string-starts-ends-with": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/semi": [
"error",
"always"
],
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "error",
"import/no-extraneous-dependencies": "error",
"jsdoc/no-types": "error",
"new-parens": "off",
"no-dupe-class-members": "off",
"operator-linebreak": "off",
"indent": "off",
"prefer-const": ["error", {
"destructuring": "all"
}],
"comma-dangle": ["error", "only-multiline", {
"objects": "always",
"arrays": "always",
"functions": "never"
}],
"no-unused-expressions": ["error", {"allowTernary": true}],
"no-prototype-builtins":"off",
"max-len": ["warn", {"code": 120, "tabWidth": 0, "ignorePattern": "^\\s*(// \\s*)?((let |const )?[a-zA-Z0-9$.]+ \\+?=>? (\\$\\()?|(return |throw )?(new )?([a-zA-Z0-9$.]+\\()?|Chat.html)?['\"`]"}],
"constructor-super": "error",
"max-classes-per-file": "off",
"no-bitwise": "off",
"no-debugger": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-fallthrough": "off",
"no-redeclare": "error",
"no-return-await": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-undef-init": "off",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"prefer-object-spread": "off",
"spaced-comment": ["error", "always", {"exceptions": ["*"]}],
"use-isnan": "error",
"valid-typeof": "off"
}
},
{
"env": {
"mocha": true
},
"files": ["test/**/*.js"],
"globals": {
"BattleEngine": false
}
}
]
}
Loading

0 comments on commit 8aa4f05

Please sign in to comment.