Skip to content

Commit e14c271

Browse files
committed
Fixed style with clang-format
1 parent 450e44c commit e14c271

30 files changed

+605
-1128
lines changed

.clang-format

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ BasedOnStyle: Google
33
IndentWidth: 4
44
TabWidth: 4
55
UseTab: Never
6+
JavaScriptQuotes: Double
67

78
AlignAfterOpenBracket: AlwaysBreak
89
AlignOperands: true
@@ -14,10 +15,11 @@ AllowShortLoopsOnASingleLine: false
1415
AlwaysBreakTemplateDeclarations: true
1516
BinPackArguments: false
1617
BinPackParameters: false
17-
BreakBeforeBraces: Allman
18+
BreakBeforeBraces: Attach
1819
BreakBeforeInheritanceComma: false
20+
BreakBeforeTernaryOperators: true
1921
BreakConstructorInitializersBeforeComma: true
20-
ColumnLimit: 120
22+
ColumnLimit: 140
2123
ConstructorInitializerAllOnOneLineOrOnePerLine: false
2224
ConstructorInitializerIndentWidth: 4
2325
ContinuationIndentWidth: 4

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@
1414
"scripts": {
1515
"build": "tsc -p tsconfig.json && npm run build-lualib",
1616
"build-lualib": "ts-node ./build_lualib.ts",
17-
"test": "tslint -p . && tslint -c ./tslint.json src/lualib/*.ts && npm run build-lualib && ts-node ./test/runner.ts",
17+
"test": "style-check && tslint -c ./tslint.json src/lualib/*.ts && npm run build-lualib && ts-node ./test/runner.ts",
1818
"coverage": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov",
1919
"coverage-html": "nyc npm test && nyc report --reporter=html",
20-
"test-threaded": "tslint -p . && npm run build && ts-node ./test/threaded_runner.ts",
20+
"test-threaded": "style-check && npm run build && ts-node ./test/threaded_runner.ts",
2121
"release-patch": "npm version patch",
2222
"release-minor": "npm version minor",
2323
"release-major": "npm version major",
2424
"preversion": "npm run build && npm test",
2525
"postversion": "git push && git push --tags",
26-
"check": "gts check",
27-
"clean": "gts clean",
28-
"fix": "gts fix"
26+
"style-check": "gts check",
27+
"style-fix": "gts fix"
2928
},
3029
"bin": {
3130
"tstl": "./dist/index.js"

src/CommandLineParser.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { CompilerOptions } from "./CompilerOptions";
2-
31
import * as fs from "fs";
42
import * as path from "path";
53
import * as ts from "typescript";
64
import * as yargs from "yargs";
75

6+
import {CompilerOptions} from "./CompilerOptions";
7+
88
interface ParsedCommandLine extends ts.ParsedCommandLine {
99
options: CompilerOptions;
1010
}
@@ -34,9 +34,7 @@ export const optionDeclarations: YargsOptions = {
3434
},
3535
};
3636

37-
class CLIError extends Error {
38-
39-
}
37+
class CLIError extends Error {}
4038

4139
/**
4240
* Removes defaults from the arguments.
@@ -66,18 +64,19 @@ export function parseCommandLine(args: string[]): ParsedCommandLine {
6664
const [tstlOptions, tstlDefaults] = getYargOptionsWithoutDefaults(optionDeclarations);
6765

6866
const parsedArgs = yargs
69-
.usage("Syntax: tstl [options] [files...]\n\n" +
70-
"In addition to the options listed below you can also pass options" +
71-
"for the typescript compiler (For a list of options use tsc -h).\n" +
72-
"Some tsc options might have no effect.")
73-
.example("tstl path/to/file.ts [...]", "Compile files")
74-
.example("tstl -p path/to/tsconfig.json", "Compile project")
75-
.wrap(yargs.terminalWidth())
76-
.options(tstlOptions)
77-
.fail((msg, err) => {
78-
throw new CLIError(msg);
79-
})
80-
.parse(args);
67+
.usage(
68+
"Syntax: tstl [options] [files...]\n\n" +
69+
"In addition to the options listed below you can also pass options" +
70+
"for the typescript compiler (For a list of options use tsc -h).\n" +
71+
"Some tsc options might have no effect.")
72+
.example("tstl path/to/file.ts [...]", "Compile files")
73+
.example("tstl -p path/to/tsconfig.json", "Compile project")
74+
.wrap(yargs.terminalWidth())
75+
.options(tstlOptions)
76+
.fail((msg, err) => {
77+
throw new CLIError(msg);
78+
})
79+
.parse(args);
8180

8281
let commandLine = ts.parseCommandLine(args);
8382

@@ -93,12 +92,7 @@ export function parseCommandLine(args: string[]): ParsedCommandLine {
9392
const configPath = commandLine.options.project;
9493
const configContents = fs.readFileSync(configPath).toString();
9594
const configJson = ts.parseConfigFileTextToJson(configPath, configContents);
96-
commandLine = ts.parseJsonConfigFileContent(
97-
configJson.config,
98-
ts.sys,
99-
path.dirname(configPath),
100-
commandLine.options
101-
);
95+
commandLine = ts.parseJsonConfigFileContent(configJson.config, ts.sys, path.dirname(configPath), commandLine.options);
10296
}
10397

10498
// Add TSTL options from tsconfig
@@ -125,9 +119,7 @@ export function parseCommandLine(args: string[]): ParsedCommandLine {
125119
return commandLine as ParsedCommandLine;
126120
}
127121

128-
function addTSTLOptions(commandLine: ts.ParsedCommandLine,
129-
additionalArgs?: yargs.Arguments,
130-
forceOverride?: boolean): void {
122+
function addTSTLOptions(commandLine: ts.ParsedCommandLine, additionalArgs?: yargs.Arguments, forceOverride?: boolean): void {
131123
additionalArgs = additionalArgs ? additionalArgs : commandLine.raw;
132124
// Add compiler options that are ignored by TS parsers
133125
if (additionalArgs) {

src/Compiler.ts

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import * as fs from "fs";
22
import * as path from "path";
33
import * as ts from "typescript";
44

5-
import { parseCommandLine } from "./CommandLineParser";
6-
import { CompilerOptions, LuaLibImportKind, LuaTarget } from "./CompilerOptions";
7-
import { createTransformer } from "./TransformerFactory";
8-
import { LuaTranspiler } from "./LuaTranspiler";
9-
5+
import {parseCommandLine} from "./CommandLineParser";
6+
import {CompilerOptions, LuaLibImportKind, LuaTarget} from "./CompilerOptions";
7+
import {LuaTranspiler} from "./LuaTranspiler";
8+
import {createTransformer} from "./TransformerFactory";
109

1110
export function compile(argv: string[]): void {
1211
const commandLine = parseCommandLine(argv);
@@ -24,19 +23,9 @@ export function watchWithOptions(fileNames: string[], options: CompilerOptions):
2423
let config = false;
2524
if (options.project) {
2625
config = true;
27-
host = ts.createWatchCompilerHost(
28-
options.project,
29-
options,
30-
ts.sys,
31-
ts.createSemanticDiagnosticsBuilderProgram
32-
);
26+
host = ts.createWatchCompilerHost(options.project, options, ts.sys, ts.createSemanticDiagnosticsBuilderProgram);
3327
} else {
34-
host = ts.createWatchCompilerHost(
35-
fileNames,
36-
options,
37-
ts.sys,
38-
ts.createSemanticDiagnosticsBuilderProgram
39-
);
28+
host = ts.createWatchCompilerHost(fileNames, options, ts.sys, ts.createSemanticDiagnosticsBuilderProgram);
4029
}
4130

4231
host.afterProgramCreate = program => {
@@ -55,19 +44,13 @@ export function watchWithOptions(fileNames: string[], options: CompilerOptions):
5544
errorDiagnostic.messageText = "Found Errors. Watching for file changes.";
5645
errorDiagnostic.code = 6193;
5746
}
58-
host.onWatchStatusChange(
59-
errorDiagnostic,
60-
host.getNewLine(),
61-
program.getCompilerOptions()
62-
);
47+
host.onWatchStatusChange(errorDiagnostic, host.getNewLine(), program.getCompilerOptions());
6348
};
6449

6550
if (config) {
66-
ts.createWatchProgram(
67-
host as ts.WatchCompilerHostOfConfigFile<ts.SemanticDiagnosticsBuilderProgram>);
51+
ts.createWatchProgram(host as ts.WatchCompilerHostOfConfigFile<ts.SemanticDiagnosticsBuilderProgram>);
6852
} else {
69-
ts.createWatchProgram(
70-
host as ts.WatchCompilerHostOfFilesAndCompilerOptions<ts.SemanticDiagnosticsBuilderProgram>);
53+
ts.createWatchProgram(host as ts.WatchCompilerHostOfFilesAndCompilerOptions<ts.SemanticDiagnosticsBuilderProgram>);
7154
}
7255
}
7356

@@ -81,11 +64,10 @@ export function compileFilesWithOptions(fileNames: string[], options: CompilerOp
8164

8265
const libSource = fs.readFileSync(path.join(path.dirname(require.resolve("typescript")), "lib.es6.d.ts")).toString();
8366

84-
export function transpileString(str: string,
85-
options: CompilerOptions = {
86-
luaLibImport: LuaLibImportKind.Require,
87-
luaTarget: LuaTarget.Lua53,
88-
}): string {
67+
export function transpileString(str: string, options: CompilerOptions = {
68+
luaLibImport: LuaLibImportKind.Require,
69+
luaTarget: LuaTarget.Lua53,
70+
}): string {
8971
const compilerHost = {
9072
directoryExists: () => true,
9173
fileExists: (fileName): boolean => true,

src/Decorator.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
export class Decorator {
2-
32
public static isValid(decoratorKindString: string): boolean {
43
return this.getDecoratorKind(decoratorKindString) !== undefined;
54
}
65

76
public static getDecoratorKind(decoratorKindString: string): DecoratorKind {
87
switch (decoratorKindString.toLowerCase()) {
9-
case "extension": return DecoratorKind.Extension;
10-
case "metaextension": return DecoratorKind.MetaExtension;
11-
case "customconstructor": return DecoratorKind.CustomConstructor;
12-
case "compilemembersonly": return DecoratorKind.CompileMembersOnly;
13-
case "pureabstract": return DecoratorKind.PureAbstract;
14-
case "phantom": return DecoratorKind.Phantom;
15-
case "tuplereturn": return DecoratorKind.TupleReturn;
16-
case "noclassor": return DecoratorKind.NoClassOr;
17-
case "luaiterator": return DecoratorKind.LuaIterator;
8+
case "extension":
9+
return DecoratorKind.Extension;
10+
case "metaextension":
11+
return DecoratorKind.MetaExtension;
12+
case "customconstructor":
13+
return DecoratorKind.CustomConstructor;
14+
case "compilemembersonly":
15+
return DecoratorKind.CompileMembersOnly;
16+
case "pureabstract":
17+
return DecoratorKind.PureAbstract;
18+
case "phantom":
19+
return DecoratorKind.Phantom;
20+
case "tuplereturn":
21+
return DecoratorKind.TupleReturn;
22+
case "noclassor":
23+
return DecoratorKind.NoClassOr;
24+
case "luaiterator":
25+
return DecoratorKind.LuaIterator;
1826
}
1927

2028
return undefined;

src/Errors.ts

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)