diff --git a/apps/generator/lib/generator.js b/apps/generator/lib/generator.js index cb4ffe950..8b2592a6f 100644 --- a/apps/generator/lib/generator.js +++ b/apps/generator/lib/generator.js @@ -134,7 +134,7 @@ class Generator { Object.defineProperty(this.templateParams, key, { enumerable: true, get() { - if (!self.templateConfig.parameters || !self.templateConfig.parameters[key]) { + if (!self.templateConfig.parameters?.[key]) { throw new Error(`Template parameter "${key}" has not been defined in the package.json file under generator property. Please make sure it's listed there before you use it in your template.`); } return templateParams[key]; diff --git a/apps/generator/lib/templateConfigValidator.js b/apps/generator/lib/templateConfigValidator.js index 3b57ef759..9e075b98b 100644 --- a/apps/generator/lib/templateConfigValidator.js +++ b/apps/generator/lib/templateConfigValidator.js @@ -97,7 +97,7 @@ function getParamSuggestion(wrongParam, configParams) { * @param {Object} templateParams All parameters provided to generator */ function isProvidedParameterSupported(configParams, templateParams) { - const wrongParams = Object.keys(templateParams || {}).filter(key => !configParams || !configParams[key]); + const wrongParams = Object.keys(templateParams || {}).filter(key => !configParams?.[key]); if (!wrongParams.length) return; if (!configParams) throw new Error('This template doesn\'t have any params.'); diff --git a/apps/generator/test/renderer.test.js b/apps/generator/test/renderer.test.js index f6c0c6458..bd1a6489e 100644 --- a/apps/generator/test/renderer.test.js +++ b/apps/generator/test/renderer.test.js @@ -10,8 +10,8 @@ jest.mock('@asyncapi/generator-react-sdk'); describe('React renderer', () => { describe('saveRenderedReactContent', () => { - let util = undefined; - let AsyncReactSDK = undefined; + let util; + let AsyncReactSDK; beforeAll(() => { util = require('../lib/utils'); AsyncReactSDK = require('@asyncapi/generator-react-sdk'); diff --git a/apps/nunjucks-filters/src/customFilters.js b/apps/nunjucks-filters/src/customFilters.js index 83ef06fbb..0914c821a 100644 --- a/apps/nunjucks-filters/src/customFilters.js +++ b/apps/nunjucks-filters/src/customFilters.js @@ -150,9 +150,11 @@ function docline(field, fieldName, scopePropName) { const getPName = (pName) => pName ? `${pName}.` : ''; const buildLineCore = (type, def, pName, fName) => { - return `* @param {${type}} ${pName}${fName}${def !== undefined ? `=${def}` : ''}`; + const paramName = `${pName}${fName}`; + const defaultValue = def !== undefined ? `=${def}` : ''; + return `* @param {${type}} ${paramName}${defaultValue}`; }; - + const buildLine = (f, fName, pName) => { const type = getType(f); const def = getDefault(f, type);