From 639d8645b08a9a34200e13a546da10c1ad1682ff Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 16 Jun 2023 00:41:06 +0000 Subject: [PATCH] feat: support context file location in repository --- .sonarcloud.properties | 2 ++ sonar-project.properties | 3 +-- src/models/Context.ts | 12 ++++++------ test/commands/context.test.ts | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 .sonarcloud.properties diff --git a/.sonarcloud.properties b/.sonarcloud.properties new file mode 100644 index 00000000000..c3a36e384f4 --- /dev/null +++ b/.sonarcloud.properties @@ -0,0 +1,2 @@ +sonar.sources = src/ +sonar.tests = test/ diff --git a/sonar-project.properties b/sonar-project.properties index 3a368ff251f..f68aa6a9f6f 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,2 +1 @@ -sonar.exclusions=test/minimaltemplate/**/* -sonar.exclusions=test/**/* \ No newline at end of file +sonar.exclusions=test/minimaltemplate/**/* \ No newline at end of file diff --git a/src/models/Context.ts b/src/models/Context.ts index d51e92be21a..811a2c2b7d9 100644 --- a/src/models/Context.ts +++ b/src/models/Context.ts @@ -17,8 +17,8 @@ const DEFAULT_CONTEXT_FILENAME = '.asyncapi-cli'; const DEFAULT_CONTEXT_FILE_LOCATION = os.homedir(); export const DEFAULT_CONTEXT_FILE_PATH = path.resolve(DEFAULT_CONTEXT_FILE_LOCATION, DEFAULT_CONTEXT_FILENAME); -const CONTEXT_FILENAME = process.env.CUSTOM_CONTEXT_FILENAME || DEFAULT_CONTEXT_FILENAME; -const CONTEXT_FILE_LOCATION = process.env.CUSTOM_CONTEXT_FILE_LOCATION || DEFAULT_CONTEXT_FILE_LOCATION; +const CONTEXT_FILENAME = process.env.CUSTOM_CONTEXT_FILENAME ?? DEFAULT_CONTEXT_FILENAME; +const CONTEXT_FILE_LOCATION = process.env.CUSTOM_CONTEXT_FILE_LOCATION ?? DEFAULT_CONTEXT_FILE_LOCATION; // Usage of promises for assignment of their resolved values to constants is // known to be troublesome: @@ -60,7 +60,7 @@ export interface ICurrentContext { } export async function loadContext(contextName?: string): Promise { - const fileContent = await loadContextFile(); + const fileContent: IContextFile = await loadContextFile(); if (contextName) { const context = fileContent.store[String(contextName)]; if (!context) {throw new ContextNotFound(contextName);} @@ -101,7 +101,7 @@ export async function addContext(contextName: string, pathToFile: string) { } export async function removeContext(contextName: string) { - const fileContent = await loadContextFile(); + const fileContent: IContextFile = await loadContextFile(); if (!fileContent.store[String(contextName)]) { throw new ContextNotFound(contextName); } @@ -113,7 +113,7 @@ export async function removeContext(contextName: string) { } export async function getCurrentContext(): Promise { - const fileContent = await loadContextFile(); + const fileContent: IContextFile = await loadContextFile(); const context = await loadContext(); return { current: fileContent.current as string, @@ -122,7 +122,7 @@ export async function getCurrentContext(): Promise { } export async function setCurrentContext(contextName: string) { - const fileContent = await loadContextFile(); + const fileContent: IContextFile = await loadContextFile(); if (!fileContent.store[String(contextName)]) { throw new ContextNotFound(contextName); } diff --git a/test/commands/context.test.ts b/test/commands/context.test.ts index 7da174bbbb5..e27c2bb672e 100644 --- a/test/commands/context.test.ts +++ b/test/commands/context.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-duplicate-string */ import path from 'path'; import { test } from '@oclif/test';