From ec650411e4110884e3d2aacec367b0d66aaebc49 Mon Sep 17 00:00:00 2001 From: Henrique Almeida Date: Sun, 31 Mar 2024 13:47:56 +0200 Subject: [PATCH] lint --- .eslintrc | 55 +++++++++++++++++++++++++++++++------- package.json | 5 ++-- src/checkDifferences.ts | 17 ++++++------ src/createShots.ts | 38 +++++++++++++++++--------- src/docker-runner/utils.ts | 4 ++- src/runner.ts | 8 +++--- src/shots/shots.ts | 34 +++++++++++------------ 7 files changed, 104 insertions(+), 57 deletions(-) diff --git a/.eslintrc b/.eslintrc index 6e888e1e..55fc1abe 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,12 @@ { - "plugins": ["@typescript-eslint", "unicorn"], - "extends": ["plugin:@typescript-eslint/recommended", "prettier"], + "plugins": [ + "@typescript-eslint", + "unicorn" + ], + "extends": [ + "plugin:@typescript-eslint/recommended", + "prettier" + ], "rules": { "@typescript-eslint/no-unused-vars": "error", "@typescript-eslint/no-explicit-any": "error", @@ -9,15 +15,44 @@ "no-console": "error", "@typescript-eslint/padding-line-between-statements": [ "error", - { "blankLine": "always", "prev": ["const", "let"], "next": "*" }, + { + "blankLine": "always", + "prev": [ + "const", + "let" + ], + "next": "*" + }, { "blankLine": "any", - "prev": ["const", "let"], - "next": ["const", "let"] + "prev": [ + "const", + "let" + ], + "next": [ + "const", + "let" + ] }, - { "blankLine": "always", "prev": ["*"], "next": ["if", "return"] }, - { "blankLine": "always", "prev": ["*"], "next": ["try"] } - ], - "no-await-in-loop": "off" + { + "blankLine": "always", + "prev": [ + "*" + ], + "next": [ + "if", + "return" + ] + }, + { + "blankLine": "always", + "prev": [ + "*" + ], + "next": [ + "try" + ] + } + ] } -} +} \ No newline at end of file diff --git a/package.json b/package.json index fc433cba..6f6706e5 100644 --- a/package.json +++ b/package.json @@ -131,7 +131,8 @@ "n/file-extension-in-import": "off", "no-lone-blocks": "off", "capitalized-comments": "off", - "unicorn/prefer-ternary": "off" + "unicorn/prefer-ternary": "off", + "no-await-in-loop": "off" } } -} +} \ No newline at end of file diff --git a/src/checkDifferences.ts b/src/checkDifferences.ts index c0fe8c40..8ebdaf40 100644 --- a/src/checkDifferences.ts +++ b/src/checkDifferences.ts @@ -122,8 +122,8 @@ export const checkDifferences = async ( addDifferenceToDifferences({ difference, differences, - shotItem: item[1] - }) + shotItem: item[1], + }); }, ); @@ -135,11 +135,11 @@ export const checkDifferences = async ( export const addDifferenceToDifferences = ({ difference, differences, - shotItem + shotItem, }: { - shotItem: ShotItem, - differences: Differences, - difference: Difference + shotItem: ShotItem; + differences: Differences; + difference: Difference; }) => { if (difference.status === 'added') differences.noBaselinesItems.push(shotItem); @@ -147,6 +147,5 @@ export const addDifferenceToDifferences = ({ differences.aboveThresholdDifferenceItems.push(shotItem); if (difference.comparisonResult) - differences.comparisonResults[shotItem.id] = - difference.comparisonResult; -} + differences.comparisonResults[shotItem.id] = difference.comparisonResult; +}; diff --git a/src/createShots.ts b/src/createShots.ts index b901ea7c..b2165b1c 100644 --- a/src/createShots.ts +++ b/src/createShots.ts @@ -33,8 +33,10 @@ import { import type { Differences } from './checkDifferences'; import { takeScreenShots } from './shots/shots'; -export const createShots = async ({ compareAfterShot }: { - compareAfterShot?: boolean +export const createShots = async ({ + compareAfterShot, +}: { + compareAfterShot?: boolean; } = {}): Promise<{ shotItems: ShotItem[]; /** Defined if using compareAfterShot option */ @@ -59,9 +61,7 @@ export const createShots = async ({ compareAfterShot }: { noBaselinesItems: [], }; - const mergeDifferences = (props: { - differences?: Differences; - }) => { + const mergeDifferences = (props: { differences?: Differences }) => { differences.aboveThresholdDifferenceItems.push( ...(props.differences?.aboveThresholdDifferenceItems ?? []), ); @@ -125,11 +125,14 @@ export const createShots = async ({ compareAfterShot }: { log.process( 'info', 'general', - `Prepared ${shotItems.length + `Prepared ${ + shotItems.length } ladle stories for screenshots on ${browser.name()}`, ); - mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot })); + mergeDifferences( + await takeScreenShots(shotItems, { browser, compareAfterShot }), + ); }); localServer?.close(); @@ -192,11 +195,14 @@ export const createShots = async ({ compareAfterShot }: { log.process( 'info', 'general', - `Prepared ${shotItems.length + `Prepared ${ + shotItems.length } Histoire stories for screenshots on ${browser.name()}`, ); - mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot })); + mergeDifferences( + await takeScreenShots(shotItems, { browser, compareAfterShot }), + ); }); localServer?.close(); @@ -258,11 +264,14 @@ export const createShots = async ({ compareAfterShot }: { log.process( 'info', 'general', - `Prepared ${shotItems.length + `Prepared ${ + shotItems.length } stories for screenshots on ${browser.name()}`, ); - mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot })); + mergeDifferences( + await takeScreenShots(shotItems, { browser, compareAfterShot }), + ); }); localServer?.close(); @@ -317,11 +326,14 @@ export const createShots = async ({ compareAfterShot }: { log.process( 'info', 'general', - `Prepared ${shotItems.length + `Prepared ${ + shotItems.length } pages for screenshots on ${browser.name()}`, ); - mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot })); + mergeDifferences( + await takeScreenShots(shotItems, { browser, compareAfterShot }), + ); }); log.process('info', 'general', 'Screenshots done!'); diff --git a/src/docker-runner/utils.ts b/src/docker-runner/utils.ts index 37d5ef5e..9ad6e140 100644 --- a/src/docker-runner/utils.ts +++ b/src/docker-runner/utils.ts @@ -28,7 +28,9 @@ export const executeDockerRun = async ({ version }: { version: string }) => { isGenerateMetaEnabled ? '-e LOST_PIXEL_GENERATE_META=true' : '', isLocalDebugModeEnabled ? '-e LOST_PIXEL_LOCAL=true' : '', // Usage: npx lost-pixel docker --dockerArgs="x y -z" - ...(argv.dockerArgs ? argv.dockerArgs.split(' ').filter(arg => arg.trim()) : []), + ...(argv.dockerArgs + ? argv.dockerArgs.split(' ').filter((arg) => arg.trim()) + : []), `lostpixel/lost-pixel:v${version}`, ]; diff --git a/src/runner.ts b/src/runner.ts index 13f736c9..4746ee07 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -1,9 +1,6 @@ import path from 'node:path'; import fse, { writeFileSync } from 'fs-extra'; -import { - checkDifferences, - type Differences, -} from './checkDifferences'; +import { checkDifferences, type Differences } from './checkDifferences'; import { createShotsFolders, exitProcess, @@ -91,7 +88,8 @@ export const runner = async (config: GenerateOnlyModeConfig) => { log.process( 'info', 'general', - `Writing meta file with ${Object.entries(differences.comparisonResults).length + `Writing meta file with ${ + Object.entries(differences.comparisonResults).length } items.`, ); writeFileSync( diff --git a/src/shots/shots.ts b/src/shots/shots.ts index 22ad2dc6..b36c0121 100644 --- a/src/shots/shots.ts +++ b/src/shots/shots.ts @@ -21,12 +21,12 @@ const takeScreenShot = async ({ browser, item: [index, shotItem], logger, - compareAfterShot + compareAfterShot, }: { browser: Browser; item: [number, ShotItem]; logger: ReturnType; - compareAfterShot?: boolean + compareAfterShot?: boolean; }): Promise<{ success: boolean; /** Defined if using compareAfterShot */ @@ -158,8 +158,7 @@ const takeScreenShot = async ({ retryCount <= config.flakynessRetries; retryCount++ ) { - if (retryCount > 0) - await sleep(config.waitBetweenFlakynessRetries); + if (retryCount > 0) await sleep(config.waitBetweenFlakynessRetries); const screenshotOptions: PageScreenshotOptions = { path: shotItem.filePathCurrent, @@ -202,8 +201,7 @@ const takeScreenShot = async ({ `Screenshot of '${shotItem.shotName}' taken (Retry ${retryCount}). Hash: ${currentShotHash} - Previous hash: ${lastShotHash}`, ); - if (lastShotHash === currentShotHash) - break; + if (lastShotHash === currentShotHash) break; } lastShotHash = currentShotHash; @@ -240,21 +238,20 @@ const takeScreenShot = async ({ export const takeScreenShots = async ( shotItems: ShotItem[], props: { - browser?: BrowserType, - compareAfterShot?: boolean - } + browser?: BrowserType; + compareAfterShot?: boolean; + }, ): Promise<{ differences?: Differences }> => { const browser = await (props.browser ?? getBrowser()).launch(); const total = shotItems.length; - const differences: Differences | undefined = - props.compareAfterShot - ? { + const differences: Differences | undefined = props.compareAfterShot + ? { aboveThresholdDifferenceItems: [], comparisonResults: {}, noBaselinesItems: [], } - : undefined; + : undefined; await mapLimit<[number, ShotItem], void>( shotItems.entries(), @@ -271,7 +268,8 @@ export const takeScreenShots = async ( logger.process( 'info', 'general', - `Taking screenshot of '${shotItem.shotName} ${shotItem.breakpoint ? `[${shotItem.breakpoint}]` : '' + `Taking screenshot of '${shotItem.shotName} ${ + shotItem.breakpoint ? `[${shotItem.breakpoint}]` : '' }'`, ); @@ -288,8 +286,11 @@ export const takeScreenShots = async ( ); if (config.compareAfterShot && differences && result.difference) - addDifferenceToDifferences({ difference: result.difference, differences, shotItem }); - + addDifferenceToDifferences({ + difference: result.difference, + differences, + shotItem, + }); } else { logger.process( 'info', @@ -304,4 +305,3 @@ export const takeScreenShots = async ( return { differences }; }; -