10000 Build: ESLint: forbid unused function parameters · jquery/jquery@d7e13f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Build: ESLint: forbid unused function parameters
Browse files Browse the repository at this point in the history
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 438b1a3)
  • Loading branch information
mgol committed Sep 25, 2019
1 parent 36b59c9 commit d7e13f1
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion dist/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/attributes/attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

Expand Down
2 changes: 1 addition & 1 deletion src/core/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/camelCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions src/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down
4 changes: 2 additions & 2 deletions src/css/var/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand All @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] ];
Expand Down
5 changes: 2 additions & 3 deletions src/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ define( [
"./var/rnothtmlwhite",
"./css/var/cssExpand",
"./css/var/isHiddenWithinTree",
"./css/var/swap",
"./css/adjustCSS",
"./data/var/dataPriv",
"./css/showHide",
Expand All @@ -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";

Expand Down Expand Up @@ -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" ?
Expand Down
2 changes: 1 addition & 1 deletion src/event/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
};
Expand Down
2 changes: 1 addition & 1 deletion src/event/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
7 changes: 3 additions & 4 deletions src/offset.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
define( [
"./core",
"./core/access",
"./var/document",
"./var/documentElement",
"./var/isFunction",
"./css/var/rnumnonpx",
Expand All @@ -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";

Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
6 changes: 3 additions & 3 deletions src/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 ) {
Expand Down

0 comments on commit d7e13f1

Please sign in to comment.
0