Build: Correct code indentations based on jQuery Style Guide

1. Correct code indentations based on jQuery Style Guide
   (contribute.jquery.org/style-guide/js/#spacing).
2. Add rules to "src/.eslintrc.json" to enable "enforcing consistent
   indentation", with minimal changes to the current code.

Closes gh-4672

(cherry picked from 3d62d57049)
This commit is contained in:
Wonseop Kim 2020-05-05 17:49:27 +09:00 committed by Michał Gołębiowski-Owczarek
parent 9908b7aace
commit 9b8cadc736
16 changed files with 70 additions and 44 deletions

View File

@ -3,9 +3,33 @@
"extends": "../.eslintrc-browser.json",
"rules": {
"indent": [ "error", "tab", {
"outerIIFEBody": 0,
// Ignore the top level function defining an AMD module
"ignoredNodes": [
"Program > ExpressionStatement > CallExpression > :last-child > *"
]
} ]
},
"overrides": [
{
"files": "wrapper.js",
"rules": {
"no-unused-vars": "off",
"indent": [ "error", "tab", {
// Unlike other codes, "wrapper.js" is implemented in UMD.
// So it required a specific exception for jQuery's UMD
// Code Style. This makes that indentation check is not
// performed for 1 depth of outer FunctionExpressions
"ignoredNodes": [
"Program > ExpressionStatement > CallExpression > :last-child > *"
]
} ]
},
"globals": {
"jQuery": false
}

View File

@ -50,7 +50,8 @@ var
// Anchor tag for parsing the document origin
originAnchor = document.createElement( "a" );
originAnchor.href = location.href;
originAnchor.href = location.href;
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
function addToPrefiltersOrTransports( structure ) {
@ -431,8 +432,8 @@ jQuery.extend( {
// Context for global events is callbackContext if it is a DOM node or jQuery collection
globalEventContext = s.context &&
( callbackContext.nodeType || callbackContext.jquery ) ?
jQuery( callbackContext ) :
jQuery.event,
jQuery( callbackContext ) :
jQuery.event,
// Deferreds
deferred = jQuery.Deferred(),

View File

@ -159,8 +159,8 @@ jQuery.fn.extend( {
if ( this.setAttribute ) {
this.setAttribute( "class",
className || value === false ?
"" :
dataPriv.get( this, "__className__" ) || ""
"" :
dataPriv.get( this, "__className__" ) || ""
);
}
}
@ -175,7 +175,7 @@ jQuery.fn.extend( {
while ( ( elem = this[ i++ ] ) ) {
if ( elem.nodeType === 1 &&
( " " + stripAndCollapse( getClass( elem ) ) + " " ).indexOf( className ) > -1 ) {
return true;
return true;
}
}

View File

@ -280,7 +280,7 @@ jQuery.extend( {
if ( isArrayLike( Object( arr ) ) ) {
jQuery.merge( ret,
typeof arr === "string" ?
[ arr ] : arr
[ arr ] : arr
);
} else {
push.call( ret, arr );
@ -375,9 +375,9 @@ if ( typeof Symbol === "function" ) {
// Populate the class2type map
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
function( _i, name ) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
} );
function( _i, name ) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
} );
function isArrayLike( obj ) {

View File

@ -48,8 +48,8 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
for ( ; i < len; i++ ) {
fn(
elems[ i ], key, raw ?
value :
value.call( elems[ i ], i, fn( elems[ i ], key ) )
value :
value.call( elems[ i ], i, fn( elems[ i ], key ) )
);
}
}

View File

@ -4,7 +4,7 @@ define( function() {
function nodeName( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
};

View File

@ -370,10 +370,10 @@ jQuery.each( [ "height", "width" ], function( _i, dimension ) {
// Running getBoundingClientRect on a disconnected node
// in IE throws an error.
( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
swap( elem, cssShow, function() {
return getWidthOrHeight( elem, dimension, extra );
} ) :
getWidthOrHeight( elem, dimension, extra );
swap( elem, cssShow, function() {
return getWidthOrHeight( elem, dimension, extra );
} ) :
getWidthOrHeight( elem, dimension, extra );
}
},
@ -432,7 +432,7 @@ jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
swap( elem, { marginLeft: 0 }, function() {
return elem.getBoundingClientRect().left;
} )
) + "px";
) + "px";
}
}
);

View File

@ -32,7 +32,8 @@ jQuery.fn.extend( {
}
} );
jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
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 ) {
@ -43,6 +44,7 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
this.on( name, null, data, fn ) :
this.trigger( name );
};
} );
}
);
} );

View File

@ -9,8 +9,11 @@ define( [
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name },
function( defaultExtra, funcName ) {
jQuery.each( {
padding: "inner" + name,
content: type,
"": "outer" + name
}, function( defaultExtra, funcName ) {
// Margin is only for outerHeight, outerWidth
jQuery.fn[ funcName ] = function( margin, value ) {

7
src/effects.js vendored
View File

@ -230,7 +230,7 @@ function defaultPrefilter( elem, props, opts ) {
anim.done( function() {
/* eslint-enable no-loop-func */
/* eslint-enable no-loop-func */
// The final step of a "hide" animation is actually hiding the element
if ( !hidden ) {
@ -350,7 +350,7 @@ function Animation( elem, properties, options ) {
tweens: [],
createTween: function( prop, end ) {
var tween = jQuery.Tween( elem, animation.opts, prop, end,
animation.opts.specialEasing[ prop ] || animation.opts.easing );
animation.opts.specialEasing[ prop ] || animation.opts.easing );
animation.tweens.push( tween );
return tween;
},
@ -523,7 +523,8 @@ jQuery.fn.extend( {
anim.stop( true );
}
};
doAnimation.finish = doAnimation;
doAnimation.finish = doAnimation;
return empty || optall.queue === false ?
this.each( doAnimation ) :

View File

@ -87,7 +87,7 @@ Tween.propHooks = {
if ( jQuery.fx.step[ tween.prop ] ) {
jQuery.fx.step[ tween.prop ]( tween );
} else if ( tween.elem.nodeType === 1 && (
jQuery.cssHooks[ tween.prop ] ||
jQuery.cssHooks[ tween.prop ] ||
tween.elem.style[ finalPropName( tween.prop ) ] != null ) ) {
jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
} else {

View File

@ -315,8 +315,8 @@ jQuery.event = {
event = jQuery.event.fix( nativeEvent ),
handlers = (
dataPriv.get( this, "events" ) || Object.create( null )
)[ event.type ] || [],
dataPriv.get( this, "events" ) || Object.create( null )
)[ event.type ] || [],
special = jQuery.event.special[ event.type ] || {};
// Use the fix-ed jQuery.Event rather than the (read-only) native event
@ -440,12 +440,12 @@ jQuery.event = {
get: isFunction( hook ) ?
function() {
if ( this.originalEvent ) {
return hook( this.originalEvent );
return hook( this.originalEvent );
}
} :
function() {
if ( this.originalEvent ) {
return this.originalEvent[ name ];
return this.originalEvent[ name ];
}
},

View File

@ -103,9 +103,7 @@ jQuery.extend( jQuery.event, {
special.bindType || type;
// jQuery handler
handle = (
dataPriv.get( cur, "events" ) || Object.create( null )
)[ event.type ] &&
handle = ( dataPriv.get( cur, "events" ) || Object.create( null ) )[ event.type ] &&
dataPriv.get( cur, "handle" );
if ( handle ) {
handle.apply( cur, data );

View File

@ -105,16 +105,14 @@ jQuery.fn.extend( {
// Can add propHook for "elements" to filter or add form elements
var elements = jQuery.prop( this, "elements" );
return elements ? jQuery.makeArray( elements ) : this;
} )
.filter( function() {
} ).filter( function() {
var type = this.type;
// Use .is( ":disabled" ) so that fieldset[disabled] works
return this.name && !jQuery( this ).is( ":disabled" ) &&
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 ) {

View File

@ -3,11 +3,11 @@ define( function() {
return function isFunction( obj ) {
// Support: Chrome <=57, Firefox <=52
// In some browsers, typeof returns "function" for HTML <object> elements
// (i.e., `typeof document.createElement( "object" ) === "function"`).
// We don't want to classify *any* DOM node as a function.
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
// Support: Chrome <=57, Firefox <=52
// In some browsers, typeof returns "function" for HTML <object> elements
// (i.e., `typeof document.createElement( "object" ) === "function"`).
// We don't want to classify *any* DOM node as a function.
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
} );

View File

@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars*/
/*!
* jQuery JavaScript Library v@VERSION
* https://jquery.com/