Skip to content

Commit 303ae21

Browse files
committed
Add ability to pass linter options
resolve wcandillon#187 Increase max lint errors
1 parent e3920f2 commit 303ae21

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

lib/codegen.js

+32-33
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ var getViewForSwagger2 = function(opts, type){
6565
}
6666
var secureTypes = [];
6767
if(swagger.securityDefinitions !== undefined || op.security !== undefined) {
68-
var mergedSecurity = _.merge([], swagger.security, op.security).map(function(security){
69-
return Object.keys(security);
68+
var mergedSecurity = _.merge([], swagger.security, op.security).map(function(security){
69+
return Object.keys(security);
7070
});
71-
if(swagger.securityDefinitions) {
72-
for(var sk in swagger.securityDefinitions) {
71+
if(swagger.securityDefinitions) {
72+
for(var sk in swagger.securityDefinitions) {
7373
if(mergedSecurity.join(',').indexOf(sk) !== -1){
74-
secureTypes.push(swagger.securityDefinitions[sk].type);
74+
secureTypes.push(swagger.securityDefinitions[sk].type);
7575
}
76-
}
76+
}
7777
}
7878
}
7979
var methodName = (op.operationId ? normalizeName(op.operationId) : getPathToMethodName(opts, m, path));
@@ -101,22 +101,22 @@ var getViewForSwagger2 = function(opts, type){
101101
summary: op.description || op.summary,
102102
externalDocs: op.externalDocs,
103103
isSecure: swagger.security !== undefined || op.security !== undefined,
104-
isSecureToken: secureTypes.indexOf('oauth2') !== -1,
105-
isSecureApiKey: secureTypes.indexOf('apiKey') !== -1,
106-
isSecureBasic: secureTypes.indexOf('basic') !== -1,
104+
isSecureToken: secureTypes.indexOf('oauth2') !== -1,
105+
isSecureApiKey: secureTypes.indexOf('apiKey') !== -1,
106+
isSecureBasic: secureTypes.indexOf('basic') !== -1,
107107
parameters: [],
108108
headers: []
109109
};
110-
if(method.isSecure && method.isSecureToken) {
111-
data.isSecureToken = method.isSecureToken;
112-
}
113-
if(method.isSecure && method.isSecureApiKey) {
114-
data.isSecureApiKey = method.isSecureApiKey;
115-
}
116-
if(method.isSecure && method.isSecureBasic) {
117-
data.isSecureBasic = method.isSecureBasic;
118-
}
119-
var produces = op.produces || swagger.produces;
110+
if(method.isSecure && method.isSecureToken) {
111+
data.isSecureToken = method.isSecureToken;
112+
}
113+
if(method.isSecure && method.isSecureApiKey) {
114+
data.isSecureApiKey = method.isSecureApiKey;
115+
}
116+
if(method.isSecure && method.isSecureBasic) {
117+
data.isSecureBasic = method.isSecureBasic;
118+
}
119+
var produces = op.produces || swagger.produces;
120120
if(produces) {
121121
method.headers.push({
122122
name: 'Accept',
@@ -277,31 +277,30 @@ var getCode = function(opts, type) {
277277
}
278278

279279
var source = Mustache.render(opts.template.class, data, opts.template);
280-
var lintOptions = {
281-
node: type === 'node' || type === 'custom',
282-
browser: type === 'angular' || type === 'custom' || type === 'react',
283-
undef: true,
284-
strict: true,
285-
trailing: true,
286-
smarttabs: true,
287-
maxerr: 999
288-
};
289-
if (opts.esnext) {
290-
lintOptions.esnext = true;
291-
}
292280

293-
if(type === 'typescript') {
281+
if (type === 'typescript') {
294282
opts.lint = false;
295283
}
296284

297-
if (opts.lint === undefined || opts.lint === true) {
285+
if (opts.lint || opts.lint === undefined) {
286+
var lintOptions = _.merge({
287+
node: type === 'node' || type === 'custom',
288+
browser: type === 'angular' || type === 'custom' || type === 'react',
289+
undef: true,
290+
strict: true,
291+
trailing: true,
292+
smarttabs: true,
293+
esnext = Boolean(opts.next),
294+
maxerr: 999
295+
}, _.isObject(opts.lint) ? opts.lint : {});
298296
lint(source, lintOptions);
299297
lint.errors.forEach(function(error) {
300298
if (error.code[0] === 'E') {
301299
throw new Error(error.reason + ' in ' + error.evidence + ' (' + error.code + ')');
302300
}
303301
});
304302
}
303+
305304
if (opts.beautify === undefined || opts.beautify === true) {
306305
return beautify(source, { indent_size: 4, max_preserve_newlines: 2 });
307306
} else {

0 commit comments

Comments
 (0)