Skip to content

Commit 081580b

Browse files
committed
Fix undefined variables
There were a few undefined variables being referenced within the Select2 code. The JSHint configuration has been modified to fail if there are undefined variables being referenced, including any global variables. There is an exception that is being made for the jQuery shim, as it must try to find the global jQuery references. An exception is made for the test helpers, as the SauceLabs reporting variables are not camelCase, and would normally trigger warnings. This closes select2#3028.
1 parent e383cb5 commit 081580b

27 files changed

Lines changed: 117 additions & 171 deletions

.jshintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
tests/vendor/*.js
2+
tests/helpers.js

.jshintrc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
"eqnull": true,
77
"freeze": true,
88
"globals": {
9-
"define": true
9+
"console": false,
10+
"define": false,
11+
"document": false,
12+
"expect": false,
13+
"MockContainer": false,
14+
"module": false,
15+
"require": false,
16+
"test": false,
17+
"window": false
1018
},
1119
"indent": 2,
1220
"maxlen": 80,
1321
"noarg": true,
1422
"nonew": true,
15-
"quotmark": "single"
23+
"quotmark": "single",
24+
"undef": true
1625
}

Gruntfile.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,12 @@ module.exports = function (grunt) {
303303

304304
grunt.registerTask('compile', ['requirejs', 'sass:dev']);
305305
grunt.registerTask('minify', ['uglify', 'sass:dist']);
306-
grunt.registerTask('test', ['qunit', 'jshint']);
306+
grunt.registerTask('test', ['connect:tests', 'qunit', 'jshint']);
307307

308-
grunt.registerTask('ci', ['compile', 'connect:tests', 'saucelabs-qunit', 'test']);
308+
grunt.registerTask('ci', [
309+
'compile', 'connect:tests',
310+
'saucelabs-qunit', 'qunit', 'jshint'
311+
]);
309312

310313
grunt.registerTask('docs', ['symlink:docs', 'jekyll:serve']);
311314

dist/js/i18n/ca.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/i18n/es.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/i18n/eu.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/i18n/is.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/i18n/lt.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/i18n/lv.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.amd.full.js

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -765,21 +765,7 @@ define('select2/keys',[
765765
UP: 38,
766766
RIGHT: 39,
767767
DOWN: 40,
768-
DELETE: 46,
769-
770-
isArrow: function (k) {
771-
k = k.which ? k.which : k;
772-
773-
switch (k) {
774-
case KEY.LEFT:
775-
case KEY.RIGHT:
776-
case KEY.UP:
777-
case KEY.DOWN:
778-
return true;
779-
}
780-
781-
return false;
782-
}
768+
DELETE: 46
783769
};
784770

785771
return KEYS;
@@ -1164,7 +1150,7 @@ define('select2/selection/allowClear',[
11641150
decorated.call(this, container, $container);
11651151

11661152
if (self.placeholder == null) {
1167-
if (console && console.error) {
1153+
if (window.console && console.error) {
11681154
console.error(
11691155
'Select2: The `allowClear` option should be used in combination ' +
11701156
'with the `placeholder` option.'
@@ -2385,7 +2371,7 @@ define('select2/data/select',[
23852371
data.push.apply(data, currentData);
23862372

23872373
for (var d = 0; d < data.length; d++) {
2388-
id = data[d].id;
2374+
var id = data[d].id;
23892375

23902376
if (val.indexOf(id) === -1) {
23912377
val.push(id);
@@ -2423,7 +2409,7 @@ define('select2/data/select',[
24232409
var val = [];
24242410

24252411
for (var d = 0; d < currentData.length; d++) {
2426-
id = currentData[d].id;
2412+
var id = currentData[d].id;
24272413

24282414
if (id !== data.id && val.indexOf(id) === -1) {
24292415
val.push(id);
@@ -2759,7 +2745,7 @@ define('select2/data/ajax',[
27592745
var $request = options.transport(options, function (data) {
27602746
var results = self.processResults(data, params);
27612747

2762-
if (console && console.error) {
2748+
if (window.console && console.error) {
27632749
// Check to make sure that the response included a `results` key.
27642750
if (!results || !results.results || !$.isArray(results.results)) {
27652751
console.error(
@@ -3428,7 +3414,7 @@ define('select2/dropdown/attachBody',[
34283414
var resizeEvent = 'resize.select2.' + container.id;
34293415
var orientationEvent = 'orientationchange.select2.' + container.id;
34303416

3431-
$watchers = this.$container.parents().filter(Utils.hasScroll);
3417+
var $watchers = this.$container.parents().filter(Utils.hasScroll);
34323418
$watchers.each(function () {
34333419
$(this).data('select2-scroll-position', {
34343420
x: $(this).scrollLeft(),
@@ -3453,7 +3439,7 @@ define('select2/dropdown/attachBody',[
34533439
var resizeEvent = 'resize.select2.' + container.id;
34543440
var orientationEvent = 'orientationchange.select2.' + container.id;
34553441

3456-
$watchers = this.$container.parents().filter(Utils.hasScroll);
3442+
var $watchers = this.$container.parents().filter(Utils.hasScroll);
34573443
$watchers.off(scrollEvent);
34583444

34593445
$(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
@@ -3545,7 +3531,7 @@ define('select2/dropdown/minimumResultsForSearch',[
35453531

35463532
], function () {
35473533
function countResults (data) {
3548-
count = 0;
3534+
var count = 0;
35493535

35503536
for (var d = 0; d < data.length; d++) {
35513537
var item = data[d];
@@ -3918,7 +3904,7 @@ define('select2/defaults',[
39183904
// The translation could not be loaded at all. Sometimes this is
39193905
// because of a configuration problem, other times this can be
39203906
// because of how Select2 helps load all possible translation files.
3921-
if (console && console.warn) {
3907+
if (window.console && console.warn) {
39223908
console.warn(
39233909
'Select2: The lanugage file for "' + name + '" could not be ' +
39243910
'automatically loaded. A fallback will be used instead.'
@@ -4085,7 +4071,7 @@ define('select2/options',[
40854071
$e.prop('multiple', this.options.multiple);
40864072

40874073
if ($e.data('select2-tags')) {
4088-
if (console && console.warn) {
4074+
if (window.console && console.warn) {
40894075
console.warn(
40904076
'Select2: The `data-select2-tags` attribute has been changed to ' +
40914077
'use the `data-data` and `data-tags="true"` attributes and will be ' +
@@ -4098,7 +4084,7 @@ define('select2/options',[
40984084
}
40994085

41004086
if ($e.data('ajax-url')) {
4101-
if (console && console.warn) {
4087+
if (window.console && console.warn) {
41024088
console.warn(
41034089
'Select2: The `data-ajax-url` attribute has been changed to ' +
41044090
'`data-ajax--url` and support for the old attribute will be removed' +
@@ -4284,8 +4270,8 @@ define('select2/core',[
42844270

42854271
var attrs = style.split(';');
42864272

4287-
for (i = 0, l = attrs.length; i < l; i = i + 1) {
4288-
attr = attrs[i].replace(/\s/g, '');
4273+
for (var i = 0, l = attrs.length; i < l; i = i + 1) {
4274+
var attr = attrs[i].replace(/\s/g, '');
42894275
var matches = attr.match(WIDTH);
42904276

42914277
if (matches !== null && matches.length >= 1) {
@@ -4532,7 +4518,7 @@ define('select2/core',[
45324518
};
45334519

45344520
Select2.prototype.enable = function (args) {
4535-
if (console && console.warn) {
4521+
if (window.console && console.warn) {
45364522
console.warn(
45374523
'Select2: The `select2("enable")` method has been deprecated and will' +
45384524
' be removed in later Select2 versions. Use $element.prop("disabled")' +
@@ -4550,7 +4536,7 @@ define('select2/core',[
45504536
};
45514537

45524538
Select2.prototype.data = function () {
4553-
if (arguments.length > 0 && console && console.warn) {
4539+
if (arguments.length > 0 && window.console && console.warn) {
45544540
console.warn(
45554541
'Select2: Data can no longer be set using `select2("data")`. You ' +
45564542
'should consider setting the value instead using `$element.val()`.'
@@ -4567,7 +4553,7 @@ define('select2/core',[
45674553
};
45684554

45694555
Select2.prototype.val = function (args) {
4570-
if (console && console.warn) {
4556+
if (window.console && console.warn) {
45714557
console.warn(
45724558
'Select2: The `select2("val")` method has been deprecated and will be' +
45734559
' removed in later Select2 versions. Use $element.val() instead.'
@@ -4911,7 +4897,7 @@ define('select2/compat/initSelection',[
49114897
'jquery'
49124898
], function ($) {
49134899
function InitSelection (decorated, $element, options) {
4914-
if (console && console.warn) {
4900+
if (window.console && console.warn) {
49154901
console.warn(
49164902
'Select2: The `initSelection` option has been deprecated in favor' +
49174903
' of a custom data adapter that overrides the `current` method. ' +
@@ -4954,7 +4940,7 @@ define('select2/compat/query',[
49544940

49554941
], function () {
49564942
function Query (decorated, $element, options) {
4957-
if (console && console.warn) {
4943+
if (window.console && console.warn) {
49584944
console.warn(
49594945
'Select2: The `query` option has been deprecated in favor of a ' +
49604946
'custom data adapter that overrides the `query` method. Support ' +

0 commit comments

Comments
 (0)