eslint-plugin-no-jquery v3.1.1
eslint-plugin-no-jquery
Disallow jQuery functions, with suggestions for native equivalents where possible.
Originally a fork of eslint-plugin-jquery.
⬇️ Installation
You'll first need to install ESLint:
npm install eslint --save-devNext, install eslint-plugin-no-jquery:
npm install eslint-plugin-no-jquery --save-devNote: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-no-jquery globally.
🛠️ Usage
Add no-jquery to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"extends": "plugin:no-jquery/deprecated",
"plugins": [
"no-jquery"
]
}📋 Configs
The config plugin:no-jquery/recommended includes the recommended rule no-jquery/variable-pattern which is required for method rules to work correctly.
The config plugin:no-jquery/deprecated includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (deprecated-1.0, ..., deprecated-3.7). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
The config plugin:no-jquery/slim includes all features excluded from the official "slim" build of jQuery, specifically the ajax and effects modules.
The config plugin:no-jquery/all includes all methods and utilies and should be used when you are aiming to remove all jQuery usage from your code.
Alternatively, you can pick out rules individually (see below).
⚙️ Settings
The following global settings can be used under the no-jquery property to configure the linter:
constructorAliases- An array of aliases for the jQuery constructor. Defaults to[ "$", "jQuery" ].variablePattern- Regular expression pattern for matching jQuery variables. Defaults to"^\\$.". This pattern can be enforced with theno-jquery/variable-patternrule.collectionReturningPlugins- An object describing the return types of jQuery plugins. Keys are plugin method names, and values can be one of:'always'a plugin which always returns a jQuery collection.- e.g.
$bar = $foo.stop()
- e.g.
'accessor'a plugin which only returns a jQuery collection when an argument is given.- e.g.
w = $foo.width(),$bar = $foo.width( 200 )
- e.g.
'valueAccessor'a plugin which only returns a jQuery collection when more than one argument is given.- e.g.
w = $foo.css( 'width' ),$bar = $foo.css( 'width', '1em' )
- e.g.
'never'(default) a plugin which never returns a jQuery collection.- e.g.
arr = $foo.toArray()
- e.g.
{
"settings": {
"no-jquery": {
"constructorAliases": [ "$", "jQuery" ],
"variablePattern": "^\\$.|^element$",
"collectionReturningPlugins": {
"datePicker": "always"
}
}
},
"plugins": [
"no-jquery"
]
}📖 Rules
Rules with options are indicated with ⚙️. Rules which are fixable are indicated with 🔧.
Where rules are included in the configs recommended, slim, all or deprecated-X.X it is indicated below. Where rules are included in a config with non-default options this is indicated with a †.
no-jquery/no-ajaxslim,allno-jquery/no-ajax-eventsslimno-jquery/no-and-self🔧1.8no-jquery/no-animate⚙️slim,allno-jquery/no-animate-toggleslimno-jquery/no-append-htmlno-jquery/no-attrallno-jquery/no-bind3.0,allno-jquery/no-box-model1.3no-jquery/no-browser1.3no-jquery/no-camel-case3.3,allno-jquery/no-classallno-jquery/no-class-stateno-jquery/no-cloneallno-jquery/no-closestallno-jquery/no-constructor-attributesno-jquery/no-containsallno-jquery/no-context-prop1.10no-jquery/no-cssallno-jquery/no-dataallno-jquery/no-deferredallno-jquery/no-delegate3.0,allno-jquery/no-done-failallno-jquery/no-eachno-jquery/no-each-collectionallno-jquery/no-each-utilallno-jquery/no-error🔧allno-jquery/no-error-shorthand🔧1.8no-jquery/no-escape-selector🔧allno-jquery/no-event-shorthand⚙️ 🔧3.5,3.3†,allno-jquery/no-extend⚙️ 🔧allno-jquery/no-fadeslim,allno-jquery/no-filterallno-jquery/no-findno-jquery/no-find-collectionallno-jquery/no-find-utilallno-jquery/no-fxslimno-jquery/no-fx-interval3.0no-jquery/no-global-evalallno-jquery/no-global-selector⚙️no-jquery/no-grepallno-jquery/no-hasallno-jquery/no-hold-ready3.2,allno-jquery/no-html⚙️allno-jquery/no-in-arrayallno-jquery/no-isallno-jquery/no-is-array🔧3.2,allno-jquery/no-is-empty-objectallno-jquery/no-is-function🔧3.3,allno-jquery/no-is-numeric3.3,allno-jquery/no-is-plain-objectallno-jquery/no-is-window3.3,allno-jquery/no-jquery-constructorallno-jquery/no-live1.7,allno-jquery/no-loadslim,allno-jquery/no-load-shorthand🔧1.8no-jquery/no-mapno-jquery/no-map-collectionallno-jquery/no-map-utilallno-jquery/no-mergeallno-jquery/no-node-name3.2,allno-jquery/no-noop🔧allno-jquery/no-now🔧3.3,allno-jquery/no-on-ready🔧1.8no-jquery/no-other-methodsallno-jquery/no-other-utilsallno-jquery/no-paramallno-jquery/no-parentallno-jquery/no-parentsallno-jquery/no-parse-htmlallno-jquery/no-parse-html-literal⚙️ 🔧no-jquery/no-parse-json🔧3.0,allno-jquery/no-parse-xml🔧slim,allno-jquery/no-propallno-jquery/no-proxy🔧3.3,allno-jquery/no-readyno-jquery/no-ready-shorthand🔧3.0,allno-jquery/no-selector-prop1.7no-jquery/no-serializeallno-jquery/no-size🔧1.8,allno-jquery/no-sizzle⚙️3.4†no-jquery/no-slideslim,allno-jquery/no-sub1.7,allno-jquery/no-support1.9no-jquery/no-textallno-jquery/no-triggerallno-jquery/no-trim3.5,allno-jquery/no-type3.3,allno-jquery/no-unique🔧3.0,allno-jquery/no-unload-shorthand🔧1.8no-jquery/no-valallno-jquery/no-visibilityallno-jquery/no-whenallno-jquery/no-wrapallno-jquery/variable-patternrecommended
⚠️ Deprecated
no-jquery/no-die(useno-jquery/no-live)no-jquery/no-hide(useno-jquery/no-visibility)no-jquery/no-show(useno-jquery/no-visibility)no-jquery/no-submit(useno-jquery/no-event-shorthand)no-jquery/no-toggle(useno-jquery/no-visibility)no-jquery/no-unbind(useno-jquery/no-bind)no-jquery/no-undelegate(useno-jquery/no-delegate)
🤖 Development
npm install
npm testTo update documentation after modifying a rule or its tests, use
npm run docTo run a specific test or tests:
npm run testpath tests/rules/no-ajax⚖️ License
Distributed under the MIT license. See LICENSE for details.