Skip to content

Commit bd39ad4

Browse files
committed
Merge pull request victorjonsson#309 from Igloczek/js-hint-errrors-fix
Most of JS Hint errors resolved
2 parents 7ab1aed + 8be62f7 commit bd39ad4

File tree

11 files changed

+264
-221
lines changed

11 files changed

+264
-221
lines changed

form-validator/brazil.dev.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ $.formUtils.addValidator({
2222
// http://www.devmedia.com.br/validar-cpf-com-javascript/23916
2323

2424
// clean up the input (digits only) and set some support vars
25-
var cpf = string.replace(/\D/g,"");
25+
var cpf = string.replace(/\D/g,'');
2626
var sum1 = 0;
2727
var sum2 = 0;
2828
var remainder1 = 0;
2929
var remainder2 = 0;
3030

3131
// skip special cases
32-
if (cpf.length != 11 || cpf == "00000000000") {
32+
if (cpf.length !== 11 || cpf === '00000000000') {
3333
return false;
3434
}
3535

3636
// check 1st verification digit
37-
for (i=1; i<=9; i++) {
37+
for (i = 1; i<= 9; i++) {
3838
sum1 += parseInt(cpf.substring(i - 1, i)) * (11 - i);
3939
}
4040
remainder1 = (sum1 * 10) % 11;
4141
if (remainder1 >= 10) {
4242
remainder1 = 0;
4343
}
44-
if (remainder1 != parseInt(cpf.substring(9, 10))) {
44+
if (remainder1 !== parseInt(cpf.substring(9, 10))) {
4545
return false;
4646
}
4747

@@ -53,7 +53,7 @@ $.formUtils.addValidator({
5353
if (remainder2 >= 10) {
5454
remainder2 = 0;
5555
}
56-
if (remainder2 != parseInt(cpf.substring(10, 11))) {
56+
if (remainder2 !== parseInt(cpf.substring(10, 11))) {
5757
return false;
5858
}
5959

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
if($el.valAttr('format')) {
4646
dateFormat = $el.valAttr('format');
4747
}
48-
else if(typeof conf.dateFormat != 'undefined') {
48+
else if(typeof conf.dateFormat !== 'undefined') {
4949
dateFormat = conf.dateFormat;
5050
}
5151

form-validator/file.dev.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616

1717
'use strict';
1818

19-
var SUPPORTS_FILE_READER = typeof window.FileReader != 'undefined',
19+
var SUPPORTS_FILE_READER = typeof window.FileReader !== 'undefined',
2020

2121
/**
2222
* @return {Array}
2323
*/
2424
_getTypes = function($input) {
2525
var allowedTypes = $.split( ($input.valAttr('allowing') || '').toLowerCase() );
26-
if( $.inArray('jpg', allowedTypes) > -1 && $.inArray('jpeg', allowedTypes) == -1)
26+
if ($.inArray('jpg', allowedTypes) > -1 && $.inArray('jpeg', allowedTypes) === -1) {
2727
allowedTypes.push('jpeg');
28-
else if( $.inArray('jpeg', allowedTypes) > -1 && $.inArray('jpg', allowedTypes) == -1)
28+
}
29+
else if ($.inArray('jpeg', allowedTypes) > -1 && $.inArray('jpg', allowedTypes) === -1) {
2930
allowedTypes.push('jpg');
31+
}
3032
return allowedTypes;
3133
},
3234

@@ -133,10 +135,10 @@
133135
allowedTypes = _getTypes($input);
134136

135137
$.each($input.get(0).files || [value], function(i, file) {
136-
var val = typeof file == 'string' ? file : (file.value || file.fileName || file.name),
138+
var val = typeof file === 'string' ? file : (file.value || file.fileName || file.name),
137139
ext = val.substr( val.lastIndexOf('.')+1 );
138140

139-
if( $.inArray(ext.toLowerCase(), allowedTypes) == -1 ) {
141+
if( $.inArray(ext.toLowerCase(), allowedTypes) === -1 ) {
140142
valid = false;
141143
_generateErrorMsg(_this, 'wrongFileType', allowedTypes.join(', '), language);
142144
return false;
@@ -187,13 +189,13 @@
187189
*/
188190
$.formUtils.convertSizeNameToBytes = function(sizeName) {
189191
sizeName = sizeName.toUpperCase();
190-
if( sizeName.substr(sizeName.length-1, 1) == 'M' ) {
192+
if( sizeName.substr(sizeName.length-1, 1) === 'M' ) {
191193
return parseInt(sizeName.substr(0, sizeName.length-1), 10) * 1024 * 1024;
192-
} else if( sizeName.substr(sizeName.length-2, 2) == 'MB' ) {
194+
} else if( sizeName.substr(sizeName.length-2, 2) === 'MB' ) {
193195
return parseInt(sizeName.substr(0, sizeName.length-2), 10) * 1024 * 1024;
194-
} else if( sizeName.substr(sizeName.length-2, 2) == 'KB' ) {
196+
} else if( sizeName.substr(sizeName.length-2, 2) === 'KB' ) {
195197
return parseInt(sizeName.substr(0, sizeName.length-2), 10) * 1024;
196-
} else if( sizeName.substr(sizeName.length-1, 1) == 'B' ) {
198+
} else if( sizeName.substr(sizeName.length-1, 1) === 'B' ) {
197199
return parseInt(sizeName.substr(0, sizeName.length-1), 10);
198200
} else {
199201
return parseInt(sizeName, 10);
@@ -223,7 +225,7 @@
223225
maxDeclaration = false,
224226
declarationParts = dimDeclaration.split('-');
225227

226-
if( declarationParts.length == 1 ) {
228+
if( declarationParts.length === 1 ) {
227229
if( declarationParts[0].indexOf('min') === 0 ) {
228230
minDeclaration = declarationParts[0];
229231
} else {
@@ -266,8 +268,6 @@
266268
*/
267269
$.formUtils.checkImageRatio = function(img, ratioDeclaration, language) {
268270
var ratio = img.width / img.height,
269-
minRatio = false,
270-
maxRatio = false,
271271
calculateRatio = function(declaration) {
272272
var dims = declaration.replace('max', '').replace('min', '').split(':');
273273
return dims[0] / dims[1];
@@ -277,15 +277,15 @@
277277
return val >= min && val <= max;
278278
};
279279

280-
if( declarationParts.length == 1 ) {
281-
if( ratio !== calculateRatio(declarationParts[0]) )
282-
return language.imageRatioNotAccepted;
283-
}
284-
else if( declarationParts.length == 2 && !isWithin(ratio, calculateRatio(declarationParts[0]), calculateRatio(declarationParts[1])) ) {
280+
if ( declarationParts.length === 1 ) {
281+
if ( ratio !== calculateRatio(declarationParts[0]) ) {
285282
return language.imageRatioNotAccepted;
286283
}
287-
288-
return false;
284+
}
285+
else if( declarationParts.length === 2 && !isWithin(ratio, calculateRatio(declarationParts[0]), calculateRatio(declarationParts[1])) ) {
286+
return language.imageRatioNotAccepted;
287+
}
288+
return false;
289289
};
290290

291291
/**
@@ -294,30 +294,30 @@
294294
$.formUtils.addValidator({
295295
name : 'dimension',
296296
validatorFunction : function(val, $input, conf, language, $form) {
297-
297+
var hasCorrectDim = false;
298298
if( SUPPORTS_FILE_READER ) {
299-
var hasCorrectDim = true,
300-
file = $input.get(0).files || [];
299+
var file = $input.get(0).files || [];
300+
hasCorrectDim = true;
301301

302-
if( $input.attr('data-validation').indexOf('mime') == -1) {
302+
if( $input.attr('data-validation').indexOf('mime') === -1) {
303303
alert('You should validate file type being jpg, gif or png on input '+$input[0].name);
304304
return false;
305305
}
306306
else if( file.length > 1 ) {
307307
alert('Validating image dimensions does not support inputs allowing multiple files');
308308
return false;
309-
} else if( file.length == 0) {
309+
} else if( file.length === 0) {
310310
return true;
311311
}
312312

313313
if( $input.valAttr('has-valid-dim') ) {
314314
return true;
315315
}
316316
else if( $input.valAttr('has-not-valid-dim') ) {
317-
this.errorMessage = language['wrongFileDim'] + ' '+$input.valAttr('has-not-valid-dim');
317+
this.errorMessage = language.wrongFileDim + ' ' + $input.valAttr('has-not-valid-dim');
318318
return false;
319319
}
320-
else if($.formUtils.eventType == 'keyup') {
320+
else if($.formUtils.eventType === 'keyup') {
321321
return null;
322322
}
323323

@@ -334,11 +334,13 @@
334334
_loadImage(file[0], function(img) {
335335
var error = false;
336336

337-
if( $input.valAttr('dimension') )
337+
if ( $input.valAttr('dimension') ) {
338338
error = $.formUtils.checkImageDimension(img, $input.valAttr('dimension'), language);
339+
}
339340

340-
if( !error && $input.valAttr('ratio') )
341+
if ( !error && $input.valAttr('ratio') ) {
341342
error = $.formUtils.checkImageRatio(img, $input.valAttr('ratio'), language);
343+
}
342344

343345
// Set validation result flag on input
344346
if( error ) {
@@ -353,7 +355,7 @@
353355
$input
354356
.valAttr('has-keyup-event', '1')
355357
.bind('keyup change', function(evt) {
356-
if( evt.keyCode != 9 && evt.keyCode != 16 ) {
358+
if( evt.keyCode !== 9 && evt.keyCode !== 16 ) {
357359
$(this)
358360
.valAttr('has-not-valid-dim', false)
359361
.valAttr('has-valid-dim', false);

form-validator/html5.dev.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
(function($, window) {
2323

24-
"use strict";
24+
'use strict';
2525

2626
var SUPPORTS_PLACEHOLDER = 'placeholder' in document.createElement('INPUT'),
2727
SUPPORTS_DATALIST = 'options' in document.createElement('DATALIST'),
@@ -61,10 +61,12 @@
6161
var max = $input.attr('max'),
6262
min = $input.attr('min');
6363
if( min || max ) {
64-
if( !min )
64+
if ( !min ) {
6565
min = '0';
66-
if( !max )
66+
}
67+
if ( !max ) {
6768
max = '9007199254740992'; // js max int
69+
}
6870

6971
attrs['data-validation-allowing'] = 'range['+min+';'+max+']';
7072
if( min.indexOf('-') === 0 || max.indexOf('-') === 0 ) {
@@ -94,7 +96,7 @@
9496
suggestions.push($(this).text());
9597
});
9698

97-
if( suggestions.length == 0 ) {
99+
if( suggestions.length === 0 ) {
98100
// IE fix
99101
var opts = $.trim($('#'+$input.attr('list')).text()).split('\n');
100102
$.each(opts, function(i, option) {
@@ -107,8 +109,9 @@
107109
$.formUtils.suggest( $input, suggestions );
108110
}
109111

110-
if( isRequired && validation.length == 0 )
112+
if ( isRequired && validation.length === 0 ) {
111113
validation.push('required');
114+
}
112115

113116
if( validation.length ) {
114117
if( !isRequired ) {
@@ -133,13 +136,13 @@
133136
this.defaultValue = this.getAttribute('placeholder');
134137
$(this)
135138
.bind('focus', function() {
136-
if(this.value == this.defaultValue) {
139+
if(this.value === this.defaultValue) {
137140
this.value = '';
138141
$(this).removeClass('showing-placeholder');
139142
}
140143
})
141144
.bind('blur', function() {
142-
if($.trim(this.value) == '') {
145+
if($.trim(this.value) === '') {
143146
this.value = this.defaultValue;
144147
$(this).addClass('showing-placeholder');
145148
}

0 commit comments

Comments
 (0)