Skip to content

Commit 9f7ff5d

Browse files
committed
Enable noUnusedLocals and noUnusedParameters
1 parent 6e79372 commit 9f7ff5d

File tree

11 files changed

+41
-39
lines changed

11 files changed

+41
-39
lines changed

build_lualib.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const options: tstl.CompilerOptions = {
1010
types: [],
1111
target: ts.ScriptTarget.ESNext,
1212
lib: ["lib.esnext.d.ts"],
13+
noUnusedLocals: true,
14+
noUnusedParameters: true,
1315

1416
outDir: path.join(__dirname, "./dist/lualib"),
1517
rootDir: path.join(__dirname, "./src/lualib"),

src/LuaTransformer.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class LuaTransformer {
114114
tstl.createReturnStatement([this.transformExpression(statement.expression)])
115115
);
116116
} else {
117-
this.pushScope(ScopeType.File, node);
117+
this.pushScope(ScopeType.File);
118118

119119
this.isModule = tsHelper.isFileModule(node);
120120
statements = this.performHoisting(this.transformStatements(node.statements));
@@ -217,14 +217,14 @@ export class LuaTransformer {
217217
}
218218

219219
public transformBlock(block: ts.Block): tstl.Block {
220-
this.pushScope(ScopeType.Block, block);
220+
this.pushScope(ScopeType.Block);
221221
const statements = this.performHoisting(this.transformStatements(block.statements));
222222
this.popScope();
223223
return tstl.createBlock(statements, block);
224224
}
225225

226226
public transformBlockAsDoStatement(block: ts.Block): StatementVisitResult {
227-
this.pushScope(ScopeType.Block, block);
227+
this.pushScope(ScopeType.Block);
228228
const statements = this.performHoisting(this.transformStatements(block.statements));
229229
this.popScope();
230230
return tstl.createDoStatement(statements, block);
@@ -1289,7 +1289,7 @@ export class LuaTransformer {
12891289
spreadIdentifier?: tstl.Identifier
12901290
): [tstl.Statement[], Scope]
12911291
{
1292-
this.pushScope(ScopeType.Function, body);
1292+
this.pushScope(ScopeType.Function);
12931293

12941294
const headerStatements = [];
12951295

@@ -1497,7 +1497,7 @@ export class LuaTransformer {
14971497

14981498
// Transform moduleblock to block and visit it
14991499
if (tsHelper.moduleHasEmittedBody(statement)) {
1500-
this.pushScope(ScopeType.Block, statement);
1500+
this.pushScope(ScopeType.Block);
15011501
let statements = ts.isModuleBlock(statement.body)
15021502
? this.transformStatements(statement.body.statements)
15031503
: this.transformModuleDeclaration(statement.body);
@@ -1805,11 +1805,11 @@ export class LuaTransformer {
18051805
return this.createLocalOrExportedOrGlobalDeclaration(name, functionExpression, functionDeclaration);
18061806
}
18071807

1808-
public transformTypeAliasDeclaration(statement: ts.TypeAliasDeclaration): StatementVisitResult {
1808+
public transformTypeAliasDeclaration(_statement: ts.TypeAliasDeclaration): StatementVisitResult {
18091809
return undefined;
18101810
}
18111811

1812-
public transformInterfaceDeclaration(statement: ts.InterfaceDeclaration): StatementVisitResult {
1812+
public transformInterfaceDeclaration(_statement: ts.InterfaceDeclaration): StatementVisitResult {
18131813
return undefined;
18141814
}
18151815

@@ -2077,7 +2077,7 @@ export class LuaTransformer {
20772077
}
20782078

20792079
public transformIfStatement(statement: ts.IfStatement): StatementVisitResult {
2080-
this.pushScope(ScopeType.Conditional, statement.thenStatement);
2080+
this.pushScope(ScopeType.Conditional);
20812081
const condition = this.transformExpression(statement.expression);
20822082
const statements = this.performHoisting(this.transformBlockOrStatement(statement.thenStatement));
20832083
this.popScope();
@@ -2087,7 +2087,7 @@ export class LuaTransformer {
20872087
const elseStatement = this.transformIfStatement(statement.elseStatement) as tstl.IfStatement;
20882088
return tstl.createIfStatement(condition, ifBlock, elseStatement);
20892089
} else {
2090-
this.pushScope(ScopeType.Conditional, statement.elseStatement);
2090+
this.pushScope(ScopeType.Conditional);
20912091
const elseStatements = this.performHoisting(this.transformBlockOrStatement(statement.elseStatement));
20922092
this.popScope();
20932093
const elseBlock = tstl.createBlock(elseStatements);
@@ -2187,7 +2187,7 @@ export class LuaTransformer {
21872187
loop: ts.WhileStatement | ts.DoStatement | ts.ForStatement | ts.ForOfStatement | ts.ForInOrOfStatement
21882188
): tstl.Statement[]
21892189
{
2190-
this.pushScope(ScopeType.Loop, loop.statement);
2190+
this.pushScope(ScopeType.Loop);
21912191
const body = this.performHoisting(this.transformBlockOrStatement(loop.statement));
21922192
const scope = this.popScope();
21932193
const scopeId = scope.id;
@@ -2401,7 +2401,7 @@ export class LuaTransformer {
24012401
throw TSTLErrors.UnsupportedForTarget("Switch statements", this.luaTarget, statement);
24022402
}
24032403

2404-
this.pushScope(ScopeType.Switch, statement);
2404+
this.pushScope(ScopeType.Switch);
24052405

24062406
// Give the switch a unique name to prevent nested switches from acting up.
24072407
const scope = this.peekScope();
@@ -2542,7 +2542,7 @@ export class LuaTransformer {
25422542
);
25432543
}
25442544

2545-
public transformEmptyStatement(statement: ts.EmptyStatement): StatementVisitResult {
2545+
public transformEmptyStatement(_statement: ts.EmptyStatement): StatementVisitResult {
25462546
return undefined;
25472547
}
25482548

@@ -5135,7 +5135,7 @@ export class LuaTransformer {
51355135
return this.scopeStack[this.scopeStack.length - 1];
51365136
}
51375137

5138-
protected pushScope(scopeType: ScopeType, node: ts.Node): void {
5138+
protected pushScope(scopeType: ScopeType): void {
51395139
this.scopeStack.push({
51405140
type: scopeType,
51415141
id: this.genVarCounter,

src/Transpile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { LuaTransformer } from "./LuaTransformer";
77
import { TranspileError } from "./TranspileError";
88

99
function getCustomTransformers(
10-
program: ts.Program,
10+
_program: ts.Program,
1111
customTransformers: ts.CustomTransformers,
1212
onSourceFile: (sourceFile: ts.SourceFile) => void
1313
): ts.CustomTransformers {

test/transpile/outFile.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test("should support outFile with declaration", () => {
3333

3434
test("should resolve outFile relative to base directory", () => {
3535
jest.spyOn(process, "cwd").mockReturnValue(__dirname);
36-
const { diagnostics, emittedFiles, emitResult } = buildVirtualProject([inputFilePath], {
36+
const { diagnostics, emittedFiles } = buildVirtualProject([inputFilePath], {
3737
outFile: "output.script",
3838
outDir: "out",
3939
declaration: true,

test/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"baseUrl": ".",
44
"paths": { "*": ["types/*"] },
55
"strict": true,
6+
"noUnusedLocals": true,
7+
"noUnusedParameters": true,
68
"target": "es2017",
79
"lib": ["es2017"],
810
"types": ["node", "jest"],

test/unit/error.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test("throwString", () => {
88

99
test("throwError", () => {
1010
expect(() => {
11-
const lua = util.transpileString(`throw Error("Some Error")`);
11+
util.transpileString(`throw Error("Some Error")`);
1212
}).toThrowExactError(TSTLErrors.InvalidThrowExpression(util.nodeStub));
1313
});
1414

test/unit/lualib/lualib.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,26 @@ test.each([
190190
});
191191

192192
test.each([
193-
{ inp: [], expected: "" },
194-
{ inp: ["test1"], expected: "test1" },
195-
{ inp: ["test1", "test2"], expected: "test1,test2" },
196-
{ inp: ["test1", "test2"], expected: "test1;test2", seperator: ";" },
197-
{ inp: ["test1", "test2"], expected: "test1test2", seperator: "" },
198-
])("array.join (%p)", ({ inp, expected, seperator }) => {
199-
let seperatorLua;
200-
if (seperator === "") {
201-
seperatorLua = '""';
202-
} else if (seperator) {
203-
seperatorLua = '"' + seperator + '"';
193+
{ inp: [] },
194+
{ inp: ["test1"] },
195+
{ inp: ["test1", "test2"] },
196+
{ inp: ["test1", "test2"], separator: ";" },
197+
{ inp: ["test1", "test2"], separator: "" },
198+
])("array.join (%p)", ({ inp, separator }) => {
199+
let separatorLua;
200+
if (separator === "") {
201+
separatorLua = '""';
202+
} else if (separator) {
203+
separatorLua = '"' + separator + '"';
204204
} else {
205-
seperatorLua = "";
205+
separatorLua = "";
206206
}
207207
const result = util.transpileAndExecute(
208208
`let joinTestTable = ${JSON.stringify(inp)};
209-
return joinTestTable.join(${seperatorLua});`,
209+
return joinTestTable.join(${separatorLua});`,
210210
);
211211

212-
const joinedInp = inp.join(seperator);
212+
const joinedInp = inp.join(separator);
213213
expect(result).toBe(joinedInp);
214214
});
215215

test/unit/modules.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as util from "../util";
44

55
test("defaultImport", () => {
66
expect(() => {
7-
const lua = util.transpileString(`import TestClass from "test"`);
7+
util.transpileString(`import TestClass from "test"`);
88
}).toThrowExactError(TSTLErrors.DefaultImportsNotSupported(util.nodeStub));
99
});
1010

test/unit/objectLiteral.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as util from "../util";
2-
const fs = require("fs");
32

43
test.each([
54
{ inp: `{a:3,b:"4"}`, out: '{\n a = 3,\n b = "4",\n}' },

test/unit/string.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,11 @@ test.each([
215215
expect(result).toBe(inp.substr(start, end));
216216
});
217217

218-
test.each([{ inp: "", expected: 0 }, { inp: "h", expected: 1 }, { inp: "hello", expected: 5 }])(
219-
"string.length (%p)",
220-
({ inp, expected }) => {
221-
const result = util.transpileAndExecute(`return "${inp}".length`);
218+
test.each(["", "h", "hello"])("string.length (%p)", input => {
219+
const result = util.transpileAndExecute(`return "${input}".length`);
222220

223-
expect(result).toBe(inp.length);
224-
},
225-
);
221+
expect(result).toBe(input.length);
222+
});
226223

227224
test.each(["hello TEST"])("string.toLowerCase (%p)", inp => {
228225
const result = util.transpileAndExecute(`return "${inp}".toLowerCase()`);

0 commit comments

Comments
 (0)