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';