From d7e13f128a4965f5d2bf510dc2314faa266f9dd7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 13 May 2019 22:25:11 +0200 Subject: [PATCH] Build: ESLint: forbid unused function parameters This commit requires all function parameters to be used, not just the last one. In cases where that's not possible as we need to match an external API, there's an escape hatch of prefixing an unused argument with `_`. This change makes it easier to catch unused AMD dependencies and unused parameters in internal functions the API of which we may change at will, among other things. Unused AMD dependencies have been removed as part of this commit. Closes gh-4381 (cherry-picked from 438b1a3e8a52d3e4efd8aba45498477038849c97) --- build/tasks/build.js | 2 +- dist/.eslintrc.json | 3 ++- package.json | 2 +- src/ajax.js | 2 +- src/attributes/attr.js | 2 +- src/core.js | 2 +- src/core/access.js | 2 +- src/core/camelCase.js | 2 +- src/css.js | 4 ++-- src/css/var/swap.js | 4 ++-- src/deferred.js | 2 +- src/effects.js | 5 ++--- src/event/ajax.js | 2 +- src/event/alias.js | 2 +- src/offset.js | 7 +++---- src/serialize.js | 2 +- src/traversing.js | 6 +++--- 17 files changed, 25 insertions(+), 26 deletions(-) diff --git a/build/tasks/build.js b/build/tasks/build.js index b59ef816e..73dfd581d 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -372,7 +372,7 @@ module.exports = function( grunt ) { // Ask for permission the first time if ( insight.optOut === undefined ) { - insight.askPermission( null, function( error, result ) { + insight.askPermission( null, function( _error, result ) { exec( result ); } ); } else { diff --git a/dist/.eslintrc.json b/dist/.eslintrc.json index c2aa05c5e..45ba0c520 100644 --- a/dist/.eslintrc.json +++ b/dist/.eslintrc.json @@ -7,9 +7,10 @@ // That is okay for the built version "no-multiple-empty-lines": "off", - // Because sizzle is not compatible to jquery code style + // Sizzle is not compatible with jQuery code style "no-nested-ternary": "off", "no-unused-expressions": "off", + "no-unused-vars": "off", "lines-around-comment": "off", "space-in-parens": "off", "camelcase": "off", diff --git a/package.json b/package.json index 955538e2d..9e1dcfafc 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@babel/plugin-transform-for-of": "7.2.0", "commitplease": "3.2.0", "core-js": "2.6.5", - "eslint-config-jquery": "1.0.1", + "eslint-config-jquery": "2.0.0", "grunt": "1.0.3", "grunt-babel": "8.0.0", "grunt-cli": "1.3.2", diff --git a/src/ajax.js b/src/ajax.js index 4cbefabaa..b1f160840 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -833,7 +833,7 @@ jQuery.extend( { } } ); -jQuery.each( [ "get", "post" ], function( i, method ) { +jQuery.each( [ "get", "post" ], function( _i, method ) { jQuery[ method ] = function( url, data, callback, type ) { // Shift arguments if data argument was omitted diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 6b5cbd2c4..4c43eb1fc 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -117,7 +117,7 @@ boolHook = { } }; -jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) { +jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( _i, name ) { var getter = attrHandle[ name ] || jQuery.find.attr; attrHandle[ name ] = function( elem, name, isXML ) { diff --git a/src/core.js b/src/core.js index 19cacf7cd..f57075ce7 100644 --- a/src/core.js +++ b/src/core.js @@ -374,7 +374,7 @@ if ( typeof Symbol === "function" ) { // Populate the class2type map jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ), -function( i, name ) { +function( _i, name ) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); } ); diff --git a/src/core/access.js b/src/core/access.js index 842c4a42b..54bcc7447 100644 --- a/src/core/access.js +++ b/src/core/access.js @@ -38,7 +38,7 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { // ...except when executing function values } else { bulk = fn; - fn = function( elem, key, value ) { + fn = function( elem, _key, value ) { return bulk.call( jQuery( elem ), value ); }; } diff --git a/src/core/camelCase.js b/src/core/camelCase.js index 799fb3752..b271044d5 100644 --- a/src/core/camelCase.js +++ b/src/core/camelCase.js @@ -7,7 +7,7 @@ var rmsPrefix = /^-ms-/, rdashAlpha = /-([a-z])/g; // Used by camelCase as callback to replace() -function fcamelCase( all, letter ) { +function fcamelCase( _all, letter ) { return letter.toUpperCase(); } diff --git a/src/css.js b/src/css.js index ac4c66e87..d4c34dbb7 100644 --- a/src/css.js +++ b/src/css.js @@ -34,7 +34,7 @@ var fontWeight: "400" }; -function setPositiveNumber( elem, value, subtract ) { +function setPositiveNumber( _elem, value, subtract ) { // Any relative (+/-) values have already been // normalized at this point @@ -344,7 +344,7 @@ jQuery.extend( { } } ); -jQuery.each( [ "height", "width" ], function( i, dimension ) { +jQuery.each( [ "height", "width" ], function( _i, dimension ) { jQuery.cssHooks[ dimension ] = { get: function( elem, computed, extra ) { if ( computed ) { diff --git a/src/css/var/swap.js b/src/css/var/swap.js index 1a9556bad..69388e5f7 100644 --- a/src/css/var/swap.js +++ b/src/css/var/swap.js @@ -3,7 +3,7 @@ define( function() { "use strict"; // A method for quickly swapping in/out CSS properties to get correct calculations. -return function( elem, options, callback, args ) { +return function( elem, options, callback ) { var ret, name, old = {}; @@ -13,7 +13,7 @@ return function( elem, options, callback, args ) { elem.style[ name ] = options[ name ]; } - ret = callback.apply( elem, args || [] ); + ret = callback.call( elem ); // Revert the old values for ( name in options ) { diff --git a/src/deferred.js b/src/deferred.js index 0425d3631..c05a37a23 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -79,7 +79,7 @@ jQuery.extend( { var fns = arguments; return jQuery.Deferred( function( newDefer ) { - jQuery.each( tuples, function( i, tuple ) { + jQuery.each( tuples, function( _i, tuple ) { // Map tuples (progress, done, fail) to arguments (done, fail, progress) var fn = isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ]; diff --git a/src/effects.js b/src/effects.js index 4ace4cafa..76b7cc765 100644 --- a/src/effects.js +++ b/src/effects.js @@ -7,7 +7,6 @@ define( [ "./var/rnothtmlwhite", "./css/var/cssExpand", "./css/var/isHiddenWithinTree", - "./css/var/swap", "./css/adjustCSS", "./data/var/dataPriv", "./css/showHide", @@ -20,7 +19,7 @@ define( [ "./css", "./effects/Tween" ], function( jQuery, camelCase, document, isFunction, rcssNum, rnothtmlwhite, cssExpand, - isHiddenWithinTree, swap, adjustCSS, dataPriv, showHide ) { + isHiddenWithinTree, adjustCSS, dataPriv, showHide ) { "use strict"; @@ -625,7 +624,7 @@ jQuery.fn.extend( { } } ); -jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) { +jQuery.each( [ "toggle", "show", "hide" ], function( _i, name ) { var cssFn = jQuery.fn[ name ]; jQuery.fn[ name ] = function( speed, easing, callback ) { return speed == null || typeof speed === "boolean" ? diff --git a/src/event/ajax.js b/src/event/ajax.js index 500b36cdd..dd9c0ffe2 100644 --- a/src/event/ajax.js +++ b/src/event/ajax.js @@ -13,7 +13,7 @@ jQuery.each( [ "ajaxError", "ajaxSuccess", "ajaxSend" -], function( i, type ) { +], function( _i, type ) { jQuery.fn[ type ] = function( fn ) { return this.on( type, fn ); }; diff --git a/src/event/alias.js b/src/event/alias.js index 863c94ad2..46bd1ae80 100644 --- a/src/event/alias.js +++ b/src/event/alias.js @@ -10,7 +10,7 @@ define( [ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + "change select submit keydown keypress keyup contextmenu" ).split( " " ), - function( i, name ) { + function( _i, name ) { // Handle event binding jQuery.fn[ name ] = function( data, fn ) { diff --git a/src/offset.js b/src/offset.js index 83b1c3a53..6e9735870 100644 --- a/src/offset.js +++ b/src/offset.js @@ -1,7 +1,6 @@ define( [ "./core", "./core/access", - "./var/document", "./var/documentElement", "./var/isFunction", "./css/var/rnumnonpx", @@ -12,8 +11,8 @@ define( [ "./core/init", "./css", "./selector" // contains -], function( jQuery, access, document, documentElement, isFunction, rnumnonpx, - curCSS, addGetHookIf, support, isWindow ) { +], function( jQuery, access, documentElement, isFunction, rnumnonpx, + curCSS, addGetHookIf, support, isWindow ) { "use strict"; @@ -214,7 +213,7 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( // Blink bug: https://bugs.chromium.org/p/chromium/issues/detail?id=589347 // getComputedStyle returns percent when specified for top/left/bottom/right; // rather than make the css module depend on the offset module, just check for it here -jQuery.each( [ "top", "left" ], function( i, prop ) { +jQuery.each( [ "top", "left" ], function( _i, prop ) { jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition, function( elem, computed ) { if ( computed ) { diff --git a/src/serialize.js b/src/serialize.js index d8a9a36a4..cd4e99f9f 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -114,7 +114,7 @@ jQuery.fn.extend( { rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && ( this.checked || !rcheckableType.test( type ) ); } ) - .map( function( i, elem ) { + .map( function( _i, elem ) { var val = jQuery( this ).val(); if ( val == null ) { diff --git a/src/traversing.js b/src/traversing.js index afbecc4f4..de377188f 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -118,7 +118,7 @@ jQuery.each( { parents: function( elem ) { return dir( elem, "parentNode" ); }, - parentsUntil: function( elem, i, until ) { + parentsUntil: function( elem, _i, until ) { return dir( elem, "parentNode", until ); }, next: function( elem ) { @@ -133,10 +133,10 @@ jQuery.each( { prevAll: function( elem ) { return dir( elem, "previousSibling" ); }, - nextUntil: function( elem, i, until ) { + nextUntil: function( elem, _i, until ) { return dir( elem, "nextSibling", until ); }, - prevUntil: function( elem, i, until ) { + prevUntil: function( elem, _i, until ) { return dir( elem, "previousSibling", until ); }, siblings: function( elem ) { -- 2.39.5