Skip to content

Commit d4d27cf

Browse files
committed
Enable more eslint rules
1 parent 66e7c98 commit d4d27cf

File tree

24 files changed

+69
-40
lines changed

24 files changed

+69
-40
lines changed

.eslintrc.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ module.exports = {
7373
"arrow-body-style": "error",
7474
curly: ["error", "multi-line"],
7575
eqeqeq: ["error", "always", { null: "ignore" }],
76-
"id-match": "error",
7776
"no-caller": "error",
7877
"no-cond-assign": "error",
7978
"no-debugger": "error",
@@ -87,6 +86,32 @@ module.exports = {
8786
"prefer-const": ["error", { destructuring: "all" }],
8887
radix: "error",
8988
"use-isnan": "error",
89+
"object-shorthand": [
90+
"error",
91+
"always",
92+
{ avoidQuotes: true, ignoreConstructors: false, avoidExplicitReturnArrows: true },
93+
],
94+
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "SequenceExpression"],
95+
"spaced-comment": [
96+
"error",
97+
"always",
98+
{
99+
line: { exceptions: ["-", "+"], markers: ["=", "!", "/"] },
100+
block: { exceptions: ["-", "+"], markers: ["=", "!", ":", "::"], balanced: true },
101+
},
102+
],
103+
"no-delete-var": ["error"],
104+
"no-label-var": ["error"],
105+
yoda: ["error"],
106+
"prefer-destructuring": [
107+
"error",
108+
{
109+
VariableDeclarator: { array: false, object: true },
110+
AssignmentExpression: { array: false, object: false },
111+
},
112+
{ enforceForRenamedProperties: false },
113+
],
114+
"prefer-numeric-literals": ["error"],
90115

91116
"import/no-default-export": "error",
92117
},
@@ -132,6 +157,7 @@ module.exports = {
132157
{
133158
files: "src/lualib/**/*.ts",
134159
rules: {
160+
"no-restricted-syntax": ["error", "LabeledStatement", "SequenceExpression"],
135161
"@typescript-eslint/no-throw-literal": "off",
136162
"@typescript-eslint/prefer-optional-chain": "off",
137163
},

src/cli/parse.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ export const optionDeclarations: CommandLineOption[] = [
7171

7272
export function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine): ParsedCommandLine {
7373
let hasRootLevelOptions = false;
74-
for (const key in parsedConfigFile.raw) {
75-
const option = optionDeclarations.find(option => option.name === key);
74+
for (const [name, rawValue] of Object.entries(parsedConfigFile.raw)) {
75+
const option = optionDeclarations.find(option => option.name === name);
7676
if (!option) continue;
7777

7878
if (parsedConfigFile.raw.tstl === undefined) parsedConfigFile.raw.tstl = {};
79-
parsedConfigFile.raw.tstl[key] = parsedConfigFile.raw[key];
79+
parsedConfigFile.raw.tstl[name] = rawValue;
8080
hasRootLevelOptions = true;
8181
}
8282

@@ -85,16 +85,16 @@ export function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine):
8585
parsedConfigFile.errors.push(cliDiagnostics.tstlOptionsAreMovingToTheTstlObject(parsedConfigFile.raw.tstl));
8686
}
8787

88-
for (const key in parsedConfigFile.raw.tstl) {
89-
const option = optionDeclarations.find(option => option.name === key);
88+
for (const [name, rawValue] of Object.entries(parsedConfigFile.raw.tstl)) {
89+
const option = optionDeclarations.find(option => option.name === name);
9090
if (!option) {
91-
parsedConfigFile.errors.push(cliDiagnostics.unknownCompilerOption(key));
91+
parsedConfigFile.errors.push(cliDiagnostics.unknownCompilerOption(name));
9292
continue;
9393
}
9494

95-
const { error, value } = readValue(option, parsedConfigFile.raw.tstl[key]);
95+
const { error, value } = readValue(option, rawValue);
9696
if (error) parsedConfigFile.errors.push(error);
97-
if (parsedConfigFile.options[key] === undefined) parsedConfigFile.options[key] = value;
97+
if (parsedConfigFile.options[name] === undefined) parsedConfigFile.options[name] = value;
9898
}
9999
}
100100

src/lualib/Map.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Map = class Map<K, V> {
2323
if (result.done) {
2424
break;
2525
}
26+
// eslint-disable-next-line prefer-destructuring
2627
const value: [K, V] = result.value; // Ensures index is offset when tuple is accessed
2728
this.set(value[0], value[1]);
2829
}
@@ -114,8 +115,7 @@ Map = class Map<K, V> {
114115
}
115116

116117
public entries(): IterableIterator<[K, V]> {
117-
const items = this.items;
118-
const nextKey = this.nextKey;
118+
const { items, nextKey } = this;
119119
let key = this.firstKey;
120120
return {
121121
[Symbol.iterator](): IterableIterator<[K, V]> {
@@ -130,7 +130,7 @@ Map = class Map<K, V> {
130130
}
131131

132132
public keys(): IterableIterator<K> {
133-
const nextKey = this.nextKey;
133+
const { nextKey } = this;
134134
let key = this.firstKey;
135135
return {
136136
[Symbol.iterator](): IterableIterator<K> {
@@ -145,8 +145,7 @@ Map = class Map<K, V> {
145145
}
146146

147147
public values(): IterableIterator<V> {
148-
const items = this.items;
149-
const nextKey = this.nextKey;
148+
const { items, nextKey } = this;
150149
let key = this.firstKey;
151150
return {
152151
[Symbol.iterator](): IterableIterator<V> {

src/lualib/ObjectFromEntries.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function __TS__ObjectFromEntries<T>(
1111
const result = iterator.next();
1212
if (result.done) break;
1313

14+
// eslint-disable-next-line prefer-destructuring
1415
const value: [string, T] = result.value;
1516
obj[value[0]] = value[1];
1617
}

src/lualib/Set.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Set = class Set<T> {
103103
}
104104

105105
public entries(): IterableIterator<[T, T]> {
106-
const nextKey = this.nextKey;
106+
const { nextKey } = this;
107107
let key: T = this.firstKey;
108108
return {
109109
[Symbol.iterator](): IterableIterator<[T, T]> {
@@ -118,7 +118,7 @@ Set = class Set<T> {
118118
}
119119

120120
public keys(): IterableIterator<T> {
121-
const nextKey = this.nextKey;
121+
const { nextKey } = this;
122122
let key: T = this.firstKey;
123123
return {
124124
[Symbol.iterator](): IterableIterator<T> {
@@ -133,7 +133,7 @@ Set = class Set<T> {
133133
}
134134

135135
public values(): IterableIterator<T> {
136-
const nextKey = this.nextKey;
136+
const { nextKey } = this;
137137
let key: T = this.firstKey;
138138
return {
139139
[Symbol.iterator](): IterableIterator<T> {

src/lualib/WeakMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ WeakMap = class WeakMap<K extends object, V> {
1717
if (result.done) {
1818
break;
1919
}
20+
// eslint-disable-next-line prefer-destructuring
2021
const value: [K, V] = result.value; // Ensures index is offset when tuple is accessed
2122
this.items.set(value[0], value[1]);
2223
}

src/transformation/builtins/array.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function transformArrayPrototypeCall(
99
context: TransformationContext,
1010
node: PropertyCallExpression
1111
): lua.CallExpression | undefined {
12-
const expression = node.expression;
12+
const { expression } = node;
1313
const signature = context.checker.getResolvedSignature(node);
1414
const params = transformArguments(context, node.arguments, signature);
1515
const caller = context.transformExpression(expression.expression);

src/transformation/builtins/function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function transformFunctionPrototypeCall(
99
context: TransformationContext,
1010
node: PropertyCallExpression
1111
): lua.CallExpression | undefined {
12-
const expression = node.expression;
12+
const { expression } = node;
1313
const callerType = context.checker.getTypeAtLocation(expression.expression);
1414
if (getFunctionContextType(context, callerType) === ContextType.Void) {
1515
context.diagnostics.push(unsupportedSelfFunctionConversion(node));

src/transformation/builtins/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function transformGlobalCall(
1212
const signature = context.checker.getResolvedSignature(node);
1313
const parameters = transformArguments(context, node.arguments, signature);
1414
const expressionType = context.checker.getTypeAtLocation(node.expression);
15-
const name = expressionType.symbol.name;
15+
const { name } = expressionType.symbol;
1616
switch (name) {
1717
case "SymbolConstructor":
1818
return transformLuaLibFunction(context, LuaLibFeature.Symbol, node, ...parameters);

src/transformation/builtins/math.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function transformMathCall(
3434
context: TransformationContext,
3535
node: PropertyCallExpression
3636
): lua.Expression | undefined {
37-
const expression = node.expression;
37+
const { expression } = node;
3838
const signature = context.checker.getResolvedSignature(node);
3939
const params = transformArguments(context, node.arguments, signature);
4040

0 commit comments

Comments
 (0)