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 the no-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.
'accessor' a plugin which only returns a jQuery collection when an argument is given.
- e.g.
w = $foo.width(), $bar = $foo.width( 200 )
'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' )
'never' (default) a plugin which never returns a jQuery collection.
- e.g.
arr = $foo.toArray()
{
"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
π€ 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.