Skip to content

Commit

Permalink
Build: Correct code indentations based on jQuery Style Guide
Browse files Browse the repository at this point in the history
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 3d62d57)
  • Loading branch information
wonseop authored and mgol committed May 5, 2020
1 parent 9908b7a commit 9b8cadc
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 44 deletions.
24 changes: 24 additions & 0 deletions src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions src/attributes/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ jQuery.fn.extend( {
if ( this.setAttribute ) {
this.setAttribute( "class",
className || value === false ?
"" :
dataPriv.get( this, "__className__" ) || ""
"" :
dataPriv.get( this, "__className__" ) || ""
);
}
}
Expand All @@ -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;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) {

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

};

Expand Down
10 changes: 5 additions & 5 deletions src/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
},

Expand Down Expand Up @@ -432,7 +432,7 @@ jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
swap( elem, { marginLeft: 0 }, function() {
return elem.getBoundingClientRect().left;
} )
) + "px";
) + "px";
}
}
);
Expand Down
6 changes: 4 additions & 2 deletions src/deprecated/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -43,6 +44,7 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
this.on( name, null, data, fn ) :
this.trigger( name );
};
} );
}
);

} );
7 changes: 5 additions & 2 deletions src/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
7 changes: 4 additions & 3 deletions src/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -523,7 +523,8 @@ jQuery.fn.extend( {
anim.stop( true );
}
};
doAnimation.finish = doAnimation;

doAnimation.finish = doAnimation;

return empty || optall.queue === false ?
this.each( doAnimation ) :
Expand Down
2 changes: 1 addition & 1 deletion src/effects/Tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ];
}
},

Expand Down
4 changes: 1 addition & 3 deletions src/event/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 2 additions & 4 deletions src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
12 changes: 6 additions & 6 deletions src/var/isFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};

} );
1 change: 0 additions & 1 deletion src/wrapper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars*/
/*!
* jQuery JavaScript Library v@VERSION
* https://jquery.com/
Expand Down

0 comments on commit 9b8cadc

Please sign in to comment.