Hi,

I've been trying to get rid of the ESLint warnings for the JavaScript code
in some of my extensions, when they go through Jenkins validation. One
warning that appears fairly often is this one:

Where possible, maintain application state in JS to avoid slower DOM queries
no-jquery/no-class-state


I'm not sure if this is a warning that's specific to Wikimedia code, but
doing a web search on it brings up this Wikimedia help page as the only
real result:

https://github.com/wikimedia/eslint-plugin-no-jquery/blob/master/docs/rules/no-class-state.md

This page is rather confusing. It says that the warning comes when calling
either hasClass() or toggleClass() on a jQuery element. That part makes
sense, but then the suggested alternatives are strange. The page says that
the following are some examples of bad code:

$( 'div' ).hasClass();
$div.hasClass();

In their place, it suggests the following:

hasClass();
[].hasClass();
div.hasClass();

Can anyone explain this? As far as I'm aware, hasClass() is only defined in
jQuery - and there, only as a method for variables representing jQuery
elements. So what do those "recommended" lines mean? And in general, what
is the best way to determine whether some element on the page has a certain
class?

-Yaron

-- 
WikiWorks · MediaWiki Consulting · http://wikiworks.com
_______________________________________________
MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
List information: 
https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/

Reply via email to