Skip to content

Commit a2ded74

Browse files
committed
Format all files with prettier
1 parent dedc6b2 commit a2ded74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1905
-2377
lines changed

CHANGELOG.md

Lines changed: 191 additions & 154 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
# Contributing to TypeScriptToLua
22

3-
1) [Project Overview](#project-overview)
4-
2) [Running Tests](#running-tests)
5-
3) [Testing Guidelines](#testing-guidelines)
6-
4) [Coding Conventions](#coding-conventions)
3+
1. [Project Overview](#project-overview)
4+
2. [Running Tests](#running-tests)
5+
3. [Testing Guidelines](#testing-guidelines)
6+
4. [Coding Conventions](#coding-conventions)
77

88
## Project Overview
9+
910
To get familiar with the project structure, here is a short overview of each directory and their function.
11+
1012
- `src/`
11-
* Source code for the project, has the transpiler core files in its root.
12-
* `src/lualib/`
13-
- Contains the TypeScript source for the lualib. This consists of implementations of standard TypeScript functions that are not present in Lua. These files are compiled to Lua using the transpiler. They are included in the Lua result when transpiling.
14-
* `src/targets/`
15-
- Version-specific transpiler overrides for the different Lua targets. The main transpiler transpiles Lua 5.0, each target-specific transpiler extends the transpiler of the version before it, so the 5.3 inherits 5.2 which inherits 5.1 which inherits 5.0. LuaJIT is based on 5.2 so inherits from the 5.2 transpiler.
16-
* *Compiler.ts* - Main entry point of the transpiler, this is what interfaces with the TypeScript compiler API.
17-
* *LuaTransformer.ts* - Main transpiler code, transforms a TypeScript AST to a Lua AST.
18-
* *LuaPrinter.ts* - Transforms a Lua AST to a string.
19-
* *TSHelper.ts* - Helper methods used during the transpilation process.
13+
- Source code for the project, has the transpiler core files in its root.
14+
- `src/lualib/`
15+
- Contains the TypeScript source for the lualib. This consists of implementations of standard TypeScript functions
16+
that are not present in Lua. These files are compiled to Lua using the transpiler. They are included in the Lua
17+
result when transpiling.
18+
- `src/targets/`
19+
- Version-specific transpiler overrides for the different Lua targets. The main transpiler transpiles Lua 5.0, each
20+
target-specific transpiler extends the transpiler of the version before it, so the 5.3 inherits 5.2 which inherits
21+
5.1 which inherits 5.0. LuaJIT is based on 5.2 so inherits from the 5.2 transpiler.
22+
- _Compiler.ts_ - Main entry point of the transpiler, this is what interfaces with the TypeScript compiler API.
23+
- _LuaTransformer.ts_ - Main transpiler code, transforms a TypeScript AST to a Lua AST.
24+
- _LuaPrinter.ts_ - Transforms a Lua AST to a string.
25+
- _TSHelper.ts_ - Helper methods used during the transpilation process.
2026
- `test/`
21-
* This directory contains all testing code for the transpiler.
22-
* `test/unit/`
23-
- Unit/Functional tests for the transpiler. Tests in here are grouped by functionality they are testing. Generally each of these tests uses the transpiler to transpile some TypeScript to Lua, then executes it using the Fengari Lua VM. Assertion is done on the result of the lua code.
24-
* `test/translation/`
25-
- **[Obsolete]** Contains tests that only check the transpiled Lua String. We prefer adding unit/functional tests over translation tests. This directory will probably be removed at some point.
27+
- This directory contains all testing code for the transpiler.
28+
- `test/unit/`
29+
- Unit/Functional tests for the transpiler. Tests in here are grouped by functionality they are testing. Generally
30+
each of these tests uses the transpiler to transpile some TypeScript to Lua, then executes it using the Fengari
31+
Lua VM. Assertion is done on the result of the lua code.
32+
- `test/translation/`
33+
- **[Obsolete]** Contains tests that only check the transpiled Lua String. We prefer adding unit/functional tests
34+
over translation tests. This directory will probably be removed at some point.
2635

2736
## Running Tests
37+
2838
The tests for this project can be executed using the standard `npm test`. This runs all tests.
2939

30-
Due to the time required to run all tests, it is impractical to run every test while developing part of the transpiler. To speed up the test run you can:
40+
Due to the time required to run all tests, it is impractical to run every test while developing part of the transpiler.
41+
To speed up the test run you can:
3142

3243
- Use `npm test name` to run tests that match a file name pattern
3344

@@ -46,14 +57,24 @@ Due to the time required to run all tests, it is impractical to run every test w
4657
```
4758

4859
## Testing Guidelines
49-
When submitting a pull request with new functionality, we require some functional (transpile and execute Lua) to be added, to ensure the new functionality works as expected, and will continue to work that way.
5060

51-
Translation tests are discouraged as in most cases as we do not really care about the exact Lua output, as long as executing it results in the correct result (which is tested by functional tests).
61+
When submitting a pull request with new functionality, we require some functional (transpile and execute Lua) to be
62+
added, to ensure the new functionality works as expected, and will continue to work that way.
63+
64+
Translation tests are discouraged as in most cases as we do not really care about the exact Lua output, as long as
65+
executing it results in the correct result (which is tested by functional tests).
5266

5367
## Coding Conventions
54-
Most coding conventions are enforced by the TSLint and Prettier. You can check your code locally by running `npm run lint`. The CI build will fail if your code does not pass the linter. For better experience, you can install extensions for your code editor for [TSLint](https://palantir.github.io/tslint/usage/third-party-tools/) and [Prettier](https://prettier.io/docs/en/editors.html).
68+
69+
Most coding conventions are enforced by the TSLint and Prettier. You can check your code locally by running
70+
`npm run lint`. The CI build will fail if your code does not pass the linter. For better experience, you can install
71+
extensions for your code editor for [TSLint](https://palantir.github.io/tslint/usage/third-party-tools/) and
72+
[Prettier](https://prettier.io/docs/en/editors.html).
5573

5674
Some extra conventions worth mentioning:
57-
* Do not abbreviate variable names. The exception here are inline lambda arguments, if it is obvious what the argument is you can abbreviate to the first letter, e.g: `statements.filter(s => ts.VariableStatement(s))`
58-
* Readability of code is more important than the amount of space it takes. If extra line breaks make your code more readable, add them.
59-
* Functional style is encouraged!
75+
76+
- Do not abbreviate variable names. The exception here are inline lambda arguments, if it is obvious what the argument
77+
is you can abbreviate to the first letter, e.g: `statements.filter(s => ts.VariableStatement(s))`
78+
- Readability of code is more important than the amount of space it takes. If extra line breaks make your code more
79+
readable, add them.
80+
- Functional style is encouraged!

README.md

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212

1313
A generic TypeScript to Lua transpiler. Write your code in TypeScript and publish Lua!
1414

15-
Large projects written in lua can become hard to maintain and make it easy to make mistakes. Writing code in TypeScript instead improves maintainability, readability and robustness, with the added bonus of good IDE support. This project is useful in any environment where Lua code is accepted, with the powerful option of simply declaring any existing API using TypeScript declaration files.
15+
Large projects written in lua can become hard to maintain and make it easy to make mistakes. Writing code in TypeScript
16+
instead improves maintainability, readability and robustness, with the added bonus of good IDE support. This project is
17+
useful in any environment where Lua code is accepted, with the powerful option of simply declaring any existing API
18+
using TypeScript declaration files.
1619

1720
## Documentation
18-
More detailed documentation and info on writing declarations can be found [on the wiki](https://github.com/TypeScriptToLua/TypescriptToLua/wiki).
21+
22+
More detailed documentation and info on writing declarations can be found
23+
[on the wiki](https://github.com/TypeScriptToLua/TypescriptToLua/wiki).
1924

2025
Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CHANGELOG.md)
2126

@@ -38,24 +43,30 @@ Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/Type
3843
`tstl -p path/to/tsconfig.json --watch`
3944

4045
**Example tsconfig.json**
46+
4147
```json
4248
{
43-
"compilerOptions": {
44-
"target": "esnext",
45-
"lib": ["esnext"],
46-
"strict": true
47-
},
48-
"tstl": {
49-
"luaTarget": "JIT"
50-
}
49+
"compilerOptions": {
50+
"target": "esnext",
51+
"lib": ["esnext"],
52+
"strict": true
53+
},
54+
"tstl": {
55+
"luaTarget": "JIT"
56+
}
5157
}
5258
```
5359

5460
## Contributing
55-
All contributions are welcome, but please read our [contribution guidelines](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CONTRIBUTING.md)!
61+
62+
All contributions are welcome, but please read our
63+
[contribution guidelines](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CONTRIBUTING.md)!
5664

5765
## Declarations
58-
The real power of this transpiler is usage together with good declarations for the Lua API provided. Some examples of Lua interface declarations can be found here:
66+
67+
The real power of this transpiler is usage together with good declarations for the Lua API provided. Some examples of
68+
Lua interface declarations can be found here:
69+
5970
- [Dota 2 Modding](https://github.com/ModDota/API/tree/master/declarations/server)
6071
- [Defold Game Engine Scripting](https://github.com/dasannikov/DefoldTypeScript/blob/master/defold.d.ts)
6172
- [LÖVE 2D Game Development](https://github.com/hazzard993/love-typescript-definitions)
@@ -71,17 +82,27 @@ The real power of this transpiler is usage together with good declarations for t
7182
`npm run coverage` or `npm run coverage-html` to generate a coverage report.
7283

7384
## Sublime Text integration
74-
This compiler works great in combination with the [Sublime Text Typescript plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin) (available through the package manager as `TypeScript`).
7585

76-
You can simply open your typescript project assuming a valid tsconfig.json file is present. The default TypeScript plugin will provide all functionality of a regular TypeScript project.
86+
This compiler works great in combination with the
87+
[Sublime Text Typescript plugin](https://github.com/Microsoft/TypeScript-Sublime-Plugin) (available through the package
88+
manager as `TypeScript`).
89+
90+
You can simply open your typescript project assuming a valid tsconfig.json file is present. The default TypeScript
91+
plugin will provide all functionality of a regular TypeScript project.
7792

7893
### Setting up a custom build system
79-
To add the option to build with the Lua transpiler instead of the regular typescript compiler, go to `Tools > Build System > New Build System...`. In the new sublime-build file that opens, enter the following (adjust path to tstl if not installed globally):
94+
95+
To add the option to build with the Lua transpiler instead of the regular typescript compiler, go to
96+
`Tools > Build System > New Build System...`. In the new sublime-build file that opens, enter the following (adjust path
97+
to tstl if not installed globally):
8098

8199
```
82100
{
83101
"cmd": ["tstl", "-p", "$file"],
84102
"shell": true
85103
}
86104
```
87-
Save this in your Sublime settings as a `TypeScriptToLua.sublime-build`. You can now select the TypeScriptToLua build system in `Tools > Build System` to build using the normal hotkey (`ctrl+B`), or if you have multiple TypeScript projects open, you can choose your compiler before building by pressing `ctrl+shift+B`.
105+
106+
Save this in your Sublime settings as a `TypeScriptToLua.sublime-build`. You can now select the TypeScriptToLua build
107+
system in `Tools > Build System` to build using the normal hotkey (`ctrl+B`), or if you have multiple TypeScript
108+
projects open, you can choose your compiler before building by pressing `ctrl+shift+B`.

src/CommandLineParser.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ export function updateParsedConfigFile(parsedConfigFile: ts.ParsedCommandLine):
9797

9898
if (parsedConfigFile.raw.tstl) {
9999
if (hasRootLevelOptions) {
100-
parsedConfigFile.errors.push(
101-
diagnostics.tstlOptionsAreMovingToTheTstlObject(parsedConfigFile.raw.tstl)
102-
);
100+
parsedConfigFile.errors.push(diagnostics.tstlOptionsAreMovingToTheTstlObject(parsedConfigFile.raw.tstl));
103101
}
104102

105103
for (const key in parsedConfigFile.raw.tstl) {
@@ -122,10 +120,7 @@ export function parseCommandLine(args: string[]): ParsedCommandLine {
122120
return updateParsedCommandLine(ts.parseCommandLine(args), args);
123121
}
124122

125-
function updateParsedCommandLine(
126-
parsedCommandLine: ts.ParsedCommandLine,
127-
args: string[]
128-
): ParsedCommandLine {
123+
function updateParsedCommandLine(parsedCommandLine: ts.ParsedCommandLine, args: string[]): ParsedCommandLine {
129124
for (let i = 0; i < args.length; i++) {
130125
if (!args[i].startsWith("-")) continue;
131126

@@ -145,8 +140,7 @@ function updateParsedCommandLine(
145140
const tsInvalidCompilerOptionErrorCode = 5023;
146141
parsedCommandLine.errors = parsedCommandLine.errors.filter(err => {
147142
return !(
148-
err.code === tsInvalidCompilerOptionErrorCode &&
149-
String(err.messageText).endsWith(`'${args[i]}'.`)
143+
err.code === tsInvalidCompilerOptionErrorCode && String(err.messageText).endsWith(`'${args[i]}'.`)
150144
);
151145
});
152146

src/Emit.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ export interface OutputFile {
1212
}
1313

1414
let lualibContent: string;
15-
export function emitTranspiledFiles(
16-
options: CompilerOptions,
17-
transpiledFiles: TranspiledFile[]
18-
): OutputFile[] {
15+
export function emitTranspiledFiles(options: CompilerOptions, transpiledFiles: TranspiledFile[]): OutputFile[] {
1916
let { rootDir, outDir, outFile, luaLibImport } = options;
2017

2118
const configFileName = options.configFilePath as string | undefined;
@@ -60,10 +57,7 @@ export function emitTranspiledFiles(
6057

6158
if (luaLibImport === LuaLibImportKind.Require || luaLibImport === LuaLibImportKind.Always) {
6259
if (lualibContent === undefined) {
63-
lualibContent = fs.readFileSync(
64-
path.resolve(__dirname, "../dist/lualib/lualib_bundle.lua"),
65-
"utf8"
66-
);
60+
lualibContent = fs.readFileSync(path.resolve(__dirname, "../dist/lualib/lualib_bundle.lua"), "utf8");
6761
}
6862

6963
let outPath = path.resolve(rootDir, "lualib_bundle.lua");

0 commit comments

Comments
 (0)