From c131a5694b9e9b9dc62fa1a7c7f361e93910c7a2 Mon Sep 17 00:00:00 2001 From: Helder Oliveira Date: Thu, 15 Aug 2024 15:30:22 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20lint=20issues=20over=20no?= =?UTF-8?q?de=20protocol=20and=20switch=20statement=20(#18)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Why? Lint issues over node protocol and switch statement ## How? - Use node protocol - Wrap switch cases to enforce scope for declared variables ## Tickets? - [Ticket 1](the-ticket-url-here) - [Ticket 2](the-ticket-url-here) - [Ticket 3](the-ticket-url-here) ## Contribution checklist? - [ ] The commit messages are detailed - [ ] The `build` command runs locally - [ ] Assets or static content are linked and stored in the project - [ ] You have manually tested - [ ] You have provided tests ## Security checklist? - [ ] Sensitive data has been identified and is being protected properly - [ ] Injection has been prevented (parameterized queries, no eval or system calls) ## Preview? Optionally, provide the preview url here --------- Co-authored-by: GitHub Action --- src/commands/functions/utils/getCodeFromPath.ts | 2 +- src/commands/sites/init.ts | 2 +- .../prompts/selectConfigurationFormatPrompt.ts | 2 +- src/commands/sites/utils/initConfiguration.ts | 4 ++-- .../sites/utils/prepareGitHubActionsIntegration.ts | 2 +- src/guards/sitesGuard.ts | 2 +- src/utils/configuration/saveConfiguration.test.ts | 14 +++++++------- src/utils/configuration/saveConfiguration.ts | 13 ++++++++----- src/utils/formats.test.ts | 2 +- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/commands/functions/utils/getCodeFromPath.ts b/src/commands/functions/utils/getCodeFromPath.ts index 1bfed56..72de602 100644 --- a/src/commands/functions/utils/getCodeFromPath.ts +++ b/src/commands/functions/utils/getCodeFromPath.ts @@ -1,6 +1,6 @@ -import path from 'path'; import * as fs from 'node:fs'; import * as os from 'node:os'; +import path from 'node:path'; // TODO: These error messages should be revised // e.g. FleekFunctionPathNotValidError happens regardless of bundling diff --git a/src/commands/sites/init.ts b/src/commands/sites/init.ts index fdaea6a..724a658 100644 --- a/src/commands/sites/init.ts +++ b/src/commands/sites/init.ts @@ -10,8 +10,8 @@ import { withGuards } from '../../guards/withGuards'; import { loadConfiguration } from '../../utils/configuration/loadConfiguration'; import { t } from '../../utils/translation'; import { confirmFileOverridePrompt } from './prompts/confirmFileOverridePrompt'; -import { initConfiguration } from './utils/initConfiguration'; import { chooseOrCreateSite } from './utils/chooseOrCreateSite'; +import { initConfiguration } from './utils/initConfiguration'; const initAction: SdkGuardedFunction = async ({ sdk }) => { const configLoadingResult = await loadConfiguration({}) diff --git a/src/commands/sites/prompts/selectConfigurationFormatPrompt.ts b/src/commands/sites/prompts/selectConfigurationFormatPrompt.ts index 3ab95af..1a3ccb8 100644 --- a/src/commands/sites/prompts/selectConfigurationFormatPrompt.ts +++ b/src/commands/sites/prompts/selectConfigurationFormatPrompt.ts @@ -1,6 +1,6 @@ import { selectPrompt } from '../../../prompts/selectPrompt'; -import { t } from '../../../utils/translation'; import { getConfigFileByTypeValue } from '../../../utils/configuration'; +import { t } from '../../../utils/translation'; import { FleekSiteConfigFormats } from '../../../utils/configuration/types'; diff --git a/src/commands/sites/utils/initConfiguration.ts b/src/commands/sites/utils/initConfiguration.ts index abbb0ba..5c956f5 100644 --- a/src/commands/sites/utils/initConfiguration.ts +++ b/src/commands/sites/utils/initConfiguration.ts @@ -2,12 +2,12 @@ import type { Site } from '@fleek-platform/sdk'; import { saveConfiguration } from '../../../utils/configuration/saveConfiguration'; import type { FleekRootConfig } from '../../../utils/configuration/types'; +import { isValidFleekConfigFormat } from '../../../utils/formats'; +import { fileExists } from '../../../utils/fs'; import { t } from '../../../utils/translation'; import { enterDirectoryPathPrompt } from '../prompts/enterDirectoryPathPrompt'; import { selectConfigurationFormatPrompt } from '../prompts/selectConfigurationFormatPrompt'; import { selectBuildCommandOrSkip } from './selectBuildCommandOrSkip'; -import { isValidFleekConfigFormat } from '../../../utils/formats'; -import { fileExists } from '../../../utils/fs'; type InitConfigurationArgs = { site: Site; diff --git a/src/commands/sites/utils/prepareGitHubActionsIntegration.ts b/src/commands/sites/utils/prepareGitHubActionsIntegration.ts index 863d160..2404690 100644 --- a/src/commands/sites/utils/prepareGitHubActionsIntegration.ts +++ b/src/commands/sites/utils/prepareGitHubActionsIntegration.ts @@ -2,8 +2,8 @@ import { join as joinPath } from 'node:path'; import { generateDeploymentWorkflowYaml } from '@fleek-platform/utils-github'; import type { Output } from '../../../output/Output'; -import { confirmFileOverridePrompt } from '../prompts/confirmFileOverridePrompt'; import { fileExists } from '../../../utils/fs'; +import { confirmFileOverridePrompt } from '../prompts/confirmFileOverridePrompt'; import { getDeploymentWorkflowYamlLocation } from './getDeploymentWorkflowYamlLocation'; import { initializeDeploymentWorkflowDirectory } from './initializeDeploymentWorkflowDirectory'; import { requestDeploymentWorkflowInstallCommand } from './requestDeploymentWorkflowInstallCommand'; diff --git a/src/guards/sitesGuard.ts b/src/guards/sitesGuard.ts index 0a301d7..8a8bb2a 100644 --- a/src/guards/sitesGuard.ts +++ b/src/guards/sitesGuard.ts @@ -1,9 +1,9 @@ import { output } from '../cli'; +import { chooseOrCreateSite } from '../commands/sites/utils/chooseOrCreateSite'; import { initConfiguration } from '../commands/sites/utils/initConfiguration'; import { loadConfiguration } from '../utils/configuration/loadConfiguration'; import { t } from '../utils/translation'; import { getSdkClient } from './sdkGuard'; -import { chooseOrCreateSite } from '../commands/sites/utils/chooseOrCreateSite'; export const sitesGuard = async ({ predefinedConfigPath, diff --git a/src/utils/configuration/saveConfiguration.test.ts b/src/utils/configuration/saveConfiguration.test.ts index 97584b1..659a695 100644 --- a/src/utils/configuration/saveConfiguration.test.ts +++ b/src/utils/configuration/saveConfiguration.test.ts @@ -1,14 +1,14 @@ -import { describe, expect, it, beforeEach, afterEach } from 'vitest'; -import { type FleekRootConfig, FleekSiteConfigFormats } from './types'; -import { saveConfiguration } from './saveConfiguration'; -import fs from 'fs/promises'; -import path from 'path'; -import ts from 'typescript'; -import { fileExists } from '../fs'; +import fs from 'node:fs/promises'; +import path from 'node:path'; import { ExpectedOneOfValuesError, InvalidJSONFormat, } from '@fleek-platform/errors'; +import ts from 'typescript'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { fileExists } from '../fs'; +import { saveConfiguration } from './saveConfiguration'; +import { type FleekRootConfig, FleekSiteConfigFormats } from './types'; const clearConfigFile = async ({ configFilePath, diff --git a/src/utils/configuration/saveConfiguration.ts b/src/utils/configuration/saveConfiguration.ts index ebaf96c..9c3168e 100644 --- a/src/utils/configuration/saveConfiguration.ts +++ b/src/utils/configuration/saveConfiguration.ts @@ -1,10 +1,10 @@ import { promises as fs } from 'node:fs'; -import path from 'path'; +import path from 'node:path'; import { + FLEEK_CONFIG_TMPL_JSON_PLACEHOLDER, getConfigFileByTypeName, getConfigTemplateByTypeName, - FLEEK_CONFIG_TMPL_JSON_PLACEHOLDER, } from '../configuration'; import { type FleekRootConfig, FleekSiteConfigFormats } from './types'; @@ -57,7 +57,7 @@ export const saveConfiguration = async ({ let configFile: ConfigFilePath; switch (format) { - case FleekSiteConfigFormats.Typescript: + case FleekSiteConfigFormats.Typescript: { const contentForTypescriptConfig = ( await fs.readFile(filePathForTypescriptConfig) ).toString(); @@ -67,7 +67,8 @@ export const saveConfiguration = async ({ ); configFile = getConfigFileByTypeName('Typescript'); break; - case FleekSiteConfigFormats.Javascript: + } + case FleekSiteConfigFormats.Javascript: { const contentForJavascriptConfig = ( await fs.readFile(filePathForJavascriptConfig) ).toString(); @@ -77,10 +78,12 @@ export const saveConfiguration = async ({ ); configFile = getConfigFileByTypeName('Javascript'); break; - case FleekSiteConfigFormats.JSON: + } + case FleekSiteConfigFormats.JSON: { content = formattedOutput; configFile = getConfigFileByTypeName('JSON'); break; + } } try { diff --git a/src/utils/formats.test.ts b/src/utils/formats.test.ts index cf4a8e0..fcb759e 100644 --- a/src/utils/formats.test.ts +++ b/src/utils/formats.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest'; -import { isValidFleekConfigFormat } from './formats'; import { FleekSiteConfigFormats } from './configuration'; +import { isValidFleekConfigFormat } from './formats'; describe('In the Formats utils', () => { describe('isValidFleekConfigFormat', () => {