From 303ae21e2e34607c2ad73eb2ce78798344c01588 Mon Sep 17 00:00:00 2001 From: "Oliver H. Rangel" Date: Wed, 25 Apr 2018 19:24:57 -0500 Subject: [PATCH 1/2] Add ability to pass linter options resolve #187 Increase max lint errors --- lib/codegen.js | 65 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/lib/codegen.js b/lib/codegen.js index 54dbe7ef..4715f910 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -65,15 +65,15 @@ var getViewForSwagger2 = function(opts, type){ } var secureTypes = []; if(swagger.securityDefinitions !== undefined || op.security !== undefined) { - var mergedSecurity = _.merge([], swagger.security, op.security).map(function(security){ - return Object.keys(security); + var mergedSecurity = _.merge([], swagger.security, op.security).map(function(security){ + return Object.keys(security); }); - if(swagger.securityDefinitions) { - for(var sk in swagger.securityDefinitions) { + if(swagger.securityDefinitions) { + for(var sk in swagger.securityDefinitions) { if(mergedSecurity.join(',').indexOf(sk) !== -1){ - secureTypes.push(swagger.securityDefinitions[sk].type); + secureTypes.push(swagger.securityDefinitions[sk].type); } - } + } } } var methodName = (op.operationId ? normalizeName(op.operationId) : getPathToMethodName(opts, m, path)); @@ -101,22 +101,22 @@ var getViewForSwagger2 = function(opts, type){ summary: op.description || op.summary, externalDocs: op.externalDocs, isSecure: swagger.security !== undefined || op.security !== undefined, - isSecureToken: secureTypes.indexOf('oauth2') !== -1, - isSecureApiKey: secureTypes.indexOf('apiKey') !== -1, - isSecureBasic: secureTypes.indexOf('basic') !== -1, + isSecureToken: secureTypes.indexOf('oauth2') !== -1, + isSecureApiKey: secureTypes.indexOf('apiKey') !== -1, + isSecureBasic: secureTypes.indexOf('basic') !== -1, parameters: [], headers: [] }; - if(method.isSecure && method.isSecureToken) { - data.isSecureToken = method.isSecureToken; - } - if(method.isSecure && method.isSecureApiKey) { - data.isSecureApiKey = method.isSecureApiKey; - } - if(method.isSecure && method.isSecureBasic) { - data.isSecureBasic = method.isSecureBasic; - } - var produces = op.produces || swagger.produces; + if(method.isSecure && method.isSecureToken) { + data.isSecureToken = method.isSecureToken; + } + if(method.isSecure && method.isSecureApiKey) { + data.isSecureApiKey = method.isSecureApiKey; + } + if(method.isSecure && method.isSecureBasic) { + data.isSecureBasic = method.isSecureBasic; + } + var produces = op.produces || swagger.produces; if(produces) { method.headers.push({ name: 'Accept', @@ -277,24 +277,22 @@ var getCode = function(opts, type) { } var source = Mustache.render(opts.template.class, data, opts.template); - var lintOptions = { - node: type === 'node' || type === 'custom', - browser: type === 'angular' || type === 'custom' || type === 'react', - undef: true, - strict: true, - trailing: true, - smarttabs: true, - maxerr: 999 - }; - if (opts.esnext) { - lintOptions.esnext = true; - } - if(type === 'typescript') { + if (type === 'typescript') { opts.lint = false; } - if (opts.lint === undefined || opts.lint === true) { + if (opts.lint || opts.lint === undefined) { + var lintOptions = _.merge({ + node: type === 'node' || type === 'custom', + browser: type === 'angular' || type === 'custom' || type === 'react', + undef: true, + strict: true, + trailing: true, + smarttabs: true, + esnext = Boolean(opts.next), + maxerr: 999 + }, _.isObject(opts.lint) ? opts.lint : {}); lint(source, lintOptions); lint.errors.forEach(function(error) { if (error.code[0] === 'E') { @@ -302,6 +300,7 @@ var getCode = function(opts, type) { } }); } + if (opts.beautify === undefined || opts.beautify === true) { return beautify(source, { indent_size: 4, max_preserve_newlines: 2 }); } else { From 0466fdc77af2b9fb9914fad60c0aafd822a03c75 Mon Sep 17 00:00:00 2001 From: "Oliver H. Rangel" Date: Wed, 25 Apr 2018 19:30:27 -0500 Subject: [PATCH 2/2] Typo assignment on object --- lib/codegen.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/codegen.js b/lib/codegen.js index 4715f910..78896f8d 100644 --- a/lib/codegen.js +++ b/lib/codegen.js @@ -290,7 +290,7 @@ var getCode = function(opts, type) { strict: true, trailing: true, smarttabs: true, - esnext = Boolean(opts.next), + esnext: Boolean(opts.next), maxerr: 999 }, _.isObject(opts.lint) ? opts.lint : {}); lint(source, lintOptions);