Skip to content

Commit dfcfa1f

Browse files
authored
Enable prettier on all files (#588)
* Chnage prettier options * Enable prettier on all files * Remove formatting rules from main tslint config * Format all files with prettier * Make some manual formatting changes
1 parent a2046bd commit dfcfa1f

File tree

88 files changed

+1995
-2632
lines changed

Some content is hidden

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

88 files changed

+1995
-2632
lines changed

.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
/dist
22
/coverage
33
/test/translation/transformation/characterEscapeSequence.ts
4-
5-
/src
6-
*.md

.prettierrc.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ const isCI = require("is-ci");
22

33
/** @type {import("prettier").Options} */
44
module.exports = {
5-
printWidth: 100,
5+
printWidth: 120,
66
tabWidth: 4,
7-
trailingComma: "all",
8-
proseWrap: "always",
7+
trailingComma: "es5",
98
endOfLine: isCI ? "lf" : "auto",
109
overrides: [{ files: ["**/*.md", "**/*.yml", "**/.*.yml"], options: { tabWidth: 2 } }],
1110
};

CHANGELOG.md

Lines changed: 172 additions & 152 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
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+
- Source code for the project, has the transpiler core files in its root.
14+
- `src/lualib/`
1315
- 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/`
16+
- `src/targets/`
1517
- 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.
18+
- _Compiler.ts_ - Main entry point of the transpiler, this is what interfaces with the TypeScript compiler API.
19+
- _LuaTransformer.ts_ - Main transpiler code, transforms a TypeScript AST to a Lua AST.
20+
- _LuaPrinter.ts_ - Transforms a Lua AST to a string.
21+
- _TSHelper.ts_ - Helper methods used during the transpilation process.
2022
- `test/`
21-
* This directory contains all testing code for the transpiler.
22-
* `test/unit/`
23+
- This directory contains all testing code for the transpiler.
24+
- `test/unit/`
2325
- 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/`
26+
- `test/translation/`
2527
- **[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.
2628

2729
## Running Tests
30+
2831
The tests for this project can be executed using the standard `npm test`. This runs all tests.
2932

3033
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:
@@ -46,14 +49,17 @@ Due to the time required to run all tests, it is impractical to run every test w
4649
```
4750

4851
## Testing Guidelines
52+
4953
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.
5054

5155
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).
5256

5357
## Coding Conventions
58+
5459
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).
5560

5661
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!
62+
63+
- 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))`
64+
- Readability of code is more important than the amount of space it takes. If extra line breaks make your code more readable, add them.
65+
- Functional style is encouraged!

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ A generic TypeScript to Lua transpiler. Write your code in TypeScript and publis
1515
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.
1616

1717
## Documentation
18+
1819
More detailed documentation and info on writing declarations can be found [on the wiki](https://github.com/TypeScriptToLua/TypescriptToLua/wiki).
1920

2021
Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CHANGELOG.md)
@@ -38,24 +39,28 @@ Changelog can be found in [CHANGELOG.md](https://github.com/TypeScriptToLua/Type
3839
`tstl -p path/to/tsconfig.json --watch`
3940

4041
**Example tsconfig.json**
42+
4143
```json
4244
{
43-
"compilerOptions": {
44-
"target": "esnext",
45-
"lib": ["esnext"],
46-
"strict": true
47-
},
48-
"tstl": {
49-
"luaTarget": "JIT"
50-
}
45+
"compilerOptions": {
46+
"target": "esnext",
47+
"lib": ["esnext"],
48+
"strict": true
49+
},
50+
"tstl": {
51+
"luaTarget": "JIT"
52+
}
5153
}
5254
```
5355

5456
## Contributing
57+
5558
All contributions are welcome, but please read our [contribution guidelines](https://github.com/TypeScriptToLua/TypescriptToLua/blob/master/CONTRIBUTING.md)!
5659

5760
## Declarations
61+
5862
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:
63+
5964
- [Dota 2 Modding](https://github.com/ModDota/API/tree/master/declarations/server)
6065
- [Defold Game Engine Scripting](https://github.com/dasannikov/DefoldTypeScript/blob/master/defold.d.ts)
6166
- [LÖVE 2D Game Development](https://github.com/hazzard993/love-typescript-definitions)
@@ -71,17 +76,20 @@ The real power of this transpiler is usage together with good declarations for t
7176
`npm run coverage` or `npm run coverage-html` to generate a coverage report.
7277

7378
## Sublime Text integration
79+
7480
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`).
7581

7682
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.
7783

7884
### 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):
85+
86+
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):
8087

8188
```
8289
{
8390
"cmd": ["tstl", "-p", "$file"],
8491
"shell": true
8592
}
8693
```
94+
8795
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`.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"pretest": "npm run lint && ts-node --transpile-only ./build_lualib.ts",
2424
"test": "jest",
2525
"lint": "npm run lint:tslint && npm run lint:prettier",
26-
"lint:prettier": "prettier --check **/*.{js,ts,yml,json} || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
26+
"lint:prettier": "prettier --check **/*.{js,ts,yml,json,md} || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
2727
"lint:tslint": "tslint -p . && tslint -p test && tslint -p src/lualib",
28-
"fix:prettier": "prettier --check --write **/*.{js,ts,yml,json}",
28+
"fix:prettier": "prettier --check --write **/*.{js,ts,yml,json,md}",
2929
"release-major": "npm version major",
3030
"release-minor": "npm version minor",
3131
"release-patch": "npm version patch",

src/CommandLineParser.ts

Lines changed: 5 additions & 10 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

@@ -143,10 +138,10 @@ function updateParsedCommandLine(
143138
if (option) {
144139
// Ignore errors caused by tstl specific compiler options
145140
const tsInvalidCompilerOptionErrorCode = 5023;
146-
parsedCommandLine.errors = parsedCommandLine.errors.filter(err => {
141+
parsedCommandLine.errors = parsedCommandLine.errors.filter(error => {
147142
return !(
148-
err.code === tsInvalidCompilerOptionErrorCode &&
149-
String(err.messageText).endsWith(`'${args[i]}'.`)
143+
error.code === tsInvalidCompilerOptionErrorCode &&
144+
String(error.messageText).endsWith(`'${args[i]}'.`)
150145
);
151146
});
152147

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)