Skip to content

Commit 6d5c032

Browse files
authored
Create CONTRIBUTING.md
1 parent ddc5a51 commit 6d5c032

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

CONTRIBUTING.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Contributing to TypeScriptToLua
2+
3+
1) [Project Overview](#project-overview)
4+
2) [Running Tests](#running-tests)
5+
3) [Testing Guidelines](#testing-guidelines)
6+
4) [Coding Conventions](#coding-conventions)
7+
8+
## Project Overview
9+
To get familiar with the project structure, here is a short overview of each directory and their function.
10+
- `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+
* *Transpiler.ts* - Main transpiler code, transforms a TypeScript AST to a Lua string.
18+
* *TSHelper.ts* - Helper methods used during the transpilation process.
19+
- `test/`
20+
* This directory contains all testing code for the transpiler.
21+
* `test/src/`
22+
- Contains all extra source and utility used to run tests.
23+
* `test/unit/`
24+
- 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.
25+
* `test/translation/`
26+
- **[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+
28+
## Running Tests
29+
The tests for this project can be executed using the standard `npm test`. This runs all tests (can take a while!).
30+
31+
### Testing while developing
32+
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 import `FocusTest` or `FocusTests` from Alsatian. If a class is decorated with `@FocusTests`, all other test classes will be ignored. Similarly, if any test method is decorated with `@FocusTest`, only `@FocusTest` methods will be run during `npm test`.
33+
34+
For example:
35+
```ts
36+
import { Expect, FocusTests, Test, TestCase } from "alsatian";
37+
38+
@FocusTests
39+
export class FunctionTests {
40+
// All tests in here will be executed.
41+
}
42+
43+
// All other tests will be ignored.
44+
```
45+
46+
Or
47+
48+
```ts
49+
import { Expect, FocusTest, Test, TestCase } from "alsatian";
50+
51+
export class FunctionTests {
52+
@FocusTest
53+
@Test("Example test 1")
54+
public test1(): void { // Will be executed
55+
}
56+
57+
@FocusTest
58+
@Test("Example test 2")
59+
public test2(): void { // Will also be executed
60+
}
61+
62+
@Test("Example test 3")
63+
public test3(): void { // Will be ignored
64+
}
65+
}
66+
67+
// All other tests will be ignored.
68+
```
69+
70+
71+
## Testing Guidelines
72+
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.
73+
74+
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).
75+
76+
## Coding Conventions
77+
Most coding conventions are enforced by the ts-lint configuration. The test process will fail if code does not pass the linter. Some extra conventions worth mentioning:
78+
* 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))`
79+
* Readability of code is more important than the amount of space it takes. If extra line breaks make your code more readable, add them.
80+
* Functional style is encouraged!

0 commit comments

Comments
 (0)