Awesome
<!-- This file is built by build-readme.js. Do not edit it directly; edit README.md.template instead. -->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-dev
Next, install eslint-plugin-no-jquery
:
npm install eslint-plugin-no-jquery --save-dev
Note: 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-pattern
rule.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-ajax
slim
,all
no-jquery/no-ajax-events
slim
no-jquery/no-and-self
🔧1.8
no-jquery/no-animate
⚙️slim
,all
no-jquery/no-animate-toggle
slim
no-jquery/no-append-html
no-jquery/no-attr
all
no-jquery/no-bind
3.0
,all
no-jquery/no-box-model
1.3
no-jquery/no-browser
1.3
no-jquery/no-camel-case
3.3
,all
no-jquery/no-class
all
no-jquery/no-class-state
no-jquery/no-clone
all
no-jquery/no-closest
all
no-jquery/no-constructor-attributes
no-jquery/no-contains
all
no-jquery/no-context-prop
1.10
no-jquery/no-css
all
no-jquery/no-data
all
no-jquery/no-deferred
all
no-jquery/no-delegate
3.0
,all
no-jquery/no-done-fail
all
no-jquery/no-each
no-jquery/no-each-collection
all
no-jquery/no-each-util
all
no-jquery/no-error
🔧all
no-jquery/no-error-shorthand
🔧1.8
no-jquery/no-escape-selector
🔧all
no-jquery/no-event-shorthand
⚙️ 🔧3.5
,3.3†
,all
no-jquery/no-extend
⚙️ 🔧all
no-jquery/no-fade
slim
,all
no-jquery/no-filter
all
no-jquery/no-find
no-jquery/no-find-collection
all
no-jquery/no-find-util
all
no-jquery/no-fx
slim
no-jquery/no-fx-interval
3.0
no-jquery/no-global-eval
all
no-jquery/no-global-selector
⚙️no-jquery/no-grep
all
no-jquery/no-has
all
no-jquery/no-hold-ready
3.2
,all
no-jquery/no-html
⚙️all
no-jquery/no-in-array
all
no-jquery/no-is
all
no-jquery/no-is-array
🔧3.2
,all
no-jquery/no-is-empty-object
all
no-jquery/no-is-function
🔧3.3
,all
no-jquery/no-is-numeric
3.3
,all
no-jquery/no-is-plain-object
all
no-jquery/no-is-window
3.3
,all
no-jquery/no-jquery-constructor
all
no-jquery/no-live
1.7
,all
no-jquery/no-load
slim
,all
no-jquery/no-load-shorthand
🔧1.8
no-jquery/no-map
no-jquery/no-map-collection
all
no-jquery/no-map-util
all
no-jquery/no-merge
all
no-jquery/no-node-name
3.2
,all
no-jquery/no-noop
🔧all
no-jquery/no-now
🔧3.3
,all
no-jquery/no-on-ready
🔧1.8
no-jquery/no-other-methods
all
no-jquery/no-other-utils
all
no-jquery/no-param
all
no-jquery/no-parent
all
no-jquery/no-parents
all
no-jquery/no-parse-html
all
no-jquery/no-parse-html-literal
⚙️ 🔧no-jquery/no-parse-json
🔧3.0
,all
no-jquery/no-parse-xml
🔧slim
,all
no-jquery/no-prop
all
no-jquery/no-proxy
🔧3.3
,all
no-jquery/no-ready
no-jquery/no-ready-shorthand
🔧3.0
,all
no-jquery/no-selector-prop
1.7
no-jquery/no-serialize
all
no-jquery/no-size
🔧1.8
,all
no-jquery/no-sizzle
⚙️3.4†
no-jquery/no-slide
slim
,all
no-jquery/no-sub
1.7
,all
no-jquery/no-support
1.9
no-jquery/no-text
all
no-jquery/no-trigger
all
no-jquery/no-trim
3.5
,all
no-jquery/no-type
3.3
,all
no-jquery/no-unique
🔧3.0
,all
no-jquery/no-unload-shorthand
🔧1.8
no-jquery/no-val
all
no-jquery/no-visibility
all
no-jquery/no-when
all
no-jquery/no-wrap
all
no-jquery/variable-pattern
recommended
⚠️ 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 test
To update documentation after modifying a rule or its tests, use
npm run doc
To run a specific test or tests:
npm run testpath tests/rules/no-ajax
⚖️ License
Distributed under the MIT license. See LICENSE for details.