diff --git a/scripts/tools/combine-tools.ts b/scripts/tools/combine-tools.ts index d8a79a50b23a..c9ebe8046b58 100644 --- a/scripts/tools/combine-tools.ts +++ b/scripts/tools/combine-tools.ts @@ -69,8 +69,7 @@ async function getFinalTool(toolObject: AsyncAPITool) { languageFuse = new Fuse(languageList, options); } } else { - // eslint-disable-next-line no-unsafe-optional-chaining - for (const language of toolObject?.filters?.language) { + for (const language of toolObject?.filters?.language ?? []) { const languageSearch = await languageFuse.search(language); if (languageSearch.length > 0) { @@ -95,8 +94,7 @@ async function getFinalTool(toolObject: AsyncAPITool) { const technologyArray = []; if (toolObject.filters.technology) { - // eslint-disable-next-line no-unsafe-optional-chaining - for (const technology of toolObject?.filters?.technology) { + for (const technology of toolObject?.filters?.technology ?? []) { const technologySearch = await technologyFuse.search(technology); if (technologySearch.length > 0) { @@ -125,42 +123,44 @@ async function getFinalTool(toolObject: AsyncAPITool) { // lists down all the language and technology tags in one JSON file. const combineTools = async (automatedTools: any, manualTools: any, toolsPath: string, tagsPath: string) => { try { - // eslint-disable-next-line no-restricted-syntax, guard-for-in + // eslint-disable-next-line no-restricted-syntax for (const key in automatedTools) { - const finalToolsList = []; + if (Object.prototype.hasOwnProperty.call(automatedTools, key)) { + const finalToolsList = []; - if (automatedTools[key].toolsList.length) { - for (const tool of automatedTools[key].toolsList) { - finalToolsList.push(await getFinalTool(tool)); + if (automatedTools[key].toolsList.length) { + for (const tool of automatedTools[key].toolsList) { + finalToolsList.push(await getFinalTool(tool)); + } } - } - if (manualTools[key]?.toolsList?.length) { - for (const tool of manualTools[key].toolsList) { - let isAsyncAPIrepo; - const isValid = await validate(tool); - - if (isValid) { - if (tool?.links?.repoUrl) { - const url = new URL(tool.links.repoUrl); - - isAsyncAPIrepo = url.href.startsWith('https://github.com/asyncapi/'); - } else isAsyncAPIrepo = false; - const toolObject = await createToolObject(tool, '', '', isAsyncAPIrepo); - - finalToolsList.push(await getFinalTool(toolObject)); - } else { - console.error({ - message: 'Tool validation failed', - tool: tool.title, - source: 'manual-tools.json', - errors: validate.errors, - note: 'Script continues execution, error logged for investigation' - }); + if (manualTools[key]?.toolsList?.length) { + for (const tool of manualTools[key].toolsList) { + let isAsyncAPIrepo; + const isValid = await validate(tool); + + if (isValid) { + if (tool?.links?.repoUrl) { + const url = new URL(tool.links.repoUrl); + + isAsyncAPIrepo = url.href.startsWith('https://github.com/asyncapi/'); + } else isAsyncAPIrepo = false; + const toolObject = await createToolObject(tool, '', '', isAsyncAPIrepo); + + finalToolsList.push(await getFinalTool(toolObject)); + } else { + console.error({ + message: 'Tool validation failed', + tool: tool.title, + source: 'manual-tools.json', + errors: validate.errors, + note: 'Script continues execution, error logged for investigation' + }); + } } } + finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title)); + finalTools[key].toolsList = finalToolsList; } - finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title)); - finalTools[key].toolsList = finalToolsList; } fs.writeFileSync(toolsPath, JSON.stringify(finalTools)); fs.writeFileSync(tagsPath, JSON.stringify({ languages: languageList, technologies: technologyList }));