From: XhmikosR Date: Thu, 27 Jul 2017 10:39:55 +0000 (+0300) Subject: Tweak ESLint rules. X-Git-Tag: v4.0.0-beta.2~323 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef8c77d8dcebd13559a141e419d003c2d10cc5f3;p=thirdparty%2Fbootstrap.git Tweak ESLint rules. --- diff --git a/assets/js/ie-emulation-modes-warning.js b/assets/js/ie-emulation-modes-warning.js index c8f0bcac50..1b4716bf5e 100644 --- a/assets/js/ie-emulation-modes-warning.js +++ b/assets/js/ie-emulation-modes-warning.js @@ -27,7 +27,7 @@ // IE JavaScript conditional compilation docs: https://msdn.microsoft.com/library/121hztk3%28v=vs.94%29.aspx // @cc_on docs: https://msdn.microsoft.com/library/8ka90k2e%28v=vs.94%29.aspx var jscriptVersion = new Function('/*@cc_on return @_jscript_version; @*/')() // eslint-disable-line no-new-func - if (jscriptVersion === undefined) { + if (typeof jscriptVersion === 'undefined') { return 11 // IE11+ not in emulation mode } if (jscriptVersion < 9) { diff --git a/js/.eslintrc.json b/js/.eslintrc.json index 72029797a3..fdca9c1dd2 100644 --- a/js/.eslintrc.json +++ b/js/.eslintrc.json @@ -14,9 +14,8 @@ "rules": { // Possible Errors "no-await-in-loop": "error", - "no-compare-neg-zero": "error", "no-extra-parens": "error", - "no-prototype-builtins": "off", + "no-prototype-builtins": "error", "no-template-curly-in-string": "error", "valid-jsdoc": "error", @@ -85,7 +84,6 @@ "no-unused-expressions": "error", "no-useless-call": "error", "no-useless-concat": "error", - "no-useless-escape": "error", "no-useless-return": "off", "no-void": "error", "no-warning-comments": "off", @@ -108,7 +106,7 @@ "no-shadow": "off", "no-shadow-restricted-names": "error", "no-undef-init": "error", - "no-undefined": "off", + "no-undefined": "error", "no-use-before-define": "off", // Node.js and CommonJS @@ -213,7 +211,7 @@ "wrap-regex": "off", // ECMAScript 6 - "arrow-body-style": "off", + "arrow-body-style": ["error", "as-needed"], "arrow-parens": "error", "arrow-spacing": "error", "generator-star-spacing": "error", diff --git a/js/src/carousel.js b/js/src/carousel.js index 6bcf470f98..8736605190 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -443,7 +443,7 @@ const Carousel = (($) => { if (typeof config === 'number') { data.to(config) } else if (typeof action === 'string') { - if (data[action] === undefined) { + if (typeof data[action] === 'undefined') { throw new Error(`No method named "${action}"`) } data[action]() diff --git a/js/src/collapse.js b/js/src/collapse.js index 2f00b98cb6..718630bd37 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -343,7 +343,7 @@ const Collapse = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 5e792a527f..e1c48ac6e5 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -204,7 +204,7 @@ const Dropdown = (($) => { _getConfig(config) { const elementData = $(this._element).data() - if (elementData.placement !== undefined) { + if (typeof elementData.placement !== 'undefined') { elementData.placement = AttachmentMap[elementData.placement.toUpperCase()] } @@ -287,7 +287,7 @@ const Dropdown = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() diff --git a/js/src/modal.js b/js/src/modal.js index 9f17fafc8f..d21a137fb6 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -507,7 +507,7 @@ const Modal = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config](relatedTarget) diff --git a/js/src/popover.js b/js/src/popover.js index 0e8953f771..7639e3e203 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -162,7 +162,7 @@ const Popover = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index b70b7e477e..588f652988 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -231,7 +231,7 @@ const ScrollSpy = (($) => { for (let i = this._offsets.length; i--;) { const isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] - && (this._offsets[i + 1] === undefined || + && (typeof this._offsets[i + 1] === 'undefined' || scrollTop < this._offsets[i + 1]) if (isActiveTarget) { @@ -246,6 +246,7 @@ const ScrollSpy = (($) => { this._clear() let queries = this._selector.split(',') + // eslint-disable-next-line arrow-body-style queries = queries.map((selector) => { return `${selector}[data-target="${target}"],` + `${selector}[href="${target}"]` @@ -287,7 +288,7 @@ const ScrollSpy = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() diff --git a/js/src/tab.js b/js/src/tab.js index 4c30914951..c32cd3776f 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -238,7 +238,7 @@ const Tab = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 2060cebbb9..721f044818 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -698,7 +698,7 @@ const Tooltip = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() diff --git a/js/src/util.js b/js/src/util.js index 387c7d2ed5..69fb8283cc 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -42,7 +42,7 @@ const Util = (($) => { if ($(event.target).is(this)) { return event.handleObj.handler.apply(this, arguments) // eslint-disable-line prefer-rest-params } - return undefined + return undefined // eslint-disable-line no-undefined } } } @@ -55,7 +55,7 @@ const Util = (($) => { const el = document.createElement('bootstrap') for (const name in TransitionEndEvent) { - if (el.style[name] !== undefined) { + if (typeof el.style[name] !== 'undefined') { return { end: TransitionEndEvent[name] } @@ -138,7 +138,7 @@ const Util = (($) => { typeCheckConfig(componentName, config, configTypes) { for (const property in configTypes) { - if (configTypes.hasOwnProperty(property)) { + if (Object.prototype.hasOwnProperty.call(configTypes, property)) { const expectedTypes = configTypes[property] const value = config[property] const valueType = value && isElement(value) ? diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index e078082c3c..aee2b70d5f 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -21,7 +21,7 @@ $(function () { QUnit.test('should provide no conflict', function (assert) { assert.expect(1) - assert.strictEqual($.fn.alert, undefined, 'alert was set back to undefined (org value)') + assert.strictEqual(typeof $.fn.alert, 'undefined', 'alert was set back to undefined (org value)') }) QUnit.test('should return jquery collection containing the element', function (assert) { diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 489d400a6c..e2a51bb4d4 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -21,7 +21,7 @@ $(function () { QUnit.test('should provide no conflict', function (assert) { assert.expect(1) - assert.strictEqual($.fn.button, undefined, 'button was set back to undefined (org value)') + assert.strictEqual(typeof $.fn.button, 'undefined', 'button was set back to undefined (org value)') }) QUnit.test('should return jquery collection containing the element', function (assert) { diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index b110fbd65d..521b24ca45 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -21,7 +21,7 @@ $(function () { QUnit.test('should provide no conflict', function (assert) { assert.expect(1) - assert.strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig value)') + assert.strictEqual(typeof $.fn.carousel, 'undefined', 'carousel was set back to undefined (orig value)') }) QUnit.test('should throw explicit error on undefined method', function (assert) { @@ -371,14 +371,14 @@ $(function () { var done = assert.async() $(template) .on('slid.bs.carousel', function (e) { - assert.ok(e.from !== undefined, 'from present') - assert.ok(e.to !== undefined, 'to present') + assert.ok(typeof e.from !== 'undefined', 'from present') + assert.ok(typeof e.to !== 'undefined', 'to present') $(this).off() done() }) .on('slide.bs.carousel', function (e) { - assert.ok(e.from !== undefined, 'from present') - assert.ok(e.to !== undefined, 'to present') + assert.ok(typeof e.from !== 'undefined', 'from present') + assert.ok(typeof e.to !== 'undefined', 'to present') $(this).off('slide.bs.carousel') }) .bootstrapCarousel('next') diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 0e9e8b6a73..4470a18c27 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -21,7 +21,7 @@ $(function () { QUnit.test('should provide no conflict', function (assert) { assert.expect(1) - assert.strictEqual($.fn.collapse, undefined, 'collapse was set back to undefined (org value)') + assert.strictEqual(typeof $.fn.collapse, 'undefined', 'collapse was set back to undefined (org value)') }) QUnit.test('should throw explicit error on undefined method', function (assert) { diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index e44e47bbcb..0b808cc487 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -21,7 +21,7 @@ $(function () { QUnit.test('should provide no conflict', function (assert) { assert.expect(1) - assert.strictEqual($.fn.dropdown, undefined, 'dropdown was set back to undefined (org value)') + assert.strictEqual(typeof $.fn.dropdown, 'undefined', 'dropdown was set back to undefined (org value)') }) QUnit.test('should throw explicit error on undefined method', function (assert) { @@ -644,7 +644,7 @@ $(function () { $triggerDropdown .parent('.dropdown') .on('shown.bs.dropdown', function () { - assert.ok($dropdownMenu.attr('style') === undefined, 'No inline style applied by Popper.js') + assert.ok(typeof $dropdownMenu.attr('style') === 'undefined', 'No inline style applied by Popper.js') done() }) $triggerDropdown.trigger($.Event('click')) diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index fc6c4f38c7..09c3524434 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -34,7 +34,7 @@ $(function () { QUnit.test('should provide no conflict', function (assert) { assert.expect(1) - assert.strictEqual($.fn.modal, undefined, 'modal was set back to undefined (orig value)') + assert.strictEqual(typeof $.fn.modal, 'undefined', 'modal was set back to undefined (orig value)') }) QUnit.test('should throw explicit error on undefined method', function (assert) { @@ -380,7 +380,7 @@ $(function () { $('