Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions eslint-rules/rules/no-jquery-variable-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,34 @@ function isjQueryMethodReturningCollection( node, jQueryVarNames ) {
}

const { object, property } = node.callee;
if ( object.type !== 'Identifier' || property.type !== 'Identifier' ) {
if ( property.type !== 'Identifier' || ! COLLECTION_RETURNING_METHODS.has( property.name ) ) {
return false;
}

if ( ! jQueryVarNames.has( object.name ) ) {
if ( object.type === 'Identifier' ) {
return jQueryVarNames.has( object.name );
}

return isjQueryConstructor( object ) || isjQueryChainedCollectionCall( object );
}

/**
* Checks if a node is a chain of jQuery collection-returning method calls.
*
* Recognizes patterns like `obj.closest( 'form' ).find( 'sel' )` where
* at least two chained methods are collection-returning, treating the
* chain itself as a strong jQuery signal regardless of the root object.
*
* @param {Object} node The AST node.
* @return {boolean} Whether this is a chained jQuery collection call.
*/
function isjQueryChainedCollectionCall( node ) {
if ( node.type !== 'CallExpression' || node.callee.type !== 'MemberExpression' ) {
return false;
}

return COLLECTION_RETURNING_METHODS.has( property.name );
const { property } = node.callee;
return property.type === 'Identifier' && COLLECTION_RETURNING_METHODS.has( property.name );
}

/**
Expand Down
Loading