Skip to content

Commit a709c7d

Browse files
authored
Upgrade Prettier to v2 (#869)
* Set "arrowParens" option to "always" * Upgrade Prettier to v2 * Revert "Set "arrowParens" option to "always"" This reverts commit 1f3a981.
1 parent 6d20032 commit a709c7d

File tree

14 files changed

+24
-62
lines changed

14 files changed

+24
-62
lines changed

.prettierrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"printWidth": 120,
33
"tabWidth": 4,
4-
"trailingComma": "es5",
5-
"endOfLine": "lf",
4+
"arrowParens": "avoid",
65
"overrides": [{ "files": ["**/*.md", "**/*.yml"], "options": { "tabWidth": 2 } }]
76
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"pretest": "npm run lint && npm run build-lualib",
2424
"test": "jest",
2525
"lint": "npm run lint:eslint && npm run lint:prettier",
26-
"lint:prettier": "prettier --check \"**/*.{js,ts,yml,json,md}\" || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
26+
"lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)",
2727
"lint:eslint": "eslint . --ext .js,.ts",
28-
"fix:prettier": "prettier --check --write \"**/*.{js,ts,yml,json,md}\"",
28+
"fix:prettier": "prettier --write .",
2929
"preversion": "npm run build && npm test",
3030
"postversion": "git push && git push --tags"
3131
},
@@ -57,7 +57,7 @@
5757
"jest": "^25.1.0",
5858
"jest-circus": "^25.1.0",
5959
"lua-types": "^2.8.0",
60-
"prettier": "^1.19.1",
60+
"prettier": "^2.0.5",
6161
"ts-jest": "^25.2.1",
6262
"ts-node": "^8.6.2"
6363
}

src/lualib/Error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function __TS__GetErrorStack(constructor: Function): string {
2121
}
2222

2323
function __TS__WrapErrorToString<T extends Error>(getDescription: (this: T) => string): (this: T) => string {
24-
return function(this: Error): string {
24+
return function (this: Error): string {
2525
const description = getDescription.call(this);
2626
const caller = debug.getinfo(3, "f");
2727
if (_VERSION === "Lua 5.1" || (caller && caller.func !== error)) {

src/lualib/Generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function __TS__GeneratorNext(this: GeneratorIterator, ...args: Vararg<any[]>) {
1919
}
2020

2121
function __TS__Generator(this: void, fn: (this: void, ...args: any[]) => any) {
22-
return function(this: void, ...args: Vararg<any[]>): GeneratorIterator {
22+
return function (this: void, ...args: Vararg<any[]>): GeneratorIterator {
2323
const argsLength = select("#", ...args);
2424
return {
2525
// Using explicit this there, since we don't pass arguments after the first nil and context is likely to be nil

src/transformation/utils/safe-names.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ export function hasUnsafeIdentifierName(
9999
}
100100

101101
const fixInvalidLuaIdentifier = (name: string) =>
102-
name.replace(
103-
/[^a-zA-Z0-9_]/g,
104-
c =>
105-
`_${c
106-
.charCodeAt(0)
107-
.toString(16)
108-
.toUpperCase()}`
109-
);
102+
name.replace(/[^a-zA-Z0-9_]/g, c => `_${c.charCodeAt(0).toString(16).toUpperCase()}`);
110103

111104
export const createSafeName = (name: string) => "____" + fixInvalidLuaIdentifier(name);

src/transpilation/transpile.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ export function transpile({
142142
diagnostics.push(...program.emit(undefined, writeFile, undefined, false, transformers).diagnostics);
143143

144144
// JSON files don't get through transformers and aren't written when outDir is the same as rootDir
145-
program
146-
.getSourceFiles()
147-
.filter(isEmittableJsonFile)
148-
.forEach(processSourceFile);
145+
program.getSourceFiles().filter(isEmittableJsonFile).forEach(processSourceFile);
149146
}
150147

151148
options.noEmit = oldNoEmit;

src/tstl.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ function updateWatchCompilationHost(
202202
}
203203

204204
function checkNodeVersion(): void {
205-
const [major, minor] = process.version
206-
.slice(1)
207-
.split(".")
208-
.map(Number);
205+
const [major, minor] = process.version.slice(1).split(".").map(Number);
209206
const isValid = major > 12 || (major === 12 && minor >= 13);
210207
if (!isValid) {
211208
console.error(`TypeScriptToLua requires Node.js >=12.13.0, the current version is ${process.version}`);

test/unit/builtins/console.spec.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ test.each([
99
'console.log("Hello %%s", "there")',
1010
'console.log("Hello", "There")',
1111
])("console.log (%p)", code => {
12-
util.testFunction(code)
13-
.setOptions(compilerOptions)
14-
.expectLuaToMatchSnapshot();
12+
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
1513
});
1614

1715
test.each([
@@ -21,9 +19,7 @@ test.each([
2119
'console.info("Hello %%s", "there")',
2220
'console.info("Hello", "There")',
2321
])("console.info (%p)", code => {
24-
util.testFunction(code)
25-
.setOptions(compilerOptions)
26-
.expectLuaToMatchSnapshot();
22+
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
2723
});
2824

2925
test.each([
@@ -33,9 +29,7 @@ test.each([
3329
'console.error("Hello %%s", "there")',
3430
'console.error("Hello", "There")',
3531
])("console.error (%p)", code => {
36-
util.testFunction(code)
37-
.setOptions(compilerOptions)
38-
.expectLuaToMatchSnapshot();
32+
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
3933
});
4034

4135
test.each([
@@ -45,9 +39,7 @@ test.each([
4539
'console.warn("Hello %%s", "there")',
4640
'console.warn("Hello", "There")',
4741
])("console.warn (%p)", code => {
48-
util.testFunction(code)
49-
.setOptions(compilerOptions)
50-
.expectLuaToMatchSnapshot();
42+
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
5143
});
5244

5345
test.each([
@@ -57,9 +49,7 @@ test.each([
5749
'console.trace("Hello %%s", "there")',
5850
'console.trace("Hello", "there")',
5951
])("console.trace (%p)", code => {
60-
util.testFunction(code)
61-
.setOptions(compilerOptions)
62-
.expectLuaToMatchSnapshot();
52+
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
6353
});
6454

6555
test.each([
@@ -69,9 +59,7 @@ test.each([
6959
'console.assert(false, "message %%s", "info")',
7060
'console.assert(false, "message", "more")',
7161
])("console.assert (%p)", code => {
72-
util.testFunction(code)
73-
.setOptions(compilerOptions)
74-
.expectLuaToMatchSnapshot();
62+
util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot();
7563
});
7664

7765
test("console.differentiation", () => {

test/unit/builtins/math.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ test.each([
1414
"Math.PI",
1515
])("%s", code => {
1616
// TODO: Remove?
17-
util.testFunction(code)
18-
.disableSemanticCheck()
19-
.expectLuaToMatchSnapshot();
17+
util.testFunction(code).disableSemanticCheck().expectLuaToMatchSnapshot();
2018
});
2119

2220
test.each(["E", "LN10", "LN2", "LOG10E", "LOG2E", "SQRT1_2", "SQRT2"])("Math.%s", constant => {

0 commit comments

Comments
 (0)