Skip to content

Commit 1945d93

Browse files
authored
Update TS and ESLint (#1027)
* Upgrade to TS 4.3 * Upgrade eslint * npm audit fix * Fixed build issue * Fixed issue with benchmark json type
1 parent 2ff677c commit 1945d93

30 files changed

+1416
-1181
lines changed

.eslintrc.js

Lines changed: 85 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,3 @@
1-
// https://github.com/ark120202/eslint-config/blob/2c24f13fd99af7ccf29e56d5d936b3ab0f237db6/bases/typescript.js
2-
const typescriptBase = {
3-
"@typescript-eslint/adjacent-overload-signatures": "error",
4-
"@typescript-eslint/array-type": "error",
5-
"@typescript-eslint/await-thenable": "error",
6-
"@typescript-eslint/ban-types": [
7-
"error",
8-
{
9-
types: {
10-
Function: null,
11-
CallableFunction: { fixWith: "(...args: any[]) => any" },
12-
NewableFunction: { fixWith: "new (...args: any[]) => any" },
13-
},
14-
},
15-
],
16-
camelcase: "off",
17-
"@typescript-eslint/camelcase": ["error", { properties: "never", ignoreDestructuring: true }],
18-
"@typescript-eslint/class-name-casing": "error",
19-
"@typescript-eslint/consistent-type-assertions": [
20-
"error",
21-
{ assertionStyle: "as", objectLiteralTypeAssertions: "never" },
22-
],
23-
"@typescript-eslint/consistent-type-definitions": "error",
24-
"@typescript-eslint/explicit-member-accessibility": ["error", { overrides: { constructors: "no-public" } }],
25-
"@typescript-eslint/generic-type-naming": ["error", "^(T([A-Z][A-Za-z]*)?|U|P|K|V)$"],
26-
"@typescript-eslint/interface-name-prefix": "error",
27-
"no-array-constructor": "off",
28-
"@typescript-eslint/no-array-constructor": "error",
29-
"@typescript-eslint/no-empty-interface": "error",
30-
"@typescript-eslint/no-extra-non-null-assertion": "error",
31-
"@typescript-eslint/no-extraneous-class": "error",
32-
"@typescript-eslint/no-floating-promises": "error",
33-
"@typescript-eslint/no-for-in-array": "error",
34-
"@typescript-eslint/no-inferrable-types": "error",
35-
"@typescript-eslint/no-misused-new": "error",
36-
"@typescript-eslint/no-misused-promises": "error",
37-
"@typescript-eslint/no-namespace": "error",
38-
"@typescript-eslint/no-require-imports": "error",
39-
"@typescript-eslint/no-this-alias": "error",
40-
"no-throw-literal": "off",
41-
"@typescript-eslint/no-throw-literal": "error",
42-
"no-constant-condition": "off",
43-
"@typescript-eslint/no-unnecessary-condition": ["error", { ignoreRhs: true, allowConstantLoopConditions: true }],
44-
"@typescript-eslint/no-unnecessary-qualifier": "error",
45-
"@typescript-eslint/no-unnecessary-type-arguments": "error",
46-
"@typescript-eslint/no-unnecessary-type-assertion": "error",
47-
"no-unused-expressions": "off",
48-
"@typescript-eslint/no-unused-expressions": "error",
49-
"no-useless-constructor": "off",
50-
"@typescript-eslint/no-useless-constructor": "error",
51-
"@typescript-eslint/prefer-function-type": "error",
52-
"@typescript-eslint/prefer-includes": "error",
53-
"@typescript-eslint/prefer-optional-chain": "error",
54-
"@typescript-eslint/prefer-namespace-keyword": "error",
55-
"@typescript-eslint/prefer-readonly": "error",
56-
"@typescript-eslint/prefer-string-starts-ends-with": "error",
57-
"@typescript-eslint/promise-function-async": ["error", { checkArrowFunctions: false }],
58-
quotes: "off",
59-
"@typescript-eslint/quotes": ["error", "single", { avoidEscape: true, allowTemplateLiterals: false }],
60-
"@typescript-eslint/require-array-sort-compare": "error",
61-
"@typescript-eslint/require-await": "error",
62-
"@typescript-eslint/restrict-plus-operands": ["error", { checkCompoundAssignments: true }],
63-
"@typescript-eslint/return-await": "error",
64-
"@typescript-eslint/triple-slash-reference": "error",
65-
"@typescript-eslint/unified-signatures": "error",
66-
};
67-
681
module.exports = {
692
extends: ["plugin:jest/recommended", "plugin:jest/style"],
703
parserOptions: {
@@ -149,7 +82,74 @@ module.exports = {
14982
files: "**/*.ts",
15083
extends: ["plugin:@typescript-eslint/base"],
15184
rules: {
152-
...typescriptBase,
85+
// https://github.com/ark120202/eslint-config/blob/2c24f13fd99af7ccf29e56d5d936b3ab0f237db6/bases/typescript.js
86+
"@typescript-eslint/adjacent-overload-signatures": "error",
87+
"@typescript-eslint/array-type": "error",
88+
"@typescript-eslint/await-thenable": "error",
89+
"@typescript-eslint/ban-types": [
90+
"error",
91+
{
92+
types: {
93+
Function: null,
94+
CallableFunction: { fixWith: "(...args: any[]) => any" },
95+
NewableFunction: { fixWith: "new (...args: any[]) => any" },
96+
},
97+
},
98+
],
99+
camelcase: "off",
100+
"@typescript-eslint/camelcase": ["error", { properties: "never", ignoreDestructuring: true }],
101+
"@typescript-eslint/consistent-type-assertions": [
102+
"error",
103+
{ assertionStyle: "as", objectLiteralTypeAssertions: "never" },
104+
],
105+
"@typescript-eslint/consistent-type-definitions": "error",
106+
"@typescript-eslint/explicit-member-accessibility": [
107+
"error",
108+
{ overrides: { constructors: "no-public" } },
109+
],
110+
"no-array-constructor": "off",
111+
"@typescript-eslint/no-array-constructor": "error",
112+
"@typescript-eslint/no-empty-interface": "error",
113+
"@typescript-eslint/no-extra-non-null-assertion": "error",
114+
"@typescript-eslint/no-extraneous-class": "error",
115+
"@typescript-eslint/no-floating-promises": "error",
116+
"@typescript-eslint/no-for-in-array": "error",
117+
"@typescript-eslint/no-inferrable-types": "error",
118+
"@typescript-eslint/no-misused-new": "error",
119+
"@typescript-eslint/no-misused-promises": "error",
120+
"@typescript-eslint/no-namespace": "error",
121+
"@typescript-eslint/no-require-imports": "error",
122+
"@typescript-eslint/no-this-alias": "error",
123+
"no-throw-literal": "off",
124+
"@typescript-eslint/no-throw-literal": "error",
125+
"no-constant-condition": "off",
126+
"@typescript-eslint/no-unnecessary-condition": [
127+
"error",
128+
{ ignoreRhs: true, allowConstantLoopConditions: true },
129+
],
130+
"@typescript-eslint/no-unnecessary-qualifier": "error",
131+
"@typescript-eslint/no-unnecessary-type-arguments": "error",
132+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
133+
"no-unused-expressions": "off",
134+
"@typescript-eslint/no-unused-expressions": "error",
135+
"no-useless-constructor": "off",
136+
"@typescript-eslint/no-useless-constructor": "error",
137+
"@typescript-eslint/prefer-function-type": "error",
138+
"@typescript-eslint/prefer-includes": "error",
139+
"@typescript-eslint/prefer-optional-chain": "error",
140+
"@typescript-eslint/prefer-namespace-keyword": "error",
141+
"@typescript-eslint/prefer-readonly": "error",
142+
"@typescript-eslint/prefer-string-starts-ends-with": "error",
143+
"@typescript-eslint/promise-function-async": ["error", { checkArrowFunctions: false }],
144+
quotes: "off",
145+
"@typescript-eslint/quotes": ["error", "single", { avoidEscape: true, allowTemplateLiterals: false }],
146+
"@typescript-eslint/require-array-sort-compare": "error",
147+
"@typescript-eslint/require-await": "error",
148+
"@typescript-eslint/restrict-plus-operands": ["error", { checkCompoundAssignments: true }],
149+
"@typescript-eslint/return-await": "error",
150+
"@typescript-eslint/triple-slash-reference": "error",
151+
"@typescript-eslint/unified-signatures": "error",
152+
// end of https://github.com/ark120202/eslint-config/blob/2c24f13fd99af7ccf29e56d5d936b3ab0f237db6/bases/typescript.js
153153
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
154154
"@typescript-eslint/ban-types": ["error", { types: { null: null } }],
155155
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
@@ -182,6 +182,23 @@ module.exports = {
182182
selector: "enumMember",
183183
format: ["PascalCase"],
184184
},
185+
{
186+
selector: "typeParameter",
187+
format: ["PascalCase"],
188+
prefix: ["T"],
189+
filter: {
190+
regex: "K|V",
191+
match: false,
192+
},
193+
},
194+
{
195+
selector: "interface",
196+
format: ["PascalCase"],
197+
custom: {
198+
regex: "^I[A-Z]",
199+
match: false,
200+
},
201+
},
185202
],
186203
},
187204
},

benchmark/src/memory_benchmark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BenchmarkKind, MemoryBenchmarkResult, ComparisonInfo, MemoryBenchmarkCategory } from "./benchmark_types";
22
import { toFixed, json, calculatePercentageChange } from "./util";
33

4-
export function runMemoryBenchmark(benchmarkFunction: Function): MemoryBenchmarkResult {
4+
export function runMemoryBenchmark(benchmarkFunction: () => void): MemoryBenchmarkResult {
55
const result: MemoryBenchmarkResult = {
66
kind: BenchmarkKind.Memory,
77
benchmarkName: "NO_NAME",

benchmark/src/memory_benchmarks/graph_cylce.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type Graph<T extends {}> = Map<T, T[]>;
1+
type Graph<T> = Map<T, T[]>;
22

33
function range(start: number, end: number): number[] {
44
if (start > end) return [];

benchmark/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function calculatePercentageChange(oldValue: number, newValue: number): n
1212
export const isWindows = package.config.startsWith("\\");
1313

1414
export const json: {
15-
decode: (this: void, str: string) => {};
15+
decode: (this: void, str: string) => Record<string, unknown> | unknown[];
1616
encode: (this: void, val: any) => string;
1717
} = require("json");
1818

language-extensions/index.d.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
type AnyTable = Record<any, any>;
2+
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/consistent-type-definitions
3+
type AnyNotNil = {};
4+
15
/**
26
* Indicates a type is a language extension provided by TypescriptToLua.
37
* For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
@@ -445,7 +449,10 @@ declare type LuaLengthMethod<TReturn> = (() => TReturn) & LuaExtension<"__luaLen
445449
* @param TKey The type of the key to use to access the table.
446450
* @param TValue The type of the value stored in the table.
447451
*/
448-
declare type LuaTableGet<TTable extends object, TKey extends {}, TValue> = ((table: TTable, key: TKey) => TValue) &
452+
declare type LuaTableGet<TTable extends AnyTable, TKey extends AnyNotNil, TValue> = ((
453+
table: TTable,
454+
key: TKey
455+
) => TValue) &
449456
LuaExtension<"__luaTableGetBrand">;
450457

451458
/**
@@ -455,7 +462,7 @@ declare type LuaTableGet<TTable extends object, TKey extends {}, TValue> = ((tab
455462
* @param TKey The type of the key to use to access the table.
456463
* @param TValue The type of the value stored in the table.
457464
*/
458-
declare type LuaTableGetMethod<TKey extends {}, TValue> = ((key: TKey) => TValue) &
465+
declare type LuaTableGetMethod<TKey extends AnyNotNil, TValue> = ((key: TKey) => TValue) &
459466
LuaExtension<"__luaTableGetMethodBrand">;
460467

461468
/**
@@ -466,7 +473,7 @@ declare type LuaTableGetMethod<TKey extends {}, TValue> = ((key: TKey) => TValue
466473
* @param TKey The type of the key to use to access the table.
467474
* @param TValue The type of the value to assign to the table.
468475
*/
469-
declare type LuaTableSet<TTable extends object, TKey extends {}, TValue> = ((
476+
declare type LuaTableSet<TTable extends AnyTable, TKey extends AnyNotNil, TValue> = ((
470477
table: TTable,
471478
key: TKey,
472479
value: TValue
@@ -480,7 +487,7 @@ declare type LuaTableSet<TTable extends object, TKey extends {}, TValue> = ((
480487
* @param TKey The type of the key to use to access the table.
481488
* @param TValue The type of the value to assign to the table.
482489
*/
483-
declare type LuaTableSetMethod<TKey extends {}, TValue> = ((key: TKey, value: TValue) => void) &
490+
declare type LuaTableSetMethod<TKey extends AnyNonNil, TValue> = ((key: TKey, value: TValue) => void) &
484491
LuaExtension<"__luaTableSetMethodBrand">;
485492

486493
/**
@@ -490,7 +497,7 @@ declare type LuaTableSetMethod<TKey extends {}, TValue> = ((key: TKey, value: TV
490497
* @param TKey The type of the keys used to access the table.
491498
* @param TValue The type of the values stored in the table.
492499
*/
493-
declare interface LuaTable<TKey extends {} = {}, TValue = any> {
500+
declare interface LuaTable<TKey extends AnyTable = AnyNotNil, TValue = any> {
494501
length: LuaLengthMethod<number>;
495502
get: LuaTableGetMethod<TKey, TValue>;
496503
set: LuaTableSetMethod<TKey, TValue>;
@@ -503,7 +510,10 @@ declare interface LuaTable<TKey extends {} = {}, TValue = any> {
503510
* @param TKey The type of the keys used to access the table.
504511
* @param TValue The type of the values stored in the table.
505512
*/
506-
declare type LuaTableConstructor = (new <TKey extends {} = {}, TValue = any>() => LuaTable<TKey, TValue>) &
513+
declare type LuaTableConstructor = (new <TKey extends AnyNotNil = AnyNotNil, TValue = any>() => LuaTable<
514+
TKey,
515+
TValue
516+
>) &
507517
LuaExtension<"__luaTableNewBrand">;
508518

509519
/**

0 commit comments

Comments
 (0)