Skip to content

Commit e52bb32

Browse files
committed
Updated linting rule for single-parameter lambda parameters
1 parent 341d65b commit e52bb32

5 files changed

Lines changed: 40 additions & 36 deletions

File tree

src/CommandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function runDiagnostics(commandLine: ts.ParsedCommandLine) {
136136
}
137137
}
138138

139-
commandLine.errors.forEach((err) => {
139+
commandLine.errors.forEach(err => {
140140
let ignore = false;
141141
// Ignore errors caused by tstl specific compiler options
142142
if (err.code === tsInvalidCompilerOptionErrorCode) {

src/Compiler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export function compile(fileNames: string[], options: CompilerOptions): void {
1313
const checker = program.getTypeChecker();
1414

1515
// Get all diagnostics, ignore unsupported extension
16-
const diagnostics = ts.getPreEmitDiagnostics(program).filter((diag) => diag.code !== 6054);
17-
diagnostics.forEach((diagnostic) => {
16+
const diagnostics = ts.getPreEmitDiagnostics(program).filter(diag => diag.code !== 6054);
17+
diagnostics.forEach(diagnostic => {
1818
if (diagnostic.file) {
1919
const { line, character } =
2020
diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!);
@@ -30,12 +30,12 @@ export function compile(fileNames: string[], options: CompilerOptions): void {
3030
});
3131

3232
// If there are errors dont emit
33-
if (diagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error).length > 0) {
33+
if (diagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error).length > 0) {
3434
console.log("Stopping compilation process because of errors.");
3535
process.exit(1);
3636
}
3737

38-
program.getSourceFiles().forEach((sourceFile) => {
38+
program.getSourceFiles().forEach(sourceFile => {
3939
if (!sourceFile.isDeclarationFile) {
4040
try {
4141
const rootDir = options.rootDir;

src/TSHelper.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export class TSHelper {
2424
}
2525

2626
public static containsStatement(statements: ts.NodeArray<ts.Statement>, kind: ts.SyntaxKind): boolean {
27-
return statements.some((statement) => statement.kind === kind);
27+
return statements.some(statement => statement.kind === kind);
2828
}
2929

3030
public static isFileModule(sourceFile: ts.SourceFile) {
3131
if (sourceFile) {
3232
// Vanilla ts flags files as external module if they have an import or
3333
// export statement, we only check for export statements
34-
return sourceFile.statements.some((statement) =>
34+
return sourceFile.statements.some(statement =>
3535
(ts.getCombinedModifierFlags(statement) & ts.ModifierFlags.Export) !== 0
3636
|| statement.kind === ts.SyntaxKind.ExportAssignment
3737
|| statement.kind === ts.SyntaxKind.ExportDeclaration);
@@ -88,9 +88,11 @@ export class TSHelper {
8888

8989
public static hasCustomDecorator(type: ts.Type, checker: ts.TypeChecker, decorator: string): boolean {
9090
if (type.symbol) {
91-
const comment = type.symbol.getDocumentationComment(checker);
91+
const comments = type.symbol.getDocumentationComment(checker);
9292
const decorators =
93-
comment.filter((_) => _.kind === "text").map((_) => _.text.trim()).filter((_) => _[0] === "!");
93+
comments.filter(comment => comment.kind === "text")
94+
.map(comment => comment.text.trim())
95+
.filter(comment => comment[0] === "!");
9496
return decorators.indexOf(decorator) > -1;
9597
}
9698
return false;

src/Transpiler.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ export class LuaTranspiler {
133133
let result = "";
134134

135135
if (ts.isBlock(node)) {
136-
node.statements.forEach((statement) => {
136+
node.statements.forEach(statement => {
137137
result += this.transpileNode(statement);
138138
});
139139
} else {
140-
node.forEachChild((child) => {
140+
node.forEachChild(child => {
141141
result += this.transpileNode(child);
142142
});
143143
}
@@ -148,7 +148,7 @@ export class LuaTranspiler {
148148
// Transpile a node of unknown kind.
149149
public transpileNode(node: ts.Node): string {
150150
// Ignore declarations
151-
if (node.modifiers && node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.DeclareKeyword)) {
151+
if (node.modifiers && node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword)) {
152152
return "";
153153
}
154154

@@ -224,7 +224,7 @@ export class LuaTranspiler {
224224
const resolvedImportPath = this.getImportPath(importPathWithoutQuotes);
225225
let result = `local ${fileImportTable} = require(${resolvedImportPath})\n`;
226226
this.importCount++;
227-
imports.elements.forEach((element) => {
227+
imports.elements.forEach(element => {
228228
const nameText = element.name.escapedText;
229229
if (element.propertyName) {
230230
result +=
@@ -285,7 +285,7 @@ export class LuaTranspiler {
285285
result += this.makeExport(name, node);
286286
}
287287

288-
node.members.forEach((member) => {
288+
node.members.forEach(member => {
289289
if (member.initializer) {
290290
if (ts.isNumericLiteral(member.initializer)) {
291291
val = parseInt(member.initializer.text);
@@ -456,7 +456,7 @@ export class LuaTranspiler {
456456
this.pushIndent();
457457

458458
this.transpilingSwitch++;
459-
clause.statements.forEach((statement) => {
459+
clause.statements.forEach(statement => {
460460
result += this.transpileNode(statement);
461461
});
462462
this.transpilingSwitch--;
@@ -541,7 +541,7 @@ export class LuaTranspiler {
541541
const declaration = tsEx.findFirstNodeAbove(node, ts.isFunctionDeclaration);
542542
if (declaration && tsEx.isTupleReturnFunction(this.checker.getTypeAtLocation(declaration), this.checker)
543543
&& ts.isArrayLiteralExpression(node.expression)) {
544-
return "return " + node.expression.elements.map((elem) => this.transpileExpression(elem)).join(",");
544+
return "return " + node.expression.elements.map(elem => this.transpileExpression(elem)).join(",");
545545
}
546546

547547
// Otherwise just do a normal return
@@ -832,7 +832,7 @@ export class LuaTranspiler {
832832

833833
public transpileTemplateExpression(node: ts.TemplateExpression) {
834834
const parts = [`"${node.head.text}"`];
835-
node.templateSpans.forEach((span) => {
835+
node.templateSpans.forEach(span => {
836836
const expr = this.transpileExpression(span.expression, true);
837837
if (ts.isTemplateTail(span.literal)) {
838838
parts.push(`tostring(${expr}).."${span.literal.text}"`);
@@ -1038,7 +1038,7 @@ export class LuaTranspiler {
10381038
parameters.push(this.transpileExpression(context));
10391039
}
10401040

1041-
params.forEach((param) => {
1041+
params.forEach(param => {
10421042
parameters.push(this.transpileExpression(param));
10431043
});
10441044

@@ -1158,7 +1158,7 @@ export class LuaTranspiler {
11581158
public transpileVariableStatement(node: ts.VariableStatement): string {
11591159
let result = "";
11601160

1161-
node.declarationList.declarations.forEach((declaration) => {
1161+
node.declarationList.declarations.forEach(declaration => {
11621162
result += this.transpileVariableDeclaration(declaration as ts.VariableDeclaration);
11631163
result += this.makeExport((declaration.name as ts.Identifier).escapedText, node);
11641164
});
@@ -1181,12 +1181,13 @@ export class LuaTranspiler {
11811181
const value = this.transpileExpression(node.initializer);
11821182

11831183
// Disallow ellipsis destruction
1184-
if (node.name.elements.some((elem) => !ts.isBindingElement(elem) || elem.dotDotDotToken !== undefined)) {
1184+
if (node.name.elements.some(elem => !ts.isBindingElement(elem) || elem.dotDotDotToken !== undefined)) {
11851185
throw new TranspileError(`Ellipsis destruction is not allowed.`, node);
11861186
}
11871187

11881188
const vars = node.name.elements.map(
1189-
(element) => ((element as ts.BindingElement).name as ts.Identifier).escapedText).join(",");
1189+
element => ((element as ts.BindingElement).name as ts.Identifier
1190+
).escapedText).join(",");
11901191

11911192
// Don't unpack TupleReturn decorated functions
11921193
if (ts.isCallExpression(node.initializer)
@@ -1277,7 +1278,7 @@ export class LuaTranspiler {
12771278
}
12781279
}
12791280
// Parameters with default values
1280-
const defaultValueParams = node.parameters.filter((declaration) => declaration.initializer !== undefined);
1281+
const defaultValueParams = node.parameters.filter(declaration => declaration.initializer !== undefined);
12811282

12821283
// Build function header
12831284
result += this.indent + `function ${callPath}${methodName}(${paramNames.join(",")})\n`;
@@ -1304,7 +1305,7 @@ export class LuaTranspiler {
13041305
// Find extends class, ignore implements
13051306
let extendsType: ts.ExpressionWithTypeArguments | undefined;
13061307
let noClassOr = false;
1307-
if (node.heritageClauses) { node.heritageClauses.forEach((clause) => {
1308+
if (node.heritageClauses) { node.heritageClauses.forEach(clause => {
13081309
if (clause.token === ts.SyntaxKind.ExtendsKeyword) {
13091310
const superType = this.checker.getTypeAtLocation(clause.types[0]);
13101311
// Ignore purely abstract types (decorated with /** @PureAbstract */)
@@ -1358,12 +1359,12 @@ export class LuaTranspiler {
13581359

13591360
// Get all properties with value
13601361
const properties = node.members.filter(ts.isPropertyDeclaration)
1361-
.filter((_) => _.initializer);
1362+
.filter(member => member.initializer);
13621363

13631364
// Divide properties into static and non-static
1364-
const isStatic = (_) => _.modifiers && _.modifiers.some((__) => __.kind === ts.SyntaxKind.StaticKeyword);
1365+
const isStatic = prop => prop.modifiers && prop.modifiers.some(m => m.kind === ts.SyntaxKind.StaticKeyword);
13651366
const staticFields = properties.filter(isStatic);
1366-
const instanceFields = properties.filter((_) => !isStatic(_));
1367+
const instanceFields = properties.filter(prop => !isStatic(prop));
13671368

13681369
// Add static declarations
13691370
for (const field of staticFields) {
@@ -1387,17 +1388,17 @@ export class LuaTranspiler {
13871388
}
13881389

13891390
// Transpile get accessors
1390-
node.members.filter(ts.isGetAccessor).forEach((getAccessor) => {
1391+
node.members.filter(ts.isGetAccessor).forEach(getAccessor => {
13911392
result += this.transpileGetAccessorDeclaration(getAccessor, className);
13921393
});
13931394

13941395
// Transpile set accessors
1395-
node.members.filter(ts.isSetAccessor).forEach((setAccessor) => {
1396+
node.members.filter(ts.isSetAccessor).forEach(setAccessor => {
13961397
result += this.transpileSetAccessorDeclaration(setAccessor, className);
13971398
});
13981399

13991400
// Transpile methods
1400-
node.members.filter(ts.isMethodDeclaration).forEach((method) => {
1401+
node.members.filter(ts.isMethodDeclaration).forEach(method => {
14011402
result += this.transpileMethodDeclaration(method, `${className}.`);
14021403
});
14031404

@@ -1422,7 +1423,7 @@ export class LuaTranspiler {
14221423
const name = (setAccessor.name as ts.Identifier).escapedText;
14231424

14241425
const paramNames: string[] = ["self"];
1425-
setAccessor.parameters.forEach((param) => {
1426+
setAccessor.parameters.forEach(param => {
14261427
paramNames.push((param.name as ts.Identifier).escapedText as string);
14271428
});
14281429

@@ -1443,7 +1444,7 @@ export class LuaTranspiler {
14431444
const extraInstanceFields = [];
14441445

14451446
const parameters = ["self"];
1446-
node.parameters.forEach((param) => {
1447+
node.parameters.forEach(param => {
14471448
// If param has decorators, add extra instance field
14481449
if (param.modifiers !== undefined) {
14491450
extraInstanceFields.push((param.name as ts.Identifier).escapedText as string);
@@ -1480,7 +1481,7 @@ export class LuaTranspiler {
14801481
public transpileArrayLiteral(node: ts.ArrayLiteralExpression): string {
14811482
const values: string[] = [];
14821483

1483-
node.elements.forEach((child) => {
1484+
node.elements.forEach(child => {
14841485
values.push(this.transpileExpression(child));
14851486
});
14861487

@@ -1490,7 +1491,7 @@ export class LuaTranspiler {
14901491
public transpileObjectLiteral(node: ts.ObjectLiteralExpression): string {
14911492
const properties: string[] = [];
14921493
// Add all property assignments
1493-
node.properties.forEach((element) => {
1494+
node.properties.forEach(element => {
14941495
let name = "";
14951496
if (ts.isIdentifier(element.name)) {
14961497
name = element.name.escapedText as string;
@@ -1514,11 +1515,11 @@ export class LuaTranspiler {
15141515
public transpileFunctionExpression(node: ts.ArrowFunction): string {
15151516
// Build parameter string
15161517
const paramNames: string[] = [];
1517-
node.parameters.forEach((param) => {
1518+
node.parameters.forEach(param => {
15181519
paramNames.push((param.name as ts.Identifier).escapedText as string);
15191520
});
15201521

1521-
const defaultValueParams = node.parameters.filter((declaration) => declaration.initializer !== undefined);
1522+
const defaultValueParams = node.parameters.filter(declaration => declaration.initializer !== undefined);
15221523

15231524
if (ts.isBlock(node.body) || defaultValueParams.length > 0) {
15241525
let result = `function(${paramNames.join(",")})\n`;
@@ -1535,7 +1536,7 @@ export class LuaTranspiler {
15351536
public transpileParameterDefaultValues(params: ts.ParameterDeclaration[]): string {
15361537
let result = "";
15371538

1538-
params.filter((declaration) => declaration.initializer !== undefined).forEach((declaration) => {
1539+
params.filter(declaration => declaration.initializer !== undefined).forEach(declaration => {
15391540
const paramName = (declaration.name as ts.Identifier).escapedText;
15401541
const paramValue = this.transpileExpression(declaration.initializer);
15411542
result += this.indent + `if ${paramName}==nil then ${paramName}=${paramValue} end\n`;

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"jsRules": {},
77
"rules": {
88
"align": [true, "parameters", "statements", "arguments", "members", "elements"],
9+
"arrow-parens": [true, "ban-single-arg-parens"],
910
"class-name": true,
1011
"no-bitwise": false,
1112
"indent": [true, "spaces", 4],

0 commit comments

Comments
 (0)