diff --git a/.prettierrc.json b/.prettierrc.json index f8774a2f2..9dd6427dc 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,7 +1,6 @@ { "printWidth": 120, "tabWidth": 4, - "trailingComma": "es5", - "endOfLine": "lf", + "arrowParens": "avoid", "overrides": [{ "files": ["**/*.md", "**/*.yml"], "options": { "tabWidth": 2 } }] } diff --git a/package-lock.json b/package-lock.json index a8e0102ed..7d07d2f17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4336,9 +4336,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz", + "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==", "dev": true }, "pretty-format": { diff --git a/package.json b/package.json index 4992ba80a..af51eb999 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "pretest": "npm run lint && npm run build-lualib", "test": "jest", "lint": "npm run lint:eslint && npm run lint:prettier", - "lint:prettier": "prettier --check \"**/*.{js,ts,yml,json,md}\" || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)", + "lint:prettier": "prettier --check . || (echo 'Run `npm run fix:prettier` to fix it.' && exit 1)", "lint:eslint": "eslint . --ext .js,.ts", - "fix:prettier": "prettier --check --write \"**/*.{js,ts,yml,json,md}\"", + "fix:prettier": "prettier --write .", "preversion": "npm run build && npm test", "postversion": "git push && git push --tags" }, @@ -57,7 +57,7 @@ "jest": "^25.1.0", "jest-circus": "^25.1.0", "lua-types": "^2.8.0", - "prettier": "^1.19.1", + "prettier": "^2.0.5", "ts-jest": "^25.2.1", "ts-node": "^8.6.2" } diff --git a/src/lualib/Error.ts b/src/lualib/Error.ts index c91223f65..d44a3b9eb 100644 --- a/src/lualib/Error.ts +++ b/src/lualib/Error.ts @@ -21,7 +21,7 @@ function __TS__GetErrorStack(constructor: Function): string { } function __TS__WrapErrorToString(getDescription: (this: T) => string): (this: T) => string { - return function(this: Error): string { + return function (this: Error): string { const description = getDescription.call(this); const caller = debug.getinfo(3, "f"); if (_VERSION === "Lua 5.1" || (caller && caller.func !== error)) { diff --git a/src/lualib/Generator.ts b/src/lualib/Generator.ts index 37b639776..a71740761 100644 --- a/src/lualib/Generator.ts +++ b/src/lualib/Generator.ts @@ -19,7 +19,7 @@ function __TS__GeneratorNext(this: GeneratorIterator, ...args: Vararg) { } function __TS__Generator(this: void, fn: (this: void, ...args: any[]) => any) { - return function(this: void, ...args: Vararg): GeneratorIterator { + return function (this: void, ...args: Vararg): GeneratorIterator { const argsLength = select("#", ...args); return { // Using explicit this there, since we don't pass arguments after the first nil and context is likely to be nil diff --git a/src/transformation/utils/safe-names.ts b/src/transformation/utils/safe-names.ts index b10ed414f..c072135f4 100644 --- a/src/transformation/utils/safe-names.ts +++ b/src/transformation/utils/safe-names.ts @@ -99,13 +99,6 @@ export function hasUnsafeIdentifierName( } const fixInvalidLuaIdentifier = (name: string) => - name.replace( - /[^a-zA-Z0-9_]/g, - c => - `_${c - .charCodeAt(0) - .toString(16) - .toUpperCase()}` - ); + name.replace(/[^a-zA-Z0-9_]/g, c => `_${c.charCodeAt(0).toString(16).toUpperCase()}`); export const createSafeName = (name: string) => "____" + fixInvalidLuaIdentifier(name); diff --git a/src/transpilation/transpile.ts b/src/transpilation/transpile.ts index 9046477e8..d024e8a09 100644 --- a/src/transpilation/transpile.ts +++ b/src/transpilation/transpile.ts @@ -142,10 +142,7 @@ export function transpile({ diagnostics.push(...program.emit(undefined, writeFile, undefined, false, transformers).diagnostics); // JSON files don't get through transformers and aren't written when outDir is the same as rootDir - program - .getSourceFiles() - .filter(isEmittableJsonFile) - .forEach(processSourceFile); + program.getSourceFiles().filter(isEmittableJsonFile).forEach(processSourceFile); } options.noEmit = oldNoEmit; diff --git a/src/tstl.ts b/src/tstl.ts index 00b6d7606..aab3feff2 100644 --- a/src/tstl.ts +++ b/src/tstl.ts @@ -202,10 +202,7 @@ function updateWatchCompilationHost( } function checkNodeVersion(): void { - const [major, minor] = process.version - .slice(1) - .split(".") - .map(Number); + const [major, minor] = process.version.slice(1).split(".").map(Number); const isValid = major > 12 || (major === 12 && minor >= 13); if (!isValid) { console.error(`TypeScriptToLua requires Node.js >=12.13.0, the current version is ${process.version}`); diff --git a/test/unit/builtins/console.spec.ts b/test/unit/builtins/console.spec.ts index 6cf4e6139..a68c1be5c 100644 --- a/test/unit/builtins/console.spec.ts +++ b/test/unit/builtins/console.spec.ts @@ -9,9 +9,7 @@ test.each([ 'console.log("Hello %%s", "there")', 'console.log("Hello", "There")', ])("console.log (%p)", code => { - util.testFunction(code) - .setOptions(compilerOptions) - .expectLuaToMatchSnapshot(); + util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot(); }); test.each([ @@ -21,9 +19,7 @@ test.each([ 'console.info("Hello %%s", "there")', 'console.info("Hello", "There")', ])("console.info (%p)", code => { - util.testFunction(code) - .setOptions(compilerOptions) - .expectLuaToMatchSnapshot(); + util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot(); }); test.each([ @@ -33,9 +29,7 @@ test.each([ 'console.error("Hello %%s", "there")', 'console.error("Hello", "There")', ])("console.error (%p)", code => { - util.testFunction(code) - .setOptions(compilerOptions) - .expectLuaToMatchSnapshot(); + util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot(); }); test.each([ @@ -45,9 +39,7 @@ test.each([ 'console.warn("Hello %%s", "there")', 'console.warn("Hello", "There")', ])("console.warn (%p)", code => { - util.testFunction(code) - .setOptions(compilerOptions) - .expectLuaToMatchSnapshot(); + util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot(); }); test.each([ @@ -57,9 +49,7 @@ test.each([ 'console.trace("Hello %%s", "there")', 'console.trace("Hello", "there")', ])("console.trace (%p)", code => { - util.testFunction(code) - .setOptions(compilerOptions) - .expectLuaToMatchSnapshot(); + util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot(); }); test.each([ @@ -69,9 +59,7 @@ test.each([ 'console.assert(false, "message %%s", "info")', 'console.assert(false, "message", "more")', ])("console.assert (%p)", code => { - util.testFunction(code) - .setOptions(compilerOptions) - .expectLuaToMatchSnapshot(); + util.testFunction(code).setOptions(compilerOptions).expectLuaToMatchSnapshot(); }); test("console.differentiation", () => { diff --git a/test/unit/builtins/math.spec.ts b/test/unit/builtins/math.spec.ts index 4d95e4afb..faaeacbcd 100644 --- a/test/unit/builtins/math.spec.ts +++ b/test/unit/builtins/math.spec.ts @@ -14,9 +14,7 @@ test.each([ "Math.PI", ])("%s", code => { // TODO: Remove? - util.testFunction(code) - .disableSemanticCheck() - .expectLuaToMatchSnapshot(); + util.testFunction(code).disableSemanticCheck().expectLuaToMatchSnapshot(); }); test.each(["E", "LN10", "LN2", "LOG10E", "LOG2E", "SQRT1_2", "SQRT2"])("Math.%s", constant => { diff --git a/test/unit/expressions.spec.ts b/test/unit/expressions.spec.ts index 25f4c20ed..6720fe8fb 100644 --- a/test/unit/expressions.spec.ts +++ b/test/unit/expressions.spec.ts @@ -15,9 +15,7 @@ test.each([ "let a = delete tbl.test", "delete tbl.test", ])("Unary expressions basic (%p)", input => { - util.testFunction(input) - .disableSemanticCheck() - .expectLuaToMatchSnapshot(); + util.testFunction(input).disableSemanticCheck().expectLuaToMatchSnapshot(); }); test.each(["3+4", "5-2", "6*3", "6**3", "20/5", "15/10", "15%3"])("Binary expressions basic numeric (%p)", input => { diff --git a/test/unit/json.spec.ts b/test/unit/json.spec.ts index b61e64fd1..2f4b0d6a5 100644 --- a/test/unit/json.spec.ts +++ b/test/unit/json.spec.ts @@ -1,9 +1,7 @@ import * as util from "../util"; test.each([0, "", [], [1, "2", []], { a: "b" }, { a: { b: "c" } }])("JSON (%p)", json => { - util.testModule(JSON.stringify(json)) - .setMainFileName("main.json") - .expectToEqual(json); + util.testModule(JSON.stringify(json)).setMainFileName("main.json").expectToEqual(json); }); test("Empty JSON file error", () => { diff --git a/test/unit/printer/sourcemaps.spec.ts b/test/unit/printer/sourcemaps.spec.ts index 6b4487ac9..96ffec05f 100644 --- a/test/unit/printer/sourcemaps.spec.ts +++ b/test/unit/printer/sourcemaps.spec.ts @@ -144,10 +144,7 @@ test.each([ ], }, ])("Source map has correct mapping (%p)", async ({ code, assertPatterns }) => { - const file = util - .testModule(code) - .expectToHaveNoDiagnostics() - .getMainLuaFileResult(); + const file = util.testModule(code).expectToHaveNoDiagnostics().getMainLuaFileResult(); const consumer = await new SourceMapConsumer(file.sourceMap); for (const { luaPattern, typeScriptPattern } of assertPatterns) { @@ -228,10 +225,7 @@ test.each([ { code: "class $$$ {}", name: "$$$" }, { code: 'namespace $$$ { const foo = "bar"; }', name: "$$$" }, ])("Source map has correct name mappings (%p)", async ({ code, name }) => { - const file = util - .testModule(code) - .expectToHaveNoDiagnostics() - .getMainLuaFileResult(); + const file = util.testModule(code).expectToHaveNoDiagnostics().getMainLuaFileResult(); const consumer = await new SourceMapConsumer(file.sourceMap); const typescriptPosition = lineAndColumnOf(code, name); diff --git a/test/util.ts b/test/util.ts index a24ce29a1..ee8b8e892 100644 --- a/test/util.ts +++ b/test/util.ts @@ -150,7 +150,7 @@ function executeJsModule(code: string): any { const memoize: MethodDecorator = (_target, _propertyKey, descriptor) => { const originalFunction = descriptor.value as any; const memoized = new WeakMap(); - descriptor.value = function(this: any, ...args: any[]): any { + descriptor.value = function (this: any, ...args: any[]): any { if (!memoized.has(this)) { memoized.set(this, originalFunction.apply(this, args)); }