Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 85 additions & 68 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,3 @@
// https://github.com/ark120202/eslint-config/blob/2c24f13fd99af7ccf29e56d5d936b3ab0f237db6/bases/typescript.js
const typescriptBase = {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-types": [
"error",
{
types: {
Function: null,
CallableFunction: { fixWith: "(...args: any[]) => any" },
NewableFunction: { fixWith: "new (...args: any[]) => any" },
},
},
],
camelcase: "off",
"@typescript-eslint/camelcase": ["error", { properties: "never", ignoreDestructuring: true }],
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-assertions": [
"error",
{ assertionStyle: "as", objectLiteralTypeAssertions: "never" },
],
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", { overrides: { constructors: "no-public" } }],
"@typescript-eslint/generic-type-naming": ["error", "^(T([A-Z][A-Za-z]*)?|U|P|K|V)$"],
"@typescript-eslint/interface-name-prefix": "error",
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-this-alias": "error",
"no-throw-literal": "off",
"@typescript-eslint/no-throw-literal": "error",
"no-constant-condition": "off",
"@typescript-eslint/no-unnecessary-condition": ["error", { ignoreRhs: true, allowConstantLoopConditions: true }],
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "error",
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": ["error", { checkArrowFunctions: false }],
quotes: "off",
"@typescript-eslint/quotes": ["error", "single", { avoidEscape: true, allowTemplateLiterals: false }],
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/require-await": "error",
"@typescript-eslint/restrict-plus-operands": ["error", { checkCompoundAssignments: true }],
"@typescript-eslint/return-await": "error",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "error",
};

module.exports = {
extends: ["plugin:jest/recommended", "plugin:jest/style"],
parserOptions: {
Expand Down Expand Up @@ -149,7 +82,74 @@ module.exports = {
files: "**/*.ts",
extends: ["plugin:@typescript-eslint/base"],
rules: {
...typescriptBase,
// https://github.com/ark120202/eslint-config/blob/2c24f13fd99af7ccf29e56d5d936b3ab0f237db6/bases/typescript.js
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-types": [
"error",
{
types: {
Function: null,
CallableFunction: { fixWith: "(...args: any[]) => any" },
NewableFunction: { fixWith: "new (...args: any[]) => any" },
},
},
],
camelcase: "off",
"@typescript-eslint/camelcase": ["error", { properties: "never", ignoreDestructuring: true }],
"@typescript-eslint/consistent-type-assertions": [
"error",
{ assertionStyle: "as", objectLiteralTypeAssertions: "never" },
],
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{ overrides: { constructors: "no-public" } },
],
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-this-alias": "error",
"no-throw-literal": "off",
"@typescript-eslint/no-throw-literal": "error",
"no-constant-condition": "off",
"@typescript-eslint/no-unnecessary-condition": [
"error",
{ ignoreRhs: true, allowConstantLoopConditions: true },
],
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": "error",
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": ["error", { checkArrowFunctions: false }],
quotes: "off",
"@typescript-eslint/quotes": ["error", "single", { avoidEscape: true, allowTemplateLiterals: false }],
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/require-await": "error",
"@typescript-eslint/restrict-plus-operands": ["error", { checkCompoundAssignments: true }],
"@typescript-eslint/return-await": "error",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "error",
// end of https://github.com/ark120202/eslint-config/blob/2c24f13fd99af7ccf29e56d5d936b3ab0f237db6/bases/typescript.js
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
"@typescript-eslint/ban-types": ["error", { types: { null: null } }],
"@typescript-eslint/no-namespace": ["error", { allowDeclarations: true }],
Expand Down Expand Up @@ -182,6 +182,23 @@ module.exports = {
selector: "enumMember",
format: ["PascalCase"],
},
{
selector: "typeParameter",
format: ["PascalCase"],
prefix: ["T"],
filter: {
regex: "K|V",
match: false,
},
},
{
selector: "interface",
format: ["PascalCase"],
custom: {
regex: "^I[A-Z]",
match: false,
},
},
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/memory_benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BenchmarkKind, MemoryBenchmarkResult, ComparisonInfo, MemoryBenchmarkCategory } from "./benchmark_types";
import { toFixed, json, calculatePercentageChange } from "./util";

export function runMemoryBenchmark(benchmarkFunction: Function): MemoryBenchmarkResult {
export function runMemoryBenchmark(benchmarkFunction: () => void): MemoryBenchmarkResult {
const result: MemoryBenchmarkResult = {
kind: BenchmarkKind.Memory,
benchmarkName: "NO_NAME",
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/memory_benchmarks/graph_cylce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Graph<T extends {}> = Map<T, T[]>;
type Graph<T> = Map<T, T[]>;

function range(start: number, end: number): number[] {
if (start > end) return [];
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function calculatePercentageChange(oldValue: number, newValue: number): n
export const isWindows = package.config.startsWith("\\");

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

Expand Down
22 changes: 16 additions & 6 deletions language-extensions/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
type AnyTable = Record<any, any>;
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/consistent-type-definitions
type AnyNotNil = {};

/**
* Indicates a type is a language extension provided by TypescriptToLua.
* For more information see: https://typescripttolua.github.io/docs/advanced/language-extensions
Expand Down Expand Up @@ -445,7 +449,10 @@ declare type LuaLengthMethod<TReturn> = (() => TReturn) & LuaExtension<"__luaLen
* @param TKey The type of the key to use to access the table.
* @param TValue The type of the value stored in the table.
*/
declare type LuaTableGet<TTable extends object, TKey extends {}, TValue> = ((table: TTable, key: TKey) => TValue) &
declare type LuaTableGet<TTable extends AnyTable, TKey extends AnyNotNil, TValue> = ((
table: TTable,
key: TKey
) => TValue) &
LuaExtension<"__luaTableGetBrand">;

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

/**
Expand All @@ -466,7 +473,7 @@ declare type LuaTableGetMethod<TKey extends {}, TValue> = ((key: TKey) => TValue
* @param TKey The type of the key to use to access the table.
* @param TValue The type of the value to assign to the table.
*/
declare type LuaTableSet<TTable extends object, TKey extends {}, TValue> = ((
declare type LuaTableSet<TTable extends AnyTable, TKey extends AnyNotNil, TValue> = ((
table: TTable,
key: TKey,
value: TValue
Expand All @@ -480,7 +487,7 @@ declare type LuaTableSet<TTable extends object, TKey extends {}, TValue> = ((
* @param TKey The type of the key to use to access the table.
* @param TValue The type of the value to assign to the table.
*/
declare type LuaTableSetMethod<TKey extends {}, TValue> = ((key: TKey, value: TValue) => void) &
declare type LuaTableSetMethod<TKey extends AnyNonNil, TValue> = ((key: TKey, value: TValue) => void) &
LuaExtension<"__luaTableSetMethodBrand">;

/**
Expand All @@ -490,7 +497,7 @@ declare type LuaTableSetMethod<TKey extends {}, TValue> = ((key: TKey, value: TV
* @param TKey The type of the keys used to access the table.
* @param TValue The type of the values stored in the table.
*/
declare interface LuaTable<TKey extends {} = {}, TValue = any> {
declare interface LuaTable<TKey extends AnyTable = AnyNotNil, TValue = any> {
length: LuaLengthMethod<number>;
get: LuaTableGetMethod<TKey, TValue>;
set: LuaTableSetMethod<TKey, TValue>;
Expand All @@ -503,7 +510,10 @@ declare interface LuaTable<TKey extends {} = {}, TValue = any> {
* @param TKey The type of the keys used to access the table.
* @param TValue The type of the values stored in the table.
*/
declare type LuaTableConstructor = (new <TKey extends {} = {}, TValue = any>() => LuaTable<TKey, TValue>) &
declare type LuaTableConstructor = (new <TKey extends AnyNotNil = AnyNotNil, TValue = any>() => LuaTable<
TKey,
TValue
>) &
LuaExtension<"__luaTableNewBrand">;

/**
Expand Down
Loading