From 0a6a581936561fa2da6295bd2b35ab72a2ce5889 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 9 May 2023 15:35:42 -0700 Subject: [PATCH] Match `xplat/yoga/javascript` prettier conventions Summary: Match Prettier config to match other Meta OSS projects Didn't update the test generator to use this form yet. Reviewed By: yungsters Differential Revision: D45570415 fbshipit-source-id: d5fd791b047debf41c28aecac75fb8dde16da3e3 --- javascript/.prettierrc.js | 9 +- javascript/jest.config.ts | 6 +- javascript/jest.setup.ts | 16 +-- javascript/just.config.ts | 135 +++++++++--------- javascript/src_js/entrypoint/_entryAsync.js | 6 +- javascript/src_js/entrypoint/_entrySync.js | 4 +- javascript/src_js/entrypoint/asmjs-async.js | 4 +- javascript/src_js/entrypoint/asmjs-sync.js | 4 +- javascript/src_js/entrypoint/wasm-async.js | 4 +- javascript/src_js/entrypoint/wasm-sync.js | 4 +- javascript/src_js/index.d.ts | 6 +- javascript/src_js/index.js | 2 +- javascript/src_js/sync.d.ts | 6 +- javascript/src_js/sync.js | 2 +- javascript/src_js/wrapAsm.d.ts | 16 +-- javascript/src_js/wrapAsm.js | 54 +++---- .../tests/Benchmarks/YGBenchmark.test.ts | 12 +- javascript/tests/YGAlignBaselineTest.test.ts | 10 +- javascript/tests/YGComputedBorderTest.test.ts | 4 +- javascript/tests/YGComputedMarginTest.test.ts | 4 +- .../tests/YGComputedPaddingTest.test.ts | 4 +- javascript/tests/YGDirtiedTest.test.ts | 22 +-- javascript/tests/YGErrataTest.test.ts | 8 +- javascript/tests/YGFlexBasisAuto.test.ts | 4 +- javascript/tests/YGMeasureCacheTest.test.ts | 6 +- javascript/tests/YGMeasureTest.test.ts | 12 +- javascript/tests/bin/run-bench.ts | 16 +-- javascript/tests/tools/MeasureCounter.ts | 12 +- javascript/tests/tools/globals.ts | 4 +- 29 files changed, 197 insertions(+), 199 deletions(-) diff --git a/javascript/.prettierrc.js b/javascript/.prettierrc.js index ae47ee6e..e7f500b1 100644 --- a/javascript/.prettierrc.js +++ b/javascript/.prettierrc.js @@ -8,8 +8,9 @@ */ module.exports = { - trailingComma: "es5", - tabWidth: 2, - semi: true, - singleQuote: false, + arrowParens: 'avoid', + bracketSameLine: true, + bracketSpacing: false, + singleQuote: true, + trailingComma: 'all', }; diff --git a/javascript/jest.config.ts b/javascript/jest.config.ts index 62e9f159..62f66a99 100644 --- a/javascript/jest.config.ts +++ b/javascript/jest.config.ts @@ -7,11 +7,11 @@ * @format */ -import type { Config } from "jest"; +import type {Config} from 'jest'; const config: Config = { - setupFiles: ["./jest.setup.ts"], - testRegex: "/tests/.*\\.test\\.[jt]s$", + setupFiles: ['./jest.setup.ts'], + testRegex: '/tests/.*\\.test\\.[jt]s$', }; export default config; diff --git a/javascript/jest.setup.ts b/javascript/jest.setup.ts index 72dd73fd..13639817 100644 --- a/javascript/jest.setup.ts +++ b/javascript/jest.setup.ts @@ -8,17 +8,17 @@ */ module.exports = async () => { - if (process.env["SYNC"] === "1" && process.env["WASM"] === "1") { - globalThis.Yoga = require("./dist/entrypoint/wasm-sync"); - } else if (process.env["SYNC"] === "1") { - globalThis.Yoga = require("./dist/entrypoint/asmjs-sync"); - } else if (process.env["WASM"] === "1") { - globalThis.Yoga = await require("./dist/entrypoint/wasm-async").loadYoga(); + if (process.env['SYNC'] === '1' && process.env['WASM'] === '1') { + globalThis.Yoga = require('./dist/entrypoint/wasm-sync'); + } else if (process.env['SYNC'] === '1') { + globalThis.Yoga = require('./dist/entrypoint/asmjs-sync'); + } else if (process.env['WASM'] === '1') { + globalThis.Yoga = await require('./dist/entrypoint/wasm-async').loadYoga(); } else { - globalThis.Yoga = await require("./dist/entrypoint/asmjs-async").loadYoga(); + globalThis.Yoga = await require('./dist/entrypoint/asmjs-async').loadYoga(); } }; -Object.defineProperty(globalThis, "YGBENCHMARK", { +Object.defineProperty(globalThis, 'YGBENCHMARK', { get: () => globalThis.test, }); diff --git a/javascript/just.config.ts b/javascript/just.config.ts index f52c2ee1..3b4175ac 100644 --- a/javascript/just.config.ts +++ b/javascript/just.config.ts @@ -20,81 +20,78 @@ import { spawn, task, tscTask, -} from "just-scripts"; +} from 'just-scripts'; -import glob from "glob"; -import path from "path"; -import which from "which"; +import glob from 'glob'; +import path from 'path'; +import which from 'which'; const node = process.execPath; -option("fix"); +option('fix'); -task("clean", cleanTask({ paths: ["build", "dist"] })); +task('clean', cleanTask({paths: ['build', 'dist']})); task( - "prepare-for-build", + 'prepare-for-build', parallel( - babelTransformTask({ paths: ["src_js"], dest: "dist" }), - copyTask({ paths: ["src_js/**/*.d.ts"], dest: "dist" }), - emcmakeGenerateTask() - ) + babelTransformTask({paths: ['src_js'], dest: 'dist'}), + copyTask({paths: ['src_js/**/*.d.ts'], dest: 'dist'}), + emcmakeGenerateTask(), + ), ); function defineFlavor(flavor: string, env: NodeJS.ProcessEnv) { - task(`cmake-build:${flavor}`, cmakeBuildTask({ targets: [flavor] })); + task(`cmake-build:${flavor}`, cmakeBuildTask({targets: [flavor]})); task( `jest:${flavor}`, - jestTask({ config: path.join(__dirname, "jest.config.ts"), env }) + jestTask({config: path.join(__dirname, 'jest.config.ts'), env}), ); task( `test:${flavor}`, - series("prepare-for-build", `cmake-build:${flavor}`, `jest:${flavor}`) + series('prepare-for-build', `cmake-build:${flavor}`, `jest:${flavor}`), ); } -defineFlavor("asmjs-async", { WASM: "0", SYNC: "0" }); -defineFlavor("asmjs-sync", { WASM: "0", SYNC: "1" }); -defineFlavor("wasm-async", { WASM: "1", SYNC: "0" }); -defineFlavor("wasm-sync", { WASM: "1", SYNC: "1" }); +defineFlavor('asmjs-async', {WASM: '0', SYNC: '0'}); +defineFlavor('asmjs-sync', {WASM: '0', SYNC: '1'}); +defineFlavor('wasm-async', {WASM: '1', SYNC: '0'}); +defineFlavor('wasm-sync', {WASM: '1', SYNC: '1'}); -task("cmake-build:all", cmakeBuildTask()); +task('cmake-build:all', cmakeBuildTask()); task( - "cmake-build:async", - cmakeBuildTask({ targets: ["asmjs-async", "wasm-async"] }) + 'cmake-build:async', + cmakeBuildTask({targets: ['asmjs-async', 'wasm-async']}), ); task( - "cmake-build:sync", - cmakeBuildTask({ targets: ["asmjs-sync", "wasm-sync"] }) + 'cmake-build:sync', + cmakeBuildTask({targets: ['asmjs-sync', 'wasm-sync']}), ); -task("build", series("prepare-for-build", "cmake-build:all")); +task('build', series('prepare-for-build', 'cmake-build:all')); task( - "test", + 'test', series( - "prepare-for-build", - series("cmake-build:asmjs-async", "jest:asmjs-async"), - series("cmake-build:asmjs-sync", "jest:asmjs-sync"), - series("cmake-build:wasm-async", "jest:wasm-async"), - series("cmake-build:wasm-sync", "jest:wasm-sync") - ) + 'prepare-for-build', + series('cmake-build:asmjs-async', 'jest:asmjs-async'), + series('cmake-build:asmjs-sync', 'jest:asmjs-sync'), + series('cmake-build:wasm-async', 'jest:wasm-async'), + series('cmake-build:wasm-sync', 'jest:wasm-sync'), + ), ); task( - "benchmark", - series("prepare-for-build", "cmake-build:sync", runBenchTask()) + 'benchmark', + series('prepare-for-build', 'cmake-build:sync', runBenchTask()), ); task( - "lint", + 'lint', parallel( tscTask(), - series( - eslintTask({ fix: argv().fix }), - clangFormatTask({ fix: argv().fix }) - ) - ) + series(eslintTask({fix: argv().fix}), clangFormatTask({fix: argv().fix})), + ), ); function babelTransformTask(opts: { @@ -102,68 +99,68 @@ function babelTransformTask(opts: { dest: string; }) { return () => { - const args = [...opts.paths, "--source-maps", "--out-dir", opts.dest]; - logger.info(`Transforming [${opts.paths.join(",")}] to '${opts.dest}'`); + const args = [...opts.paths, '--source-maps', '--out-dir', opts.dest]; + logger.info(`Transforming [${opts.paths.join(',')}] to '${opts.dest}'`); - return spawn(node, [require.resolve("@babel/cli/bin/babel"), ...args]); + return spawn(node, [require.resolve('@babel/cli/bin/babel'), ...args]); }; } function runBenchTask() { return () => { - const files = glob.sync("./tests/Benchmarks/**/*"); - const args = ["./tests/bin/run-bench.ts", ...files]; - logger.info(args.join(" ")); + const files = glob.sync('./tests/Benchmarks/**/*'); + const args = ['./tests/bin/run-bench.ts', ...files]; + logger.info(args.join(' ')); return spawn(node, args, { - stdio: "inherit", - env: { NODE_OPTIONS: "-r ts-node/register" }, + stdio: 'inherit', + env: {NODE_OPTIONS: '-r ts-node/register'}, }); }; } function emcmakeGenerateTask() { return () => { - const emcmake = which.sync("emcmake"); - const ninja = which.sync("ninja", { nothrow: true }); + const emcmake = which.sync('emcmake'); + const ninja = which.sync('ninja', {nothrow: true}); const args = [ - "cmake", - "-S", - ".", - "-B", - "build", - ...(ninja ? ["-G", "Ninja"] : []), + 'cmake', + '-S', + '.', + '-B', + 'build', + ...(ninja ? ['-G', 'Ninja'] : []), ]; - logger.info(["emcmake", ...args].join(" ")); + logger.info(['emcmake', ...args].join(' ')); return spawn(emcmake, args); }; } -function cmakeBuildTask(opts?: { targets?: ReadonlyArray }) { +function cmakeBuildTask(opts?: {targets?: ReadonlyArray}) { return () => { - const cmake = which.sync("cmake"); + const cmake = which.sync('cmake'); const args = [ - "--build", - "build", - ...(opts?.targets ? ["--target", ...opts.targets] : []), + '--build', + 'build', + ...(opts?.targets ? ['--target', ...opts.targets] : []), ]; - logger.info(["cmake", ...args].join(" ")); + logger.info(['cmake', ...args].join(' ')); - return spawn(cmake, args, { stdio: "inherit" }); + return spawn(cmake, args, {stdio: 'inherit'}); }; } -function clangFormatTask(opts?: { fix?: boolean }) { +function clangFormatTask(opts?: {fix?: boolean}) { return () => { const args = [ - ...(opts?.fix ? ["-i"] : ["--dry-run", "--Werror"]), - ...glob.sync("**/*.{h,hh,hpp,c,cpp,cc,m,mm}"), + ...(opts?.fix ? ['-i'] : ['--dry-run', '--Werror']), + ...glob.sync('**/*.{h,hh,hpp,c,cpp,cc,m,mm}'), ]; - logger.info(["clang-format", ...args].join(" ")); + logger.info(['clang-format', ...args].join(' ')); - return spawn(node, [require.resolve("clang-format"), ...args], { - stdio: "inherit", + return spawn(node, [require.resolve('clang-format'), ...args], { + stdio: 'inherit', }); }; } diff --git a/javascript/src_js/entrypoint/_entryAsync.js b/javascript/src_js/entrypoint/_entryAsync.js index 942296a7..7d46c388 100644 --- a/javascript/src_js/entrypoint/_entryAsync.js +++ b/javascript/src_js/entrypoint/_entryAsync.js @@ -7,9 +7,9 @@ * @format */ -const wrapAsm = require("../wrapAsm"); +const wrapAsm = require('../wrapAsm'); -module.exports = (loadAsm) => ({ +module.exports = loadAsm => ({ loadYoga: () => loadAsm().then(wrapAsm), - ...require("../generated/YGEnums"), + ...require('../generated/YGEnums'), }); diff --git a/javascript/src_js/entrypoint/_entrySync.js b/javascript/src_js/entrypoint/_entrySync.js index 42de4bee..9495d98c 100644 --- a/javascript/src_js/entrypoint/_entrySync.js +++ b/javascript/src_js/entrypoint/_entrySync.js @@ -7,5 +7,5 @@ * @format */ -const wrapAsm = require("../wrapAsm"); -module.exports = (asm) => wrapAsm(asm()); +const wrapAsm = require('../wrapAsm'); +module.exports = asm => wrapAsm(asm()); diff --git a/javascript/src_js/entrypoint/asmjs-async.js b/javascript/src_js/entrypoint/asmjs-async.js index dcab5f92..eb1b52d7 100644 --- a/javascript/src_js/entrypoint/asmjs-async.js +++ b/javascript/src_js/entrypoint/asmjs-async.js @@ -7,5 +7,5 @@ * @format */ -const asm = require("../build/asmjs-async"); -module.exports = require("./_entryAsync")(asm); +const asm = require('../build/asmjs-async'); +module.exports = require('./_entryAsync')(asm); diff --git a/javascript/src_js/entrypoint/asmjs-sync.js b/javascript/src_js/entrypoint/asmjs-sync.js index ac940b7f..69197714 100644 --- a/javascript/src_js/entrypoint/asmjs-sync.js +++ b/javascript/src_js/entrypoint/asmjs-sync.js @@ -7,5 +7,5 @@ * @format */ -const asm = require("../build/asmjs-sync"); -module.exports = require("./_entrySync")(asm); +const asm = require('../build/asmjs-sync'); +module.exports = require('./_entrySync')(asm); diff --git a/javascript/src_js/entrypoint/wasm-async.js b/javascript/src_js/entrypoint/wasm-async.js index 80dc1f5f..ad5be421 100644 --- a/javascript/src_js/entrypoint/wasm-async.js +++ b/javascript/src_js/entrypoint/wasm-async.js @@ -7,5 +7,5 @@ * @format */ -const asm = require("../build/wasm-async"); -module.exports = require("./_entryAsync")(asm); +const asm = require('../build/wasm-async'); +module.exports = require('./_entryAsync')(asm); diff --git a/javascript/src_js/entrypoint/wasm-sync.js b/javascript/src_js/entrypoint/wasm-sync.js index e0404a60..88983508 100644 --- a/javascript/src_js/entrypoint/wasm-sync.js +++ b/javascript/src_js/entrypoint/wasm-sync.js @@ -7,5 +7,5 @@ * @format */ -const asm = require("../build/wasm-sync"); -module.exports = require("./_entrySync")(asm); +const asm = require('../build/wasm-sync'); +module.exports = require('./_entrySync')(asm); diff --git a/javascript/src_js/index.d.ts b/javascript/src_js/index.d.ts index 770a61b5..fb2830e4 100644 --- a/javascript/src_js/index.d.ts +++ b/javascript/src_js/index.d.ts @@ -7,9 +7,9 @@ * @format */ -import type { Yoga } from "./wrapAsm"; +import type {Yoga} from './wrapAsm'; -export * from "./generated/YGEnums"; -export * from "./wrapAsm"; +export * from './generated/YGEnums'; +export * from './wrapAsm'; export function loadYoga(): Promise; diff --git a/javascript/src_js/index.js b/javascript/src_js/index.js index bea46e9b..06a348c4 100644 --- a/javascript/src_js/index.js +++ b/javascript/src_js/index.js @@ -8,4 +8,4 @@ */ // Fallback for when the export map is not followed -module.exports = require("./entrypoint/asmjs-async"); +module.exports = require('./entrypoint/asmjs-async'); diff --git a/javascript/src_js/sync.d.ts b/javascript/src_js/sync.d.ts index 01a6765e..27bd8ecc 100644 --- a/javascript/src_js/sync.d.ts +++ b/javascript/src_js/sync.d.ts @@ -7,10 +7,10 @@ * @format */ -import type { Yoga } from "./wrapAsm"; +import type {Yoga} from './wrapAsm'; -export * from "./generated/YGEnums"; -export * from "./wrapAsm"; +export * from './generated/YGEnums'; +export * from './wrapAsm'; declare const yoga: Yoga; export default yoga; diff --git a/javascript/src_js/sync.js b/javascript/src_js/sync.js index 70fd4660..6ac610ef 100644 --- a/javascript/src_js/sync.js +++ b/javascript/src_js/sync.js @@ -8,4 +8,4 @@ */ // Fallback for when the export map is not followed -module.exports = require("./entrypoint/asmjs-sync"); +module.exports = require('./entrypoint/asmjs-sync'); diff --git a/javascript/src_js/wrapAsm.d.ts b/javascript/src_js/wrapAsm.d.ts index 179923e8..49b00e6c 100644 --- a/javascript/src_js/wrapAsm.d.ts +++ b/javascript/src_js/wrapAsm.d.ts @@ -22,9 +22,9 @@ import type { PositionType, Unit, Wrap, -} from "./generated/YGEnums"; +} from './generated/YGEnums'; -import type * as YGEnums from "./generated/YGEnums"; +import type * as YGEnums from './generated/YGEnums'; type Layout = { left: number; @@ -50,7 +50,7 @@ export type Config = { isExperimentalFeatureEnabled(feature: ExperimentalFeature): boolean; setExperimentalFeatureEnabled( feature: ExperimentalFeature, - enabled: boolean + enabled: boolean, ): void; setPointScaleFactor(factor: number): void; /** @@ -77,7 +77,7 @@ export type MeasureFunction = ( width: number, widthMode: MeasureMode, height: number, - heightMode: MeasureMode + heightMode: MeasureMode, ) => Size; export type Node = { @@ -135,20 +135,20 @@ export type Node = { setBorder(edge: Edge, borderWidth: number): void; setDisplay(display: Display): void; setFlex(flex: number): void; - setFlexBasis(flexBasis: number | "auto" | `${number}%`): void; + setFlexBasis(flexBasis: number | 'auto' | `${number}%`): void; setFlexBasisPercent(flexBasis: number): void; setFlexBasisAuto(): void; setFlexDirection(flexDirection: FlexDirection): void; setFlexGrow(flexGrow: number): void; setFlexShrink(flexShrink: number): void; setFlexWrap(flexWrap: Wrap): void; - setHeight(height: number | "auto" | `${number}%`): void; + setHeight(height: number | 'auto' | `${number}%`): void; setIsReferenceBaseline(isReferenceBaseline: boolean): void; setHeightAuto(): void; setHeightPercent(height: number): void; setJustifyContent(justifyContent: Justify): void; setGap(gutter: Gutter, gapLength: number): Value; - setMargin(edge: Edge, margin: number | "auto" | `${number}%`): void; + setMargin(edge: Edge, margin: number | 'auto' | `${number}%`): void; setMarginAuto(edge: Edge): void; setMarginPercent(edge: Edge, margin: number): void; setMaxHeight(maxHeight: number | `${number}%`): void; @@ -167,7 +167,7 @@ export type Node = { setPosition(edge: Edge, position: number | `${number}%`): void; setPositionPercent(edge: Edge, position: number): void; setPositionType(positionType: PositionType): void; - setWidth(width: number | "auto" | `${number}%`): void; + setWidth(width: number | 'auto' | `${number}%`): void; setWidthAuto(): void; setWidthPercent(width: number): void; unsetDirtiedFunc(): void; diff --git a/javascript/src_js/wrapAsm.js b/javascript/src_js/wrapAsm.js index e0c3c888..f0280f1f 100644 --- a/javascript/src_js/wrapAsm.js +++ b/javascript/src_js/wrapAsm.js @@ -7,9 +7,9 @@ * @format */ -const CONSTANTS = require("./generated/YGEnums"); +const CONSTANTS = require('./generated/YGEnums'); -module.exports = (lib) => { +module.exports = lib => { function patch(prototype, name, fn) { const original = prototype[name]; @@ -19,16 +19,16 @@ module.exports = (lib) => { } for (const fnName of [ - "setPosition", - "setMargin", - "setFlexBasis", - "setWidth", - "setHeight", - "setMinWidth", - "setMinHeight", - "setMaxWidth", - "setMaxHeight", - "setPadding", + 'setPosition', + 'setMargin', + 'setFlexBasis', + 'setWidth', + 'setHeight', + 'setMinWidth', + 'setMinHeight', + 'setMaxWidth', + 'setMaxHeight', + 'setPadding', ]) { const methods = { [CONSTANTS.UNIT_POINT]: lib.Node.prototype[fnName], @@ -43,15 +43,15 @@ module.exports = (lib) => { const value = args.pop(); let unit, asNumber; - if (value === "auto") { + if (value === 'auto') { unit = CONSTANTS.UNIT_AUTO; asNumber = undefined; - } else if (typeof value === "object") { + } else if (typeof value === 'object') { unit = value.unit; asNumber = value.valueOf(); } else { unit = - typeof value === "string" && value.endsWith("%") + typeof value === 'string' && value.endsWith('%') ? CONSTANTS.UNIT_PERCENT : CONSTANTS.UNIT_POINT; asNumber = parseFloat(value); @@ -62,7 +62,7 @@ module.exports = (lib) => { if (!methods[unit]) throw new Error( - `Failed to execute "${fnName}": Unsupported unit '${value}'` + `Failed to execute "${fnName}": Unsupported unit '${value}'`, ); if (asNumber !== undefined) { @@ -76,7 +76,7 @@ module.exports = (lib) => { function wrapMeasureFunction(measureFunction) { return lib.MeasureCallback.implement({ measure: (...args) => { - const { width, height } = measureFunction(...args); + const {width, height} = measureFunction(...args); return { width: width ?? NaN, height: height ?? NaN, @@ -85,7 +85,7 @@ module.exports = (lib) => { }); } - patch(lib.Node.prototype, "setMeasureFunc", function (original, measureFunc) { + patch(lib.Node.prototype, 'setMeasureFunc', function (original, measureFunc) { // This patch is just a convenience patch, since it helps write more // idiomatic source code (such as .setMeasureFunc(null)) if (measureFunc) { @@ -96,33 +96,33 @@ module.exports = (lib) => { }); function wrapDirtiedFunc(dirtiedFunction) { - return lib.DirtiedCallback.implement({ dirtied: dirtiedFunction }); + return lib.DirtiedCallback.implement({dirtied: dirtiedFunction}); } - patch(lib.Node.prototype, "setDirtiedFunc", function (original, dirtiedFunc) { + patch(lib.Node.prototype, 'setDirtiedFunc', function (original, dirtiedFunc) { original.call(this, wrapDirtiedFunc(dirtiedFunc)); }); - patch(lib.Config.prototype, "free", function () { + patch(lib.Config.prototype, 'free', function () { // Since we handle the memory allocation ourselves (via lib.Config.create), // we also need to handle the deallocation lib.Config.destroy(this); }); - patch(lib.Node, "create", (_, config) => { + patch(lib.Node, 'create', (_, config) => { // We decide the constructor we want to call depending on the parameters return config ? lib.Node.createWithConfig(config) : lib.Node.createDefault(); }); - patch(lib.Node.prototype, "free", function () { + patch(lib.Node.prototype, 'free', function () { // Since we handle the memory allocation ourselves (via lib.Node.create), // we also need to handle the deallocation lib.Node.destroy(this); }); - patch(lib.Node.prototype, "freeRecursive", function () { + patch(lib.Node.prototype, 'freeRecursive', function () { for (let t = 0, T = this.getChildCount(); t < T; ++t) { this.getChild(0).freeRecursive(); } @@ -131,16 +131,16 @@ module.exports = (lib) => { patch( lib.Node.prototype, - "calculateLayout", + 'calculateLayout', function ( original, width = NaN, height = NaN, - direction = CONSTANTS.DIRECTION_LTR + direction = CONSTANTS.DIRECTION_LTR, ) { // Just a small patch to add support for the function default parameters return original.call(this, width, height, direction); - } + }, ); return { diff --git a/javascript/tests/Benchmarks/YGBenchmark.test.ts b/javascript/tests/Benchmarks/YGBenchmark.test.ts index 384530cf..8dbfcf8f 100644 --- a/javascript/tests/Benchmarks/YGBenchmark.test.ts +++ b/javascript/tests/Benchmarks/YGBenchmark.test.ts @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -import { getMeasureCounter } from "../tools/MeasureCounter"; -import { Yoga, YGBENCHMARK } from "../tools/globals"; +import {getMeasureCounter} from '../tools/MeasureCounter'; +import {Yoga, YGBENCHMARK} from '../tools/globals'; const ITERATIONS = 2000; -YGBENCHMARK("Stack with flex", () => { +YGBENCHMARK('Stack with flex', () => { const root = Yoga.Node.create(); root.setWidth(100); root.setHeight(100); @@ -28,7 +28,7 @@ YGBENCHMARK("Stack with flex", () => { root.freeRecursive(); }); -YGBENCHMARK("Align stretch in undefined axis", () => { +YGBENCHMARK('Align stretch in undefined axis', () => { const root = Yoga.Node.create(); const measureCounter = getMeasureCounter(); @@ -44,7 +44,7 @@ YGBENCHMARK("Align stretch in undefined axis", () => { root.freeRecursive(); }); -YGBENCHMARK("Nested flex", () => { +YGBENCHMARK('Nested flex', () => { const root = Yoga.Node.create(); const measureCounter = getMeasureCounter(); @@ -68,7 +68,7 @@ YGBENCHMARK("Nested flex", () => { root.freeRecursive(); }); -YGBENCHMARK("Huge nested layout", () => { +YGBENCHMARK('Huge nested layout', () => { const root = Yoga.Node.create(); const iterations = Math.pow(ITERATIONS, 1 / 4); diff --git a/javascript/tests/YGAlignBaselineTest.test.ts b/javascript/tests/YGAlignBaselineTest.test.ts index 9eeb7f5c..da9613db 100644 --- a/javascript/tests/YGAlignBaselineTest.test.ts +++ b/javascript/tests/YGAlignBaselineTest.test.ts @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -test("align_baseline_parent_using_child_in_column_as_reference", () => { +test('align_baseline_parent_using_child_in_column_as_reference', () => { const config = Yoga.Config.create(); let root; @@ -57,7 +57,7 @@ test("align_baseline_parent_using_child_in_column_as_reference", () => { expect(root_child1_child1.getComputedLeft()).toBe(0); expect(root_child1_child1.getComputedTop()).toBe(300); } finally { - if (typeof root !== "undefined") { + if (typeof root !== 'undefined') { root.freeRecursive(); } @@ -65,7 +65,7 @@ test("align_baseline_parent_using_child_in_column_as_reference", () => { } }); -test("align_baseline_parent_using_child_in_row_as_reference", () => { +test('align_baseline_parent_using_child_in_row_as_reference', () => { const config = Yoga.Config.create(); let root; @@ -115,7 +115,7 @@ test("align_baseline_parent_using_child_in_row_as_reference", () => { expect(root_child1_child1.getComputedLeft()).toBe(500); expect(root_child1_child1.getComputedTop()).toBe(0); } finally { - if (typeof root !== "undefined") { + if (typeof root !== 'undefined') { root.freeRecursive(); } diff --git a/javascript/tests/YGComputedBorderTest.test.ts b/javascript/tests/YGComputedBorderTest.test.ts index 55f412cc..c74bc956 100644 --- a/javascript/tests/YGComputedBorderTest.test.ts +++ b/javascript/tests/YGComputedBorderTest.test.ts @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -test("border_start", () => { +test('border_start', () => { const root = Yoga.Node.create(); root.setWidth(100); root.setHeight(100); diff --git a/javascript/tests/YGComputedMarginTest.test.ts b/javascript/tests/YGComputedMarginTest.test.ts index 3ce35ebf..91a1ed87 100644 --- a/javascript/tests/YGComputedMarginTest.test.ts +++ b/javascript/tests/YGComputedMarginTest.test.ts @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -test("margin_start", () => { +test('margin_start', () => { const root = Yoga.Node.create(); root.setWidth(100); root.setHeight(100); diff --git a/javascript/tests/YGComputedPaddingTest.test.ts b/javascript/tests/YGComputedPaddingTest.test.ts index 28961f97..c07c54d4 100644 --- a/javascript/tests/YGComputedPaddingTest.test.ts +++ b/javascript/tests/YGComputedPaddingTest.test.ts @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -test("padding_start", () => { +test('padding_start', () => { const root = Yoga.Node.create(); root.setWidth(100); root.setHeight(100); diff --git a/javascript/tests/YGDirtiedTest.test.ts b/javascript/tests/YGDirtiedTest.test.ts index f78dc6a7..ef5ff40d 100644 --- a/javascript/tests/YGDirtiedTest.test.ts +++ b/javascript/tests/YGDirtiedTest.test.ts @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -test("dirtied", () => { +test('dirtied', () => { const root = Yoga.Node.create(); root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setWidth(100); @@ -21,7 +21,7 @@ test("dirtied", () => { }); // only nodes with a measure function can be marked dirty - root.setMeasureFunc(() => ({ width: 0, height: 0 })); + root.setMeasureFunc(() => ({width: 0, height: 0})); expect(dirtied).toBe(0); @@ -36,7 +36,7 @@ test("dirtied", () => { root.freeRecursive(); }); -test("dirtied_propagation", () => { +test('dirtied_propagation', () => { const root = Yoga.Node.create(); root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setWidth(100); @@ -46,7 +46,7 @@ test("dirtied_propagation", () => { root_child0.setAlignItems(Yoga.ALIGN_FLEX_START); root_child0.setWidth(50); root_child0.setHeight(20); - root_child0.setMeasureFunc(() => ({ width: 0, height: 0 })); + root_child0.setMeasureFunc(() => ({width: 0, height: 0})); root.insertChild(root_child0, 0); const root_child1 = Yoga.Node.create(); @@ -75,7 +75,7 @@ test("dirtied_propagation", () => { root.freeRecursive(); }); -test("dirtied_hierarchy", () => { +test('dirtied_hierarchy', () => { const root = Yoga.Node.create(); root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setWidth(100); @@ -85,14 +85,14 @@ test("dirtied_hierarchy", () => { root_child0.setAlignItems(Yoga.ALIGN_FLEX_START); root_child0.setWidth(50); root_child0.setHeight(20); - root_child0.setMeasureFunc(() => ({ width: 0, height: 0 })); + root_child0.setMeasureFunc(() => ({width: 0, height: 0})); root.insertChild(root_child0, 0); const root_child1 = Yoga.Node.create(); root_child1.setAlignItems(Yoga.ALIGN_FLEX_START); root_child1.setWidth(50); root_child1.setHeight(20); - root_child0.setMeasureFunc(() => ({ width: 0, height: 0 })); + root_child0.setMeasureFunc(() => ({width: 0, height: 0})); root.insertChild(root_child1, 0); root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); @@ -118,12 +118,12 @@ test("dirtied_hierarchy", () => { root.freeRecursive(); }); -test("dirtied_reset", () => { +test('dirtied_reset', () => { const root = Yoga.Node.create(); root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setWidth(100); root.setHeight(100); - root.setMeasureFunc(() => ({ width: 0, height: 0 })); + root.setMeasureFunc(() => ({width: 0, height: 0})); root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR); @@ -145,7 +145,7 @@ test("dirtied_reset", () => { root.setAlignItems(Yoga.ALIGN_FLEX_START); root.setWidth(100); root.setHeight(100); - root.setMeasureFunc(() => ({ width: 0, height: 0 })); + root.setMeasureFunc(() => ({width: 0, height: 0})); root.markDirty(); diff --git a/javascript/tests/YGErrataTest.test.ts b/javascript/tests/YGErrataTest.test.ts index 4c13a73a..02dda49a 100644 --- a/javascript/tests/YGErrataTest.test.ts +++ b/javascript/tests/YGErrataTest.test.ts @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -test("errata_all_contains_example_errata", () => { +test('errata_all_contains_example_errata', () => { const config = Yoga.Config.create(); config.setErrata(Yoga.ERRATA_ALL); @@ -17,7 +17,7 @@ test("errata_all_contains_example_errata", () => { config.free(); }); -test("errata_none_omits_example_errata", () => { +test('errata_none_omits_example_errata', () => { const config = Yoga.Config.create(); config.setErrata(Yoga.ERRATA_NONE); @@ -27,7 +27,7 @@ test("errata_none_omits_example_errata", () => { config.free(); }); -test("errata_is_settable", () => { +test('errata_is_settable', () => { const config = Yoga.Config.create(); config.setErrata(Yoga.ERRATA_ALL); diff --git a/javascript/tests/YGFlexBasisAuto.test.ts b/javascript/tests/YGFlexBasisAuto.test.ts index e2408a72..903ead2d 100644 --- a/javascript/tests/YGFlexBasisAuto.test.ts +++ b/javascript/tests/YGFlexBasisAuto.test.ts @@ -5,9 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -test("flex_basis_auto", () => { +test('flex_basis_auto', () => { const root = Yoga.Node.create(); expect(root.getFlexBasis().unit).toBe(Yoga.UNIT_AUTO); diff --git a/javascript/tests/YGMeasureCacheTest.test.ts b/javascript/tests/YGMeasureCacheTest.test.ts index a684eaa5..8866281c 100644 --- a/javascript/tests/YGMeasureCacheTest.test.ts +++ b/javascript/tests/YGMeasureCacheTest.test.ts @@ -5,11 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; +import {Yoga} from './tools/globals'; -import { getMeasureCounterMax } from "./tools/MeasureCounter"; +import {getMeasureCounterMax} from './tools/MeasureCounter'; -test("measure_once_single_flexible_child", () => { +test('measure_once_single_flexible_child', () => { const root = Yoga.Node.create(); root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW); root.setAlignItems(Yoga.ALIGN_FLEX_START); diff --git a/javascript/tests/YGMeasureTest.test.ts b/javascript/tests/YGMeasureTest.test.ts index 16f3abf9..e4d4a132 100644 --- a/javascript/tests/YGMeasureTest.test.ts +++ b/javascript/tests/YGMeasureTest.test.ts @@ -5,10 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import { Yoga } from "./tools/globals"; -import { getMeasureCounter } from "./tools/MeasureCounter"; +import {Yoga} from './tools/globals'; +import {getMeasureCounter} from './tools/MeasureCounter'; -test("dont_measure_single_grow_shrink_child", () => { +test('dont_measure_single_grow_shrink_child', () => { const root = Yoga.Node.create(); root.setWidth(100); root.setHeight(100); @@ -27,11 +27,11 @@ test("dont_measure_single_grow_shrink_child", () => { root.freeRecursive(); }); -test("dont_fail_with_incomplete_measure_dimensions", () => { +test('dont_fail_with_incomplete_measure_dimensions', () => { // @ts-expect-error Testing bad usage - const heightOnlyCallback = getMeasureCounter(() => ({ height: 10 })); + const heightOnlyCallback = getMeasureCounter(() => ({height: 10})); // @ts-expect-error Testing bad usage - const widthOnlyCallback = getMeasureCounter(() => ({ width: 10 })); + const widthOnlyCallback = getMeasureCounter(() => ({width: 10})); // @ts-expect-error Testing bad usage const emptyCallback = getMeasureCounter(() => ({})); diff --git a/javascript/tests/bin/run-bench.ts b/javascript/tests/bin/run-bench.ts index f71d5cf6..836f7f0b 100644 --- a/javascript/tests/bin/run-bench.ts +++ b/javascript/tests/bin/run-bench.ts @@ -8,7 +8,7 @@ * @format */ -import path from "path"; +import path from 'path'; const WARMUP_ITERATIONS = 3; const BENCHMARK_ITERATIONS = 10; @@ -17,10 +17,10 @@ const testFiles = process.argv.slice(2); const testResults = new Map>(); -for (const type of ["asmjs", "wasm"]) { - globalThis.Yoga = require(type === "asmjs" - ? "../../dist/entrypoint/asmjs-sync" - : "../../dist/entrypoint/wasm-sync"); +for (const type of ['asmjs', 'wasm']) { + globalThis.Yoga = require(type === 'asmjs' + ? '../../dist/entrypoint/asmjs-sync' + : '../../dist/entrypoint/wasm-sync'); for (const file of testFiles) { globalThis.YGBENCHMARK = (name: string, fn: () => void) => { @@ -42,14 +42,14 @@ for (const type of ["asmjs", "wasm"]) { const modulePath = path.resolve(file); - delete require.cache[require.resolve("../tools/globals")]; + delete require.cache[require.resolve('../tools/globals')]; delete require.cache[modulePath]; require(modulePath); } } console.log( - `Note: those tests are independants; there is no time relation to be expected between them` + `Note: those tests are independants; there is no time relation to be expected between them`, ); for (const [name, results] of testResults) { @@ -61,7 +61,7 @@ for (const [name, results] of testResults) { for (const [type, result] of results) { console.log( - ` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)` + ` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)`, ); } } diff --git a/javascript/tests/tools/MeasureCounter.ts b/javascript/tests/tools/MeasureCounter.ts index 20570631..542f0266 100644 --- a/javascript/tests/tools/MeasureCounter.ts +++ b/javascript/tests/tools/MeasureCounter.ts @@ -7,8 +7,8 @@ * @format */ -import type { MeasureFunction } from "yoga-layout"; -import { Yoga } from "./globals"; +import type {MeasureFunction} from 'yoga-layout'; +import {Yoga} from './globals'; export type MeasureCounter = { inc: MeasureFunction; @@ -18,7 +18,7 @@ export type MeasureCounter = { export function getMeasureCounter( cb?: MeasureFunction | null, staticWidth = 0, - staticHeight = 0 + staticHeight = 0, ): MeasureCounter { let counter = 0; @@ -28,7 +28,7 @@ export function getMeasureCounter( return cb ? cb(width, widthMode, height, heightMode) - : { width: staticWidth, height: staticHeight }; + : {width: staticWidth, height: staticHeight}; }, get: function () { @@ -44,7 +44,7 @@ export function getMeasureCounterMax(): MeasureCounter { const measuredHeight = heightMode === Yoga.MEASURE_MODE_UNDEFINED ? 10 : height; - return { width: measuredWidth, height: measuredHeight }; + return {width: measuredWidth, height: measuredHeight}; }); } @@ -61,6 +61,6 @@ export function getMeasureCounterMin(): MeasureCounter { ? 10 : height; - return { width: measuredWidth, height: measuredHeight }; + return {width: measuredWidth, height: measuredHeight}; }); } diff --git a/javascript/tests/tools/globals.ts b/javascript/tests/tools/globals.ts index 1f5131bd..e7d958a7 100644 --- a/javascript/tests/tools/globals.ts +++ b/javascript/tests/tools/globals.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import type { Yoga } from "yoga-layout"; +import type {Yoga} from 'yoga-layout'; declare global { // eslint-disable-next-line no-var @@ -24,4 +24,4 @@ if (globalThis.YGBENCHMARK === undefined) { const yoga = globalThis.Yoga; const benchmark = globalThis.YGBENCHMARK; -export { yoga as Yoga, benchmark as YGBENCHMARK }; +export {yoga as Yoga, benchmark as YGBENCHMARK};