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
This commit is contained in:
Wonseop Kim 2020-05-05 17:49:27 +09:00 committed by GitHub
parent 11066a9e6a
commit 3d62d57049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 60 additions and 42 deletions

View File

@ -12,7 +12,10 @@
"rules": { "rules": {
"import/extensions": [ "error", "always" ], "import/extensions": [ "error", "always" ],
"import/no-cycle": "error" "import/no-cycle": "error",
"indent": [ "error", "tab", {
"outerIIFEBody": 0
} ]
}, },
"overrides": [ "overrides": [
@ -23,7 +26,17 @@
"sourceType": "script" "sourceType": "script"
}, },
"rules": { "rules": {
"no-unused-vars": "off" "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 > FunctionExpression > *"
]
} ]
}, },
"globals": { "globals": {
"jQuery": false, "jQuery": false,

View File

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

View File

@ -8,9 +8,9 @@ jQuery.ajaxSettings.xhr = function() {
var xhrSuccessStatus = { var xhrSuccessStatus = {
// File protocol always yields status code 0, assume 200 // File protocol always yields status code 0, assume 200
0: 200 0: 200
}; };
jQuery.ajaxTransport( function( options ) { jQuery.ajaxTransport( function( options ) {
var callback; var callback;

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
function nodeName( elem, name ) { function nodeName( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
}; };

View File

@ -320,10 +320,10 @@ jQuery.each( [ "height", "width" ], function( _i, dimension ) {
// Running getBoundingClientRect on a disconnected node // Running getBoundingClientRect on a disconnected node
// in IE throws an error. // in IE throws an error.
( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ? ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
swap( elem, cssShow, function() { swap( elem, cssShow, function() {
return getWidthOrHeight( elem, dimension, extra ); return getWidthOrHeight( elem, dimension, extra );
} ) : } ) :
getWidthOrHeight( elem, dimension, extra ); getWidthOrHeight( elem, dimension, extra );
} }
}, },

View File

@ -28,7 +28,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 " + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup contextmenu" ).split( " " ), "change select submit keydown keypress keyup contextmenu" ).split( " " ),
function( _i, name ) { function( _i, name ) {
@ -39,4 +40,5 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
this.on( name, null, data, fn ) : this.on( name, null, data, fn ) :
this.trigger( name ); this.trigger( name );
}; };
} ); }
);

View File

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

5
src/effects.js vendored
View File

@ -338,7 +338,7 @@ function Animation( elem, properties, options ) {
tweens: [], tweens: [],
createTween: function( prop, end ) { createTween: function( prop, end ) {
var tween = jQuery.Tween( elem, animation.opts, 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 ); animation.tweens.push( tween );
return tween; return tween;
}, },
@ -511,7 +511,8 @@ jQuery.fn.extend( {
anim.stop( true ); anim.stop( true );
} }
}; };
doAnimation.finish = doAnimation;
doAnimation.finish = doAnimation;
return empty || optall.queue === false ? return empty || optall.queue === false ?
this.each( doAnimation ) : this.each( doAnimation ) :

View File

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

View File

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

View File

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

View File

@ -602,9 +602,11 @@ Expr = jQuery.expr = {
TAG: function( nodeNameSelector ) { TAG: function( nodeNameSelector ) {
var expectedNodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase(); var expectedNodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
return nodeNameSelector === "*" ? return nodeNameSelector === "*" ?
function() { function() {
return true; return true;
} : } :
function( elem ) { function( elem ) {
return nodeName( elem, expectedNodeName ); return nodeName( elem, expectedNodeName );
}; };

View File

@ -101,16 +101,14 @@ jQuery.fn.extend( {
// Can add propHook for "elements" to filter or add form elements // Can add propHook for "elements" to filter or add form elements
var elements = jQuery.prop( this, "elements" ); var elements = jQuery.prop( this, "elements" );
return elements ? jQuery.makeArray( elements ) : this; return elements ? jQuery.makeArray( elements ) : this;
} ) } ).filter( function() {
.filter( function() {
var type = this.type; var type = this.type;
// Use .is( ":disabled" ) so that fieldset[disabled] works // Use .is( ":disabled" ) so that fieldset[disabled] works
return this.name && !jQuery( this ).is( ":disabled" ) && return this.name && !jQuery( this ).is( ":disabled" ) &&
rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
( this.checked || !rcheckableType.test( type ) ); ( this.checked || !rcheckableType.test( type ) );
} ) } ).map( function( _i, elem ) {
.map( function( _i, elem ) {
var val = jQuery( this ).val(); var val = jQuery( this ).val();
if ( val == null ) { if ( val == null ) {