├── .editorconfig ├── .eslintdocgenrc.json ├── .eslintignore ├── .eslintrc.json ├── .github └── workflows │ └── nodejs.yml ├── .gitignore ├── .mailmap ├── .nycrc.json ├── Changelog.md ├── LICENSE ├── README.md ├── README.md.template ├── codecov.yaml ├── docs └── rules │ ├── no-ajax-events.md │ ├── no-ajax.md │ ├── no-and-self.md │ ├── no-animate-toggle.md │ ├── no-animate.md │ ├── no-append-html.md │ ├── no-attr.md │ ├── no-bind.md │ ├── no-box-model.md │ ├── no-browser.md │ ├── no-camel-case.md │ ├── no-class-state.md │ ├── no-class.md │ ├── no-clone.md │ ├── no-closest.md │ ├── no-constructor-attributes.md │ ├── no-contains.md │ ├── no-context-prop.md │ ├── no-css.md │ ├── no-data.md │ ├── no-deferred.md │ ├── no-delegate.md │ ├── no-die.md │ ├── no-done-fail.md │ ├── no-each-collection.md │ ├── no-each-util.md │ ├── no-each.md │ ├── no-error-shorthand.md │ ├── no-error.md │ ├── no-escape-selector.md │ ├── no-event-shorthand.md │ ├── no-extend.md │ ├── no-fade.md │ ├── no-filter.md │ ├── no-find-collection.md │ ├── no-find-util.md │ ├── no-find.md │ ├── no-fx-interval.md │ ├── no-fx.md │ ├── no-global-eval.md │ ├── no-global-selector.md │ ├── no-grep.md │ ├── no-has.md │ ├── no-hide.md │ ├── no-hold-ready.md │ ├── no-html.md │ ├── no-in-array.md │ ├── no-is-array.md │ ├── no-is-empty-object.md │ ├── no-is-function.md │ ├── no-is-numeric.md │ ├── no-is-plain-object.md │ ├── no-is-window.md │ ├── no-is.md │ ├── no-jquery-constructor.md │ ├── no-live.md │ ├── no-load-shorthand.md │ ├── no-load.md │ ├── no-map-collection.md │ ├── no-map-util.md │ ├── no-map.md │ ├── no-merge.md │ ├── no-node-name.md │ ├── no-noop.md │ ├── no-now.md │ ├── no-on-ready.md │ ├── no-other-methods.md │ ├── no-other-utils.md │ ├── no-param.md │ ├── no-parent.md │ ├── no-parents.md │ ├── no-parse-html-literal.md │ ├── no-parse-html.md │ ├── no-parse-json.md │ ├── no-parse-xml.md │ ├── no-prop.md │ ├── no-proxy.md │ ├── no-ready-shorthand.md │ ├── no-ready.md │ ├── no-selector-prop.md │ ├── no-serialize.md │ ├── no-show.md │ ├── no-size.md │ ├── no-sizzle.md │ ├── no-slide.md │ ├── no-sub.md │ ├── no-submit.md │ ├── no-support.md │ ├── no-text.md │ ├── no-toggle.md │ ├── no-trigger.md │ ├── no-trim.md │ ├── no-type.md │ ├── no-unbind.md │ ├── no-undelegate.md │ ├── no-unique.md │ ├── no-unload-shorthand.md │ ├── no-val.md │ ├── no-visibility.md │ ├── no-when.md │ ├── no-wrap.md │ └── variable-pattern.md ├── package-lock.json ├── package.json ├── src ├── .eslintrc.js ├── all-methods.js ├── index.js ├── rules │ ├── no-ajax-events.js │ ├── no-ajax.js │ ├── no-and-self.js │ ├── no-animate-toggle.js │ ├── no-animate.js │ ├── no-append-html.js │ ├── no-attr.js │ ├── no-bind.js │ ├── no-box-model.js │ ├── no-browser.js │ ├── no-camel-case.js │ ├── no-class-state.js │ ├── no-class.js │ ├── no-clone.js │ ├── no-closest.js │ ├── no-constructor-attributes.js │ ├── no-contains.js │ ├── no-context-prop.js │ ├── no-css.js │ ├── no-data.js │ ├── no-deferred.js │ ├── no-delegate.js │ ├── no-die.js │ ├── no-done-fail.js │ ├── no-each-collection.js │ ├── no-each-util.js │ ├── no-each.js │ ├── no-error-shorthand.js │ ├── no-error.js │ ├── no-escape-selector.js │ ├── no-event-shorthand.js │ ├── no-extend.js │ ├── no-fade.js │ ├── no-filter.js │ ├── no-find-collection.js │ ├── no-find-util.js │ ├── no-find.js │ ├── no-fx-interval.js │ ├── no-fx.js │ ├── no-global-eval.js │ ├── no-global-selector.js │ ├── no-grep.js │ ├── no-has.js │ ├── no-hide.js │ ├── no-hold-ready.js │ ├── no-html.js │ ├── no-in-array.js │ ├── no-is-array.js │ ├── no-is-empty-object.js │ ├── no-is-function.js │ ├── no-is-numeric.js │ ├── no-is-plain-object.js │ ├── no-is-window.js │ ├── no-is.js │ ├── no-jquery-constructor.js │ ├── no-live.js │ ├── no-load-shorthand.js │ ├── no-load.js │ ├── no-map-collection.js │ ├── no-map-util.js │ ├── no-map.js │ ├── no-merge.js │ ├── no-node-name.js │ ├── no-noop.js │ ├── no-now.js │ ├── no-on-ready.js │ ├── no-other-methods.js │ ├── no-other-utils.js │ ├── no-param.js │ ├── no-parent.js │ ├── no-parents.js │ ├── no-parse-html-literal.js │ ├── no-parse-html.js │ ├── no-parse-json.js │ ├── no-parse-xml.js │ ├── no-prop.js │ ├── no-proxy.js │ ├── no-ready-shorthand.js │ ├── no-ready.js │ ├── no-selector-prop.js │ ├── no-serialize.js │ ├── no-show.js │ ├── no-size.js │ ├── no-sizzle.js │ ├── no-slide.js │ ├── no-sub.js │ ├── no-submit.js │ ├── no-support.js │ ├── no-text.js │ ├── no-toggle.js │ ├── no-trigger.js │ ├── no-trim.js │ ├── no-type.js │ ├── no-unbind.js │ ├── no-undelegate.js │ ├── no-unique.js │ ├── no-unload-shorthand.js │ ├── no-val.js │ ├── no-visibility.js │ ├── no-when.js │ ├── no-wrap.js │ └── variable-pattern.js └── utils.js ├── test-self ├── .eslintrc.json ├── all │ ├── .eslintrc.json │ ├── constructor.js │ ├── methods.js │ └── utils.js ├── deprecated-1.10 │ ├── .eslintrc.json │ └── test.js ├── deprecated-1.3 │ ├── .eslintrc.json │ └── test.js ├── deprecated-1.7 │ ├── .eslintrc.json │ └── test.js ├── deprecated-1.8 │ ├── .eslintrc.json │ └── test.js ├── deprecated-1.9 │ ├── .eslintrc.json │ └── test.js ├── deprecated-3.0 │ ├── .eslintrc.json │ └── test.js ├── deprecated-3.2 │ ├── .eslintrc.json │ └── test.js ├── deprecated-3.3 │ ├── .eslintrc.json │ └── test.js ├── deprecated-3.4 │ ├── .eslintrc.json │ └── test.js ├── deprecated-3.5 │ ├── .eslintrc.json │ └── test.js ├── recommended │ ├── .eslintrc.json │ └── test.js └── slim │ ├── .eslintrc.json │ └── test.js ├── tests ├── .eslintrc.json ├── index.js ├── rules │ ├── no-ajax-events.js │ ├── no-ajax.js │ ├── no-and-self.js │ ├── no-animate-toggle.js │ ├── no-animate.js │ ├── no-append-html.js │ ├── no-attr.js │ ├── no-bind.js │ ├── no-box-model.js │ ├── no-browser.js │ ├── no-camel-case.js │ ├── no-class-state.js │ ├── no-class.js │ ├── no-clone.js │ ├── no-closest.js │ ├── no-constructor-attributes.js │ ├── no-contains.js │ ├── no-context-prop.js │ ├── no-css.js │ ├── no-data.js │ ├── no-deferred.js │ ├── no-delegate.js │ ├── no-die.js │ ├── no-done-fail.js │ ├── no-each-collection.js │ ├── no-each-util.js │ ├── no-each.js │ ├── no-error-shorthand.js │ ├── no-error.js │ ├── no-escape-selector.js │ ├── no-event-shorthand.js │ ├── no-extend.js │ ├── no-fade.js │ ├── no-filter.js │ ├── no-find-collection.js │ ├── no-find-util.js │ ├── no-find.js │ ├── no-fx-interval.js │ ├── no-fx.js │ ├── no-global-eval.js │ ├── no-global-selector.js │ ├── no-grep.js │ ├── no-has.js │ ├── no-hide.js │ ├── no-hold-ready.js │ ├── no-html.js │ ├── no-in-array.js │ ├── no-is-array.js │ ├── no-is-empty-object.js │ ├── no-is-function.js │ ├── no-is-numeric.js │ ├── no-is-plain-object.js │ ├── no-is-window.js │ ├── no-is.js │ ├── no-jquery-constructor.js │ ├── no-live.js │ ├── no-load-shorthand.js │ ├── no-load.js │ ├── no-map-collection.js │ ├── no-map-util.js │ ├── no-map.js │ ├── no-merge.js │ ├── no-node-name.js │ ├── no-noop.js │ ├── no-now.js │ ├── no-on-ready.js │ ├── no-other-methods.js │ ├── no-other-utils.js │ ├── no-param.js │ ├── no-parent.js │ ├── no-parents.js │ ├── no-parse-html-literal.js │ ├── no-parse-html.js │ ├── no-parse-json.js │ ├── no-parse-xml.js │ ├── no-prop.js │ ├── no-proxy.js │ ├── no-ready-shorthand.js │ ├── no-ready.js │ ├── no-selector-prop.js │ ├── no-serialize.js │ ├── no-show.js │ ├── no-size.js │ ├── no-sizzle.js │ ├── no-slide.js │ ├── no-sub.js │ ├── no-submit.js │ ├── no-support.js │ ├── no-text.js │ ├── no-toggle.js │ ├── no-trigger.js │ ├── no-trim.js │ ├── no-type.js │ ├── no-unbind.js │ ├── no-undelegate.js │ ├── no-unique.js │ ├── no-unload-shorthand.js │ ├── no-val.js │ ├── no-visibility.js │ ├── no-when.js │ ├── no-wrap.js │ └── variable-pattern.js └── settings.js └── tools ├── build-all-methods.js ├── build-readme.js └── rule-tester.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | 9 | [*.js] 10 | indent_style = tab 11 | -------------------------------------------------------------------------------- /.eslintdocgenrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "docPath": "docs/rules/{name}.md", 3 | "rulePath": "src/rules/{name}.js", 4 | "testPath": "tests/rules/{name}.js" 5 | } 6 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | docs/ 2 | .eslintrc.js 3 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "wikimedia", 4 | "wikimedia/node", 5 | "wikimedia/language/es2016", 6 | "plugin:eslint-plugin/all" 7 | ], 8 | "plugins": [ 9 | "eslint-plugin" 10 | ], 11 | "rules": { 12 | "eslint-plugin/consistent-output": "off", 13 | "eslint-plugin/fixer-return": "off", 14 | "eslint-plugin/prefer-message-ids": "off", 15 | "eslint-plugin/require-meta-docs-description": "off", 16 | "eslint-plugin/require-meta-docs-recommended": "off", 17 | "eslint-plugin/require-meta-docs-url": "off", 18 | "eslint-plugin/test-case-property-ordering": [ "error", 19 | [ "code", "options", "parserOptions", "settings", "errors", "output" ] 20 | ], 21 | "object-shorthand": [ "error", "properties" ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: Node CI 2 | 3 | on: [push,pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | node-version: [18.x, 20.x, 22.x] 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Use Node.js ${{ matrix.node-version }} 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - name: npm install, build, and test 21 | run: | 22 | npm ci 23 | npm run build --if-present 24 | npm test 25 | npm run report 26 | npm i --no-save eslint@8.0.0 --force 27 | npm run onlytest 28 | env: 29 | CI: true 30 | - name: Upload coverage to Codecov 31 | uses: codecov/codecov-action@v4 32 | with: 33 | token: ${{ secrets.CODECOV_TOKEN }} 34 | file: ./coverage.lcov 35 | flgas: unittests 36 | name: codecov-umbrella 37 | fail_ci_if_error: true 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .nyc_output/ 3 | coverage/ 4 | coverage.lcov 5 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Brendan Abbott 2 | Brendan Abbott 3 | David Graham 4 | David Graham 5 | Ed Sanders 6 | James D. Forrester 7 | -------------------------------------------------------------------------------- /.nycrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "include": [ 4 | "src/**/*.js" 5 | ], 6 | "check-coverage": true, 7 | "per-file": true, 8 | "branches": 90, 9 | "lines": 90, 10 | "functions": 90, 11 | "statements": 90 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ed Sanders, David Graham and others 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /codecov.yaml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: "diff, files" 3 | -------------------------------------------------------------------------------- /docs/rules/no-ajax-events.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-ajax-events 4 | 5 | Disallows global ajax events handlers: [`.ajaxComplete`](https://api.jquery.com/ajaxComplete/)/[`.ajaxError`](https://api.jquery.com/ajaxError/)/[`.ajaxSend`](https://api.jquery.com/ajaxSend/)/[`.ajaxStart`](https://api.jquery.com/ajaxStart/)/[`.ajaxStop`](https://api.jquery.com/ajaxStop/)/[`.ajaxSuccess`](https://api.jquery.com/ajaxSuccess/). Prefer local events. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/slim`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( document ).on( 'ajaxSend', fn ); 14 | $( document ).on( 'ajaxSuccess', fn ); 15 | $form.on( 'ajaxError', fn ); 16 | $form.on( 'ajaxComplete', fn ); 17 | $form.on( 'ajaxStart', fn ); 18 | $form.on( 'ajaxStop', fn ); 19 | $( document ).ajaxSend( fn ); 20 | $( document ).ajaxSuccess( fn ); 21 | $form.ajaxError( fn ); 22 | $form.ajaxComplete( fn ); 23 | $form.ajaxStart( fn ); 24 | $form.ajaxStop( fn ); 25 | ``` 26 | 27 | ✔️ Examples of **correct** code: 28 | ```js 29 | $( document ).on( 'click', fn ); 30 | $form.on( 'submit', fn ); 31 | $form.on(); 32 | on( 'ajaxSuccess', '.js-select-menu', fn ); 33 | form.on( 'ajaxSend' ); 34 | form.ajaxSend(); 35 | $.ajaxSend(); 36 | ``` 37 | 38 | ## Resources 39 | 40 | * [Rule source](/src/rules/no-ajax-events.js) 41 | * [Test source](/tests/rules/no-ajax-events.js) 42 | -------------------------------------------------------------------------------- /docs/rules/no-ajax.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-ajax 4 | 5 | Disallows the [`$.ajax`](https://api.jquery.com/jQuery.ajax/)/[`$.get`](https://api.jquery.com/jQuery.get/)/[`$.getJSON`](https://api.jquery.com/jQuery.getJSON/)/[`$.getScript`](https://api.jquery.com/jQuery.getScript/)/[`$.post`](https://api.jquery.com/jQuery.post/) utilies. Prefer `Window.fetch`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/slim`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.ajax(); 16 | $.get(); 17 | $.getJSON(); 18 | $.getScript(); 19 | $.post(); 20 | ``` 21 | 22 | ✔️ Examples of **correct** code: 23 | ```js 24 | ajax(); 25 | div.ajax(); 26 | div.ajax; 27 | get(); 28 | div.get(); 29 | div.get; 30 | getJSON(); 31 | div.getJSON(); 32 | div.getJSON; 33 | getScript(); 34 | div.getScript(); 35 | div.getScript; 36 | post(); 37 | div.post(); 38 | div.post; 39 | ``` 40 | 41 | ## Resources 42 | 43 | * [Rule source](/src/rules/no-ajax.js) 44 | * [Test source](/tests/rules/no-ajax.js) 45 | -------------------------------------------------------------------------------- /docs/rules/no-and-self.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-and-self 4 | 5 | Disallows the [`.andSelf`](https://api.jquery.com/andSelf/) method. Prefer `.addBack`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.8`. 8 | 9 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( 'div' ).andSelf( '.foo' ); 16 | $div.andSelf( '.foo' ); 17 | $( 'div' ).first().andSelf(); 18 | $( 'div' ).append( $( 'input' ).andSelf() ); 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | andSelf(); 24 | [].andSelf(); 25 | div.andSelf(); 26 | div.andSelf; 27 | ``` 28 | 29 | 🔧 Examples of code **fixed** by this rule: 30 | ```js 31 | $( 'div' ).andSelf( '.foo' ); /* → */ $( 'div' ).addBack( '.foo' ); 32 | $div.andSelf( '.foo' ); /* → */ $div.addBack( '.foo' ); 33 | $( 'div' ).first().andSelf(); /* → */ $( 'div' ).first().addBack(); 34 | $( 'div' ).append( $( 'input' ).andSelf() ); /* → */ $( 'div' ).append( $( 'input' ).addBack() ); 35 | ``` 36 | 37 | ## Resources 38 | 39 | * [Rule source](/src/rules/no-and-self.js) 40 | * [Test source](/tests/rules/no-and-self.js) 41 | -------------------------------------------------------------------------------- /docs/rules/no-attr.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-attr 4 | 5 | Disallows the [`.attr`](https://api.jquery.com/attr/)/[`.removeAttr`](https://api.jquery.com/removeAttr/) methods and `$.attr`/[`$.removeAttr`](https://api.jquery.com/jQuery.removeAttr/) utilies. Prefer `Element#getAttribute`/`setAttribute`/`removeAttribute`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.attr(); 14 | $( 'div' ).attr(); 15 | $div.attr(); 16 | $( 'div' ).first().attr(); 17 | $( 'div' ).append( $( 'input' ).attr() ); 18 | $( 'div' ).attr( 'name' ); 19 | $( 'div' ).attr( 'name', 'random' ); 20 | $.removeAttr(); 21 | $( 'div' ).removeAttr( 'name' ); 22 | ``` 23 | 24 | ✔️ Examples of **correct** code: 25 | ```js 26 | attr(); 27 | [].attr(); 28 | div.attr(); 29 | div.attr; 30 | removeAttr(); 31 | div.removeAttr; 32 | ``` 33 | 34 | ## Resources 35 | 36 | * [Rule source](/src/rules/no-attr.js) 37 | * [Test source](/tests/rules/no-attr.js) 38 | -------------------------------------------------------------------------------- /docs/rules/no-bind.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-bind 4 | 5 | Disallows the [`.bind`](https://api.jquery.com/bind/)/[`.unbind`](https://api.jquery.com/unbind/) methods. Prefer `.on`/`.off` or `EventTarget#addEventListener`/`removeEventListener`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.0`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( 'div' ).bind(); 16 | $div.bind(); 17 | $( 'div' ).first().bind(); 18 | $( 'div' ).append( $( 'input' ).bind() ); 19 | $( 'div' ).unbind(); 20 | $div.unbind(); 21 | $( 'div' ).first().unbind(); 22 | $( 'div' ).append( $( 'input' ).unbind() ); 23 | ``` 24 | 25 | ✔️ Examples of **correct** code: 26 | ```js 27 | bind(); 28 | [].bind(); 29 | div.bind(); 30 | div.bind; 31 | $div.remove.bind( $div ); 32 | unbind(); 33 | [].unbind(); 34 | div.unbind(); 35 | div.unbind; 36 | $div.remove.unbind( $div ); 37 | ``` 38 | 39 | ## Resources 40 | 41 | * [Rule source](/src/rules/no-bind.js) 42 | * [Test source](/tests/rules/no-bind.js) 43 | -------------------------------------------------------------------------------- /docs/rules/no-box-model.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-box-model 4 | 5 | Disallows the [`$.boxModel`](https://api.jquery.com/jQuery.boxModel/) property. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.3`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.boxModel; 14 | $.boxModel.style; 15 | ``` 16 | 17 | ✔️ Examples of **correct** code: 18 | ```js 19 | boxModel; 20 | a.boxModel; 21 | boxModel.foo; 22 | a.boxModel.foo; 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-box-model.js) 28 | * [Test source](/tests/rules/no-box-model.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-browser.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-browser 4 | 5 | Disallows the [`$.browser`](https://api.jquery.com/jQuery.browser/) property. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.3`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.browser; 14 | $.browser.style; 15 | ``` 16 | 17 | ✔️ Examples of **correct** code: 18 | ```js 19 | browser; 20 | a.browser; 21 | browser.foo; 22 | a.browser.foo; 23 | $.browsers; 24 | ``` 25 | 26 | ## Resources 27 | 28 | * [Rule source](/src/rules/no-browser.js) 29 | * [Test source](/tests/rules/no-browser.js) 30 | -------------------------------------------------------------------------------- /docs/rules/no-camel-case.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-camel-case 4 | 5 | Disallows the `$.camelCase` utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.3`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.camelCase(); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | camelCase(); 21 | myClass.camelCase(); 22 | $div.camelCase(); 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-camel-case.js) 28 | * [Test source](/tests/rules/no-camel-case.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-class-state.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-class-state 4 | 5 | Disallows [`.hasClass`](https://api.jquery.com/hasClass/) and [`.toggleClass`](https://api.jquery.com/toggleClass/) to discourage querying the DOM for state information. [`.toggleClass`](https://api.jquery.com/toggleClass/) may be used with a boolean argument as then it behaves like [`.addClass`](https://api.jquery.com/addClass/)/[`.removeClass`](https://api.jquery.com/removeClass/). 6 | 7 | ## Rule details 8 | 9 | ❌ Examples of **incorrect** code: 10 | ```js 11 | $( 'div' ).hasClass(); 12 | $div.hasClass(); 13 | $( 'div' ).first().hasClass(); 14 | $( 'div' ).append( $( 'input' ).hasClass() ); 15 | $( 'div' ).toggleClass( 'myClass' ); 16 | $div.toggleClass( 'myClass' ); 17 | $( 'div' ).first().toggleClass( 'myClass' ); 18 | $( 'div' ).append( $( 'input' ).toggleClass( 'myClass' ) ); 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | hasClass(); 24 | [].hasClass(); 25 | div.hasClass(); 26 | div.hasClass; 27 | toggleClass(); 28 | [].toggleClass(); 29 | div.toggleClass(); 30 | div.toggleClass; 31 | $div.toggleClass( 'myClass', true ); 32 | $div.toggleClass( 'myClass', false ); 33 | ``` 34 | 35 | ## Resources 36 | 37 | * [Rule source](/src/rules/no-class-state.js) 38 | * [Test source](/tests/rules/no-class-state.js) 39 | -------------------------------------------------------------------------------- /docs/rules/no-clone.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-clone 4 | 5 | Disallows the [`.clone`](https://api.jquery.com/clone/) method and `$.clone` utility. Prefer `Node#cloneNode`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.clone(); 14 | $( 'div' ).clone(); 15 | $div.clone(); 16 | this.prop.$div.clone(); 17 | $( 'div' ).first().clone(); 18 | $( 'div' ).append( $( 'input' ).clone() ); 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | clone(); 24 | [].clone(); 25 | div.clone(); 26 | div.clone; 27 | $div.prop.clone(); 28 | $div[ 0 ].clone(); 29 | ``` 30 | 31 | ## Resources 32 | 33 | * [Rule source](/src/rules/no-clone.js) 34 | * [Test source](/tests/rules/no-clone.js) 35 | -------------------------------------------------------------------------------- /docs/rules/no-closest.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-closest 4 | 5 | Disallows the [`.closest`](https://api.jquery.com/closest/) method. Prefer `Element#closest`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).closest(); 14 | $div.closest(); 15 | $( 'div' ).first().closest(); 16 | $( 'div' ).append( $( 'input' ).closest() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | closest(); 22 | [].closest(); 23 | div.closest(); 24 | div.closest; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-closest.js) 30 | * [Test source](/tests/rules/no-closest.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-constructor-attributes.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-constructor-attributes 4 | 5 | Disallows passing attributes to the jQuery constructor. Prefer `.attr`. 6 | 7 | ## Rule details 8 | 9 | ❌ Examples of **incorrect** code: 10 | ```js 11 | $( '
', { width: 100, class: 'foo' } ); 12 | $( '
', { on: { click: function () {} } } ); 13 | $( '
', { data: { foo: 'bar' } } ); 14 | $div.add( '
', { width: 100, class: 'foo' } ); 15 | ``` 16 | 17 | ✔️ Examples of **correct** code: 18 | ```js 19 | $( '.div' ); 20 | $( '
' ); 21 | $( '.div', context ); 22 | $( '
', ownerDocument ); 23 | $( '
', ownerDocument ); 24 | $div.add( '
', context ); 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-constructor-attributes.js) 30 | * [Test source](/tests/rules/no-constructor-attributes.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-contains.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-contains 4 | 5 | Disallows the [`$.contains`](https://api.jquery.com/jQuery.contains/) utility. Prefer `Node#contains`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.contains(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | contains(); 19 | myClass.contains(); 20 | $div.contains(); 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-contains.js) 26 | * [Test source](/tests/rules/no-contains.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-context-prop.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-context-prop 4 | 5 | Disallows the [`.context`](https://api.jquery.com/context/) property. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.10`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).context; 14 | $div.context; 15 | $div.context.prop; 16 | $div.context.method(); 17 | $( 'div' ).first().context; 18 | f( $div.context ); 19 | $( 'div' ).append( $( 'input' ).context ); 20 | ``` 21 | 22 | ✔️ Examples of **correct** code: 23 | ```js 24 | context; 25 | div.context; 26 | $div.prop.context; 27 | $div.context(); 28 | $div.context( arg ); 29 | ``` 30 | 31 | ## Resources 32 | 33 | * [Rule source](/src/rules/no-context-prop.js) 34 | * [Test source](/tests/rules/no-context-prop.js) 35 | -------------------------------------------------------------------------------- /docs/rules/no-css.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-css 4 | 5 | Disallows the [`.css`](https://api.jquery.com/css/) method and `$.css` utility. Prefer `Window#getComputedStyle`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.css(); 14 | $( 'div' ).css(); 15 | $div.css(); 16 | $( 'div' ).first().css(); 17 | $( 'div' ).append( $( 'input' ).css() ); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | css(); 23 | [].css(); 24 | div.css(); 25 | div.css; 26 | ``` 27 | 28 | ## Resources 29 | 30 | * [Rule source](/src/rules/no-css.js) 31 | * [Test source](/tests/rules/no-css.js) 32 | -------------------------------------------------------------------------------- /docs/rules/no-data.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-data 4 | 5 | Disallows the [`.data`](https://api.jquery.com/data/)/[`.removeData`](https://api.jquery.com/removeData/)/`.hasData` methods and [`$.data`](https://api.jquery.com/jQuery.data/)/[`$.removeData`](https://api.jquery.com/jQuery.removeData/)/[`$.hasData`](https://api.jquery.com/jQuery.hasData/) utilies. Prefer `WeakMap`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.data( elem, 'foo' ); 14 | $( 'div' ).data( 'foo', 'bar' ); 15 | $div.data( 'foo' ); 16 | $( 'div' ).first().data( 'foo', 'bar' ); 17 | $( 'div' ).append( $( 'input' ).data( 'foo' ) ); 18 | $.removeData( elem, 'foo' ); 19 | $( 'div' ).removeData( 'foo' ); 20 | $div.removeData( 'foo' ); 21 | $.hasData( elem ); 22 | ``` 23 | 24 | ✔️ Examples of **correct** code: 25 | ```js 26 | data(); 27 | [].data(); 28 | div.data(); 29 | div.data; 30 | removeData(); 31 | [].removeData(); 32 | div.removeData(); 33 | div.removeData; 34 | hasData(); 35 | [].hasData(); 36 | div.hasData(); 37 | div.hasData; 38 | ``` 39 | 40 | ## Resources 41 | 42 | * [Rule source](/src/rules/no-data.js) 43 | * [Test source](/tests/rules/no-data.js) 44 | -------------------------------------------------------------------------------- /docs/rules/no-deferred.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-deferred 4 | 5 | Disallows [`$.Deferred`](https://api.jquery.com/jQuery.Deferred/) constructor. Prefer `Promise`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.Deferred(); 14 | new $.Deferred(); 15 | ``` 16 | 17 | ✔️ Examples of **correct** code: 18 | ```js 19 | Deferred(); 20 | new Deferred(); 21 | 'test'.Deferred(); 22 | 'test'.Deferred; 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-deferred.js) 28 | * [Test source](/tests/rules/no-deferred.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-delegate.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-delegate 4 | 5 | Disallows the [`.delegate`](https://api.jquery.com/delegate/)/[`.undelegate`](https://api.jquery.com/undelegate/) methods. Prefer `.on`/`.off` or `EventTarget#addEventListener`/`removeEventListener`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.0`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( 'div' ).delegate(); 16 | $div.delegate(); 17 | $( 'div' ).first().delegate(); 18 | $( 'div' ).append( $( 'input' ).delegate() ); 19 | $( 'div' ).undelegate(); 20 | $div.undelegate(); 21 | $( 'div' ).first().undelegate(); 22 | $( 'div' ).append( $( 'input' ).undelegate() ); 23 | ``` 24 | 25 | ✔️ Examples of **correct** code: 26 | ```js 27 | delegate(); 28 | [].delegate(); 29 | div.delegate(); 30 | div.delegate; 31 | undelegate(); 32 | [].undelegate(); 33 | div.undelegate(); 34 | div.undelegate; 35 | ``` 36 | 37 | ## Resources 38 | 39 | * [Rule source](/src/rules/no-delegate.js) 40 | * [Test source](/tests/rules/no-delegate.js) 41 | -------------------------------------------------------------------------------- /docs/rules/no-die.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-die 4 | 5 | Disallows the [`.die`](https://api.jquery.com/die/) method. Prefer `.off`/`EventTarget#removeEventListener`. 6 | 7 | ⚠️ This rule is deprecated. Use [`no-live`](no-live.md) instead. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).die(); 14 | $div.die(); 15 | $( 'div' ).first().die(); 16 | $( 'div' ).append( $( 'input' ).die() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | die(); 22 | [].die(); 23 | div.die(); 24 | div.die; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-die.js) 30 | * [Test source](/tests/rules/no-die.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-done-fail.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-done-fail 4 | 5 | Disallows the [`.done`](https://api.jquery.com/deferred.done/)/[`.fail`](https://api.jquery.com/deferred.fail/) methods. Prefer `.then`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | promise.done( callback ); 14 | promise.fail( callback ); 15 | ``` 16 | 17 | ✔️ Examples of **correct** code: 18 | ```js 19 | promise.then( doneCallback, failCallback ); 20 | done(); 21 | fail(); 22 | ``` 23 | 24 | ## Resources 25 | 26 | * [Rule source](/src/rules/no-done-fail.js) 27 | * [Test source](/tests/rules/no-done-fail.js) 28 | -------------------------------------------------------------------------------- /docs/rules/no-each-collection.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-each-collection 4 | 5 | Disallows the [`.each`](https://api.jquery.com/each/) method. Prefer `Array#forEach`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).each(); 14 | $div.each(); 15 | $( 'div' ).first().each(); 16 | $( 'div' ).append( $( 'input' ).each() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | each(); 22 | [].each(); 23 | div.each(); 24 | div.each; 25 | $.each(); 26 | ``` 27 | 28 | ## Resources 29 | 30 | * [Rule source](/src/rules/no-each-collection.js) 31 | * [Test source](/tests/rules/no-each-collection.js) 32 | -------------------------------------------------------------------------------- /docs/rules/no-each-util.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-each-util 4 | 5 | Disallows the [`$.each`](https://api.jquery.com/jQuery.each/) utility. Prefer `Array#forEach`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.each(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | each(); 19 | [].each(); 20 | div.each(); 21 | div.each; 22 | $( 'div' ).each(); 23 | $div.each(); 24 | $( 'div' ).first().each(); 25 | $( 'div' ).append( $( 'input' ).each() ); 26 | ``` 27 | 28 | ## Resources 29 | 30 | * [Rule source](/src/rules/no-each-util.js) 31 | * [Test source](/tests/rules/no-each-util.js) 32 | -------------------------------------------------------------------------------- /docs/rules/no-each.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-each 4 | 5 | Disallows the [`.each`](https://api.jquery.com/each/) method and [`$.each`](https://api.jquery.com/jQuery.each/) utility. Prefer `Array#forEach`. 6 | 7 | ## Rule details 8 | 9 | ❌ Examples of **incorrect** code: 10 | ```js 11 | $.each(); 12 | $( 'div' ).each(); 13 | $div.each(); 14 | $( 'div' ).first().each(); 15 | $( 'div' ).append( $( 'input' ).each() ); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | each(); 21 | [].each(); 22 | div.each(); 23 | div.each; 24 | ``` 25 | 26 | ## Resources 27 | 28 | * [Rule source](/src/rules/no-each.js) 29 | * [Test source](/tests/rules/no-each.js) 30 | -------------------------------------------------------------------------------- /docs/rules/no-error-shorthand.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-error-shorthand 4 | 5 | Disallows the [`.error`](https://api.jquery.com/error/) method. Prefer `.on` or `.trigger`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.8`. 8 | 9 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( 'div' ).error( handler ); 16 | $div.error(); 17 | $( 'div' ).first().error(); 18 | $( 'div' ).append( $( 'input' ).error() ); 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | error(); 24 | [].error(); 25 | div.error(); 26 | div.error; 27 | $.error(); 28 | ``` 29 | 30 | 🔧 Examples of code **fixed** by this rule: 31 | ```js 32 | $( 'div' ).error( handler ); /* → */ $( 'div' ).on( 'error', handler ); 33 | $div.error(); /* → */ $div.trigger( 'error' ); 34 | $( 'div' ).first().error(); /* → */ $( 'div' ).first().trigger( 'error' ); 35 | $( 'div' ).append( $( 'input' ).error() ); /* → */ $( 'div' ).append( $( 'input' ).trigger( 'error' ) ); 36 | ``` 37 | 38 | ## Resources 39 | 40 | * [Rule source](/src/rules/no-error-shorthand.js) 41 | * [Test source](/tests/rules/no-error-shorthand.js) 42 | -------------------------------------------------------------------------------- /docs/rules/no-error.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-error 4 | 5 | Disallows the [`$.error`](https://api.jquery.com/jQuery.error/) utility. Prefer `throw`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.error( msg ); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | error( msg ); 21 | myClass.error( msg ); 22 | $div.error( msg ); 23 | ``` 24 | 25 | 🔧 Examples of code **fixed** by this rule: 26 | ```js 27 | $.error( msg ); /* → */ throw new Error( msg ); 28 | ``` 29 | 30 | ## Resources 31 | 32 | * [Rule source](/src/rules/no-error.js) 33 | * [Test source](/tests/rules/no-error.js) 34 | -------------------------------------------------------------------------------- /docs/rules/no-escape-selector.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-escape-selector 4 | 5 | Disallows the [`$.escapeSelector`](https://api.jquery.com/jQuery.escapeSelector/) utility. Prefer `CSS.escape`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.escapeSelector( '.foo>' ); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | escapeSelector( '.foo>' ); 21 | myClass.escapeSelector( '.foo>' ); 22 | $div.escapeSelector( '.foo>' ); 23 | ``` 24 | 25 | 🔧 Examples of code **fixed** by this rule: 26 | ```js 27 | $.escapeSelector( '.foo>' ); /* → */ CSS.escape( '.foo>' ); 28 | ``` 29 | 30 | ## Resources 31 | 32 | * [Rule source](/src/rules/no-escape-selector.js) 33 | * [Test source](/tests/rules/no-escape-selector.js) 34 | -------------------------------------------------------------------------------- /docs/rules/no-filter.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-filter 4 | 5 | Disallows the [`.filter`](https://api.jquery.com/filter/) method and `$.filter` utility. Prefer `Array#filter`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.filter(); 14 | $( 'div' ).filter(); 15 | $div.filter(); 16 | $( 'div' ).first().filter(); 17 | $( 'div' ).append( $( 'input' ).filter() ); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | filter(); 23 | [].filter(); 24 | div.filter(); 25 | div.filter; 26 | ``` 27 | 28 | ## Resources 29 | 30 | * [Rule source](/src/rules/no-filter.js) 31 | * [Test source](/tests/rules/no-filter.js) 32 | -------------------------------------------------------------------------------- /docs/rules/no-find-collection.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-find-collection 4 | 5 | Disallows the [`.find`](https://api.jquery.com/find/) method. Prefer `Document#querySelectorAll`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).find(); 14 | $div.find(); 15 | $( 'div' ).first().find(); 16 | $( 'div' ).append( $( 'input' ).find() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | $.find(); 22 | find(); 23 | [].find(); 24 | div.find(); 25 | div.find; 26 | $.extend().find(); 27 | $div.myPlugin( 'foo' ).find(); 28 | ``` 29 | 30 | ## Resources 31 | 32 | * [Rule source](/src/rules/no-find-collection.js) 33 | * [Test source](/tests/rules/no-find-collection.js) 34 | -------------------------------------------------------------------------------- /docs/rules/no-find-util.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-find-util 4 | 5 | Disallows the `$.find` utility. Prefer `Document#querySelectorAll`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.find(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | find(); 19 | [].find(); 20 | div.find(); 21 | div.find; 22 | $.extend().find(); 23 | $div.myPlugin( 'foo' ).find(); 24 | $( 'div' ).find(); 25 | $div.find(); 26 | $( 'div' ).first().find(); 27 | $( 'div' ).append( $( 'input' ).find() ); 28 | ``` 29 | 30 | ## Resources 31 | 32 | * [Rule source](/src/rules/no-find-util.js) 33 | * [Test source](/tests/rules/no-find-util.js) 34 | -------------------------------------------------------------------------------- /docs/rules/no-find.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-find 4 | 5 | Disallows the [`.find`](https://api.jquery.com/find/) method and `$.find` utility. Prefer `Document#querySelectorAll`. 6 | 7 | ## Rule details 8 | 9 | ❌ Examples of **incorrect** code: 10 | ```js 11 | $.find(); 12 | $( 'div' ).find(); 13 | $div.find(); 14 | $( 'div' ).first().find(); 15 | $( 'div' ).append( $( 'input' ).find() ); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | find(); 21 | [].find(); 22 | div.find(); 23 | div.find; 24 | $.extend().find(); 25 | $div.myPlugin( 'foo' ).find(); 26 | ``` 27 | 28 | ## Resources 29 | 30 | * [Rule source](/src/rules/no-find.js) 31 | * [Test source](/tests/rules/no-find.js) 32 | -------------------------------------------------------------------------------- /docs/rules/no-fx-interval.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-fx-interval 4 | 5 | Disallows [`$.fx.interval`](https://api.jquery.com/jQuery.fx.interval/). 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.0`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.fx.interval; 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | interval; 19 | fx.interval; 20 | $.interval; 21 | a.fx.interval; 22 | $.fx; 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-fx-interval.js) 28 | * [Test source](/tests/rules/no-fx-interval.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-fx.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-fx 4 | 5 | Disallows `$.fx`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/slim`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.fx; 14 | $.fx.interval; 15 | $.fx.off; 16 | $.fx.speeds.slow; 17 | $.fx.start(); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | fx; 23 | fx.interval; 24 | a.fx; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-fx.js) 30 | * [Test source](/tests/rules/no-fx.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-global-eval.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-global-eval 4 | 5 | Disallows the [`$.globalEval`](https://api.jquery.com/jQuery.globalEval/) utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.globalEval(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | globalEval(); 19 | 'test'.globalEval(); 20 | 'test'.globalEval; 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-global-eval.js) 26 | * [Test source](/tests/rules/no-global-eval.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-grep.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-grep 4 | 5 | Disallows the [`$.grep`](https://api.jquery.com/jQuery.grep/) utility. Prefer `Array#filter`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.grep(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | grep(); 19 | 'test'.grep(); 20 | 'test'.grep; 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-grep.js) 26 | * [Test source](/tests/rules/no-grep.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-has.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-has 4 | 5 | Disallows the [`.has`](https://api.jquery.com/has/) method. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).has(); 14 | $div.has(); 15 | $( 'div' ).first().has(); 16 | $( 'div' ).append( $( 'input' ).has() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | has(); 22 | [].has(); 23 | div.has(); 24 | div.has; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-has.js) 30 | * [Test source](/tests/rules/no-has.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-hide.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-hide 4 | 5 | Disallows the [`.hide`](https://api.jquery.com/hide/) method. 6 | 7 | ⚠️ This rule is deprecated. Use [`no-visibility`](no-visibility.md) instead. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).hide(); 14 | $div.hide(); 15 | $( 'div' ).first().hide(); 16 | $( 'div' ).append( $( 'input' ).hide() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | hide(); 22 | [].hide(); 23 | div.hide(); 24 | div.hide; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-hide.js) 30 | * [Test source](/tests/rules/no-hide.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-hold-ready.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-hold-ready 4 | 5 | Disallows the [`$.holdReady`](https://api.jquery.com/jQuery.holdReady/) utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.2`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.holdReady(); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | holdReady(); 21 | 'test'.holdReady(); 22 | 'test'.holdReady; 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-hold-ready.js) 28 | * [Test source](/tests/rules/no-hold-ready.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-in-array.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-in-array 4 | 5 | Disallows the [`$.inArray`](https://api.jquery.com/jQuery.inArray/) utility. Prefer `Array#indexOf`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.inArray(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | inArray(); 19 | 'test'.inArray(); 20 | 'test'.inArray; 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-in-array.js) 26 | * [Test source](/tests/rules/no-in-array.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-is-array.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-is-array 4 | 5 | Disallows the [`$.isArray`](https://api.jquery.com/jQuery.isArray/) utility. Prefer `Array.isArray`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.2`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $.isArray( [] ); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | isArray(); 23 | 'test'.isArray(); 24 | 'test'.isArray; 25 | ``` 26 | 27 | 🔧 Examples of code **fixed** by this rule: 28 | ```js 29 | $.isArray( [] ); /* → */ Array.isArray( [] ); 30 | ``` 31 | 32 | ## Resources 33 | 34 | * [Rule source](/src/rules/no-is-array.js) 35 | * [Test source](/tests/rules/no-is-array.js) 36 | -------------------------------------------------------------------------------- /docs/rules/no-is-empty-object.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-is-empty-object 4 | 5 | Disallows the [`$.isEmptyObject`](https://api.jquery.com/jQuery.isEmptyObject/) utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.isEmptyObject(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | isEmptyObject(); 19 | myClass.isEmptyObject(); 20 | $div.isEmptyObject(); 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-is-empty-object.js) 26 | * [Test source](/tests/rules/no-is-empty-object.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-is-function.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-is-function 4 | 5 | Disallows the [`$.isFunction`](https://api.jquery.com/jQuery.isFunction/) utility. Prefer `typeof`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.3`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $.isFunction( expression( arg ) ); 18 | if ( $.isFunction( fn ) ) { g(); } 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | isFunction(); 24 | myClass.isFunction(); 25 | $div.isFunction(); 26 | ``` 27 | 28 | 🔧 Examples of code **fixed** by this rule: 29 | ```js 30 | $.isFunction( expression( arg ) ); /* → */ typeof expression( arg ) === 'function'; 31 | if ( $.isFunction( fn ) ) { g(); } /* → */ if ( typeof fn === 'function' ) { g(); } 32 | ``` 33 | 34 | ## Resources 35 | 36 | * [Rule source](/src/rules/no-is-function.js) 37 | * [Test source](/tests/rules/no-is-function.js) 38 | -------------------------------------------------------------------------------- /docs/rules/no-is-numeric.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-is-numeric 4 | 5 | Disallows the [`$.isNumeric`](https://api.jquery.com/jQuery.isNumeric/) utility. Prefer `typeof`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.3`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.isNumeric(); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | isNumeric(); 21 | myClass.isNumeric(); 22 | $div.isNumeric(); 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-is-numeric.js) 28 | * [Test source](/tests/rules/no-is-numeric.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-is-plain-object.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-is-plain-object 4 | 5 | Disallows the [`$.isPlainObject`](https://api.jquery.com/jQuery.isPlainObject/) utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.isPlainObject(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | isPlainObject(); 19 | myClass.isPlainObject(); 20 | $div.isPlainObject(); 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-is-plain-object.js) 26 | * [Test source](/tests/rules/no-is-plain-object.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-is-window.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-is-window 4 | 5 | Disallows the [`$.isWindow`](https://api.jquery.com/jQuery.isWindow/) utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.3`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.isWindow(); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | isWindow(); 21 | myClass.isWindow(); 22 | ``` 23 | 24 | ## Resources 25 | 26 | * [Rule source](/src/rules/no-is-window.js) 27 | * [Test source](/tests/rules/no-is-window.js) 28 | -------------------------------------------------------------------------------- /docs/rules/no-is.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-is 4 | 5 | Disallows the [`.is`](https://api.jquery.com/is/) method. Prefer `Element#matches`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).is(); 14 | $div.is(); 15 | $( 'div' ).first().is(); 16 | $( 'div' ).append( $( 'input' ).is() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | is(); 22 | [].is(); 23 | div.is(); 24 | div.is; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-is.js) 30 | * [Test source](/tests/rules/no-is.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-jquery-constructor.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-jquery-constructor 4 | 5 | Disallows the jQuery constructor `$()`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ); 14 | $( '#id' ); 15 | $( '.selector' ); 16 | $( '.selector', '.context' ); 17 | $( function () {} ); 18 | $( [] ); 19 | $( undefined ); 20 | $( false ); 21 | jQuery( 'div' ); 22 | ``` 23 | 24 | ✔️ Examples of **correct** code: 25 | ```js 26 | foo.$( '.selector' ); 27 | foo.$( '
' ); 28 | foo.jQuery( '.selector' ); 29 | foo.jQuery( '
' ); 30 | $; 31 | jQuery; 32 | ``` 33 | 34 | ## Resources 35 | 36 | * [Rule source](/src/rules/no-jquery-constructor.js) 37 | * [Test source](/tests/rules/no-jquery-constructor.js) 38 | -------------------------------------------------------------------------------- /docs/rules/no-live.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-live 4 | 5 | Disallows the [`.live`](https://api.jquery.com/live/)/[`.die`](https://api.jquery.com/die/) methods. Prefer `.on`/`.off` or `EventTarget#addEventListener`/`removeEventListener`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.7`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( 'div' ).live(); 16 | $div.live(); 17 | $( 'div' ).first().live(); 18 | $( 'div' ).append( $( 'input' ).live() ); 19 | $( 'div' ).die(); 20 | $div.die(); 21 | $( 'div' ).first().die(); 22 | $( 'div' ).append( $( 'input' ).die() ); 23 | ``` 24 | 25 | ✔️ Examples of **correct** code: 26 | ```js 27 | live(); 28 | [].live(); 29 | div.live(); 30 | div.live; 31 | die(); 32 | [].die(); 33 | div.die(); 34 | div.die; 35 | ``` 36 | 37 | ## Resources 38 | 39 | * [Rule source](/src/rules/no-live.js) 40 | * [Test source](/tests/rules/no-live.js) 41 | -------------------------------------------------------------------------------- /docs/rules/no-load.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-load 4 | 5 | Disallows the [`.load`](https://api.jquery.com/load/) method. Prefer `fetch`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/slim`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( 'div' ).load(); 16 | $div.load(); 17 | $( 'div' ).first().load(); 18 | $( 'div' ).append( $( 'input' ).load() ); 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | load(); 24 | [].load(); 25 | div.load(); 26 | div.load; 27 | $.load(); 28 | ``` 29 | 30 | ## Resources 31 | 32 | * [Rule source](/src/rules/no-load.js) 33 | * [Test source](/tests/rules/no-load.js) 34 | -------------------------------------------------------------------------------- /docs/rules/no-map-collection.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-map-collection 4 | 5 | Disallows the [`.map`](https://api.jquery.com/map/) method. Prefer `Array#map`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).map(); 14 | $div.map(); 15 | $( 'div' ).first().map(); 16 | $( 'div' ).append( $( 'input' ).map() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | map(); 22 | [].map(); 23 | div.map(); 24 | div.map; 25 | $.map(); 26 | $( 'select' ).val().map(); 27 | ``` 28 | 29 | ## Resources 30 | 31 | * [Rule source](/src/rules/no-map-collection.js) 32 | * [Test source](/tests/rules/no-map-collection.js) 33 | -------------------------------------------------------------------------------- /docs/rules/no-map-util.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-map-util 4 | 5 | Disallows the [`$.map`](https://api.jquery.com/jQuery.map/) utility. Prefer `Array#map`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.map(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | map(); 19 | [].map(); 20 | div.map(); 21 | div.map; 22 | $( 'div' ).map(); 23 | $div.map(); 24 | $( 'div' ).first().map(); 25 | $( 'div' ).append( $( 'input' ).map() ); 26 | $( 'select' ).val().map(); 27 | ``` 28 | 29 | ## Resources 30 | 31 | * [Rule source](/src/rules/no-map-util.js) 32 | * [Test source](/tests/rules/no-map-util.js) 33 | -------------------------------------------------------------------------------- /docs/rules/no-map.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-map 4 | 5 | Disallows the [`.map`](https://api.jquery.com/map/) method and [`$.map`](https://api.jquery.com/jQuery.map/) utility. Prefer `Array#map`. 6 | 7 | ## Rule details 8 | 9 | ❌ Examples of **incorrect** code: 10 | ```js 11 | $.map(); 12 | $( 'div' ).map(); 13 | $div.map(); 14 | $( 'div' ).first().map(); 15 | $( 'div' ).append( $( 'input' ).map() ); 16 | $( 'select' ).val( [] ).map(); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | map(); 22 | [].map(); 23 | div.map(); 24 | div.map; 25 | $( 'div' ).toArray().map(); 26 | $( 'select' ).val().map(); 27 | ``` 28 | 29 | ## Resources 30 | 31 | * [Rule source](/src/rules/no-map.js) 32 | * [Test source](/tests/rules/no-map.js) 33 | -------------------------------------------------------------------------------- /docs/rules/no-merge.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-merge 4 | 5 | Disallows the [`$.merge`](https://api.jquery.com/jQuery.merge/) utility. Prefer `Array#concat`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.merge(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | merge(); 19 | 'test'.merge(); 20 | 'test'.merge; 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-merge.js) 26 | * [Test source](/tests/rules/no-merge.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-node-name.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-node-name 4 | 5 | Disallows the [`$.nodeName`](https://api.jquery.com/jQuery.nodeName/) utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.2`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.nodeName(); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | nodeName(); 21 | myClass.nodeName(); 22 | $div.nodeName(); 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-node-name.js) 28 | * [Test source](/tests/rules/no-node-name.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-noop.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-noop 4 | 5 | Disallows the [`$.noop`](https://api.jquery.com/jQuery.noop/) property. Prefer `function(){}`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.noop; 16 | $.noop(); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | foo.noop; 22 | foo.noop(); 23 | foo.noop( bar ); 24 | $.noOp; 25 | ``` 26 | 27 | 🔧 Examples of code **fixed** by this rule: 28 | ```js 29 | $.noop; /* → */ ( function () {} ); 30 | $.noop(); /* → */ ( function () {}() ); 31 | ``` 32 | 33 | ## Resources 34 | 35 | * [Rule source](/src/rules/no-noop.js) 36 | * [Test source](/tests/rules/no-noop.js) 37 | -------------------------------------------------------------------------------- /docs/rules/no-now.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-now 4 | 5 | Disallows the [`$.now`](https://api.jquery.com/jQuery.now/) utility. Prefer `Date.now`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.3`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $.now(); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | now(); 23 | myClass.now(); 24 | $div.now(); 25 | ``` 26 | 27 | 🔧 Examples of code **fixed** by this rule: 28 | ```js 29 | $.now(); /* → */ Date.now(); 30 | ``` 31 | 32 | ## Resources 33 | 34 | * [Rule source](/src/rules/no-now.js) 35 | * [Test source](/tests/rules/no-now.js) 36 | -------------------------------------------------------------------------------- /docs/rules/no-on-ready.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-on-ready 4 | 5 | Disallows using the ready event on the document. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.8`. 8 | 9 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( document ).on( 'ready', function () {} ); 16 | $document.on( 'ready', function () {} ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | $( document ).on( 'click', function () {} ); 22 | $( document ).on(); 23 | $document.on( 'click', function () {} ); 24 | $document.on(); 25 | $document.on( ready ); 26 | $document.on( ready() ); 27 | $document.ready(); 28 | $( function () {} ); 29 | document.on( 'ready' ); 30 | document.on( 'ready', function () {} ); 31 | ``` 32 | 33 | 🔧 Examples of code **fixed** by this rule: 34 | ```js 35 | $( document ).on( 'ready', function () {} ); /* → */ $( document ).ready( function () {} ); 36 | $document.on( 'ready', function () {} ); /* → */ $document.ready( function () {} ); 37 | ``` 38 | 39 | ## Resources 40 | 41 | * [Rule source](/src/rules/no-on-ready.js) 42 | * [Test source](/tests/rules/no-on-ready.js) 43 | -------------------------------------------------------------------------------- /docs/rules/no-other-methods.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-other-methods 4 | 5 | Disallows all methods not covered by more specific rules. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $div.add(); 14 | $div.height(); 15 | $div.prepend(); 16 | $div.otherMethod(); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | $div.each(); 22 | $div.find(); 23 | $div.map(); 24 | $div.otherProperty; 25 | div.otherMethod(); 26 | $.otherUtil(); 27 | method(); 28 | ``` 29 | 30 | ## Resources 31 | 32 | * [Rule source](/src/rules/no-other-methods.js) 33 | * [Test source](/tests/rules/no-other-methods.js) 34 | -------------------------------------------------------------------------------- /docs/rules/no-other-utils.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-other-utils 4 | 5 | Disallows all utilities not covered by more specific rules. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.dequeue(); 14 | $.noConflict(); 15 | $.uniqueSort(); 16 | $.otherUtil(); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | $.each(); 22 | $.find(); 23 | $.map(); 24 | $.otherProperty; 25 | $div.otherMethod(); 26 | method(); 27 | ``` 28 | 29 | ## Resources 30 | 31 | * [Rule source](/src/rules/no-other-utils.js) 32 | * [Test source](/tests/rules/no-other-utils.js) 33 | -------------------------------------------------------------------------------- /docs/rules/no-param.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-param 4 | 5 | Disallows the [`$.param`](https://api.jquery.com/jQuery.param/) utility. Prefer `FormData` or `URLSearchParams`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.param(); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | param(); 19 | 'test'.param(); 20 | 'test'.param; 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-param.js) 26 | * [Test source](/tests/rules/no-param.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-parent.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-parent 4 | 5 | Disallows the [`.parent`](https://api.jquery.com/parent/) method. Prefer `Node#parentElement`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).parent(); 14 | $div.parent(); 15 | $( 'div' ).first().parent(); 16 | $( 'div' ).append( $( 'input' ).parent() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | parent(); 22 | [].parent(); 23 | div.parent(); 24 | div.parent; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-parent.js) 30 | * [Test source](/tests/rules/no-parent.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-parents.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-parents 4 | 5 | Disallows the [`.parents`](https://api.jquery.com/parents/) method. Prefer `Element#closest`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).parents(); 14 | $div.parents(); 15 | $( 'div' ).first().parents(); 16 | $( 'div' ).append( $( 'input' ).parents() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | parents(); 22 | [].parents(); 23 | div.parents(); 24 | div.parents; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-parents.js) 30 | * [Test source](/tests/rules/no-parents.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-parse-html.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-parse-html 4 | 5 | Disallows the [`$.parseHTML`](https://api.jquery.com/jQuery.parseHTML/) utility. Prefer `DOMImplementation#createHTMLDocument`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.parseHTML( 'test' ); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | parseHTML( 'test' ); 19 | 'test'.parseHTML( 'test' ); 20 | 'test'.parseHTML; 21 | ``` 22 | 23 | ## Resources 24 | 25 | * [Rule source](/src/rules/no-parse-html.js) 26 | * [Test source](/tests/rules/no-parse-html.js) 27 | -------------------------------------------------------------------------------- /docs/rules/no-parse-json.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-parse-json 4 | 5 | Disallows the [`$.parseJSON`](https://api.jquery.com/jQuery.parseJSON/) utility. Prefer `JSON.parse`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.0`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $.parseJSON( '{}' ); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | parseJSON(); 23 | $div.parseJSON(); 24 | 'test'.parseJSON; 25 | ``` 26 | 27 | 🔧 Examples of code **fixed** by this rule: 28 | ```js 29 | $.parseJSON( '{}' ); /* → */ JSON.parse( '{}' ); 30 | ``` 31 | 32 | ## Resources 33 | 34 | * [Rule source](/src/rules/no-parse-json.js) 35 | * [Test source](/tests/rules/no-parse-json.js) 36 | -------------------------------------------------------------------------------- /docs/rules/no-parse-xml.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-parse-xml 4 | 5 | Disallows the [`$.parseXML`](https://api.jquery.com/jQuery.parseXML/) utility. Prefer `DOMParser#parseFromString`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/slim`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $.parseXML( 'test' ); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | parseXML( 'test' ); 23 | 'test'.parseXML( 'test' ); 24 | 'test'.parseXML; 25 | ``` 26 | 27 | 🔧 Examples of code **fixed** by this rule: 28 | ```js 29 | $.parseXML( 'test' ); /* → */ ( new window.DOMParser() ).parseFromString( 'test', 'text/xml' ); 30 | ``` 31 | 32 | ## Resources 33 | 34 | * [Rule source](/src/rules/no-parse-xml.js) 35 | * [Test source](/tests/rules/no-parse-xml.js) 36 | -------------------------------------------------------------------------------- /docs/rules/no-prop.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-prop 4 | 5 | Disallows the [`.prop`](https://api.jquery.com/prop/)/[`.removeProp`](https://api.jquery.com/removeProp/) methods and `$.prop`/[`$.removeProp`](https://api.jquery.com/jQuery.removeProp/) utilies. Prefer direct property access. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.prop(); 14 | $( 'div' ).prop(); 15 | $div.prop(); 16 | $( 'div' ).first().prop(); 17 | $( 'div' ).append( $( 'input' ).prop() ); 18 | $( 'div' ).removeProp(); 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | prop(); 24 | [].prop(); 25 | div.prop(); 26 | div.prop; 27 | removeProp(); 28 | div.removeProp(); 29 | ``` 30 | 31 | ## Resources 32 | 33 | * [Rule source](/src/rules/no-prop.js) 34 | * [Test source](/tests/rules/no-prop.js) 35 | -------------------------------------------------------------------------------- /docs/rules/no-proxy.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-proxy 4 | 5 | Disallows the [`$.proxy`](https://api.jquery.com/jQuery.proxy/) utility. Prefer `Function#bind`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.3`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $.proxy( this.fn, context ); 18 | $.proxy( fn, context, arg1, arg2 ); 19 | $.proxy( context, 'fnName' ); 20 | $.proxy( context, 'fnName', arg1, arg2 ); 21 | ``` 22 | 23 | ✔️ Examples of **correct** code: 24 | ```js 25 | proxy( fn, context ); 26 | 'test'.proxy( fn, context ); 27 | 'test'.proxy; 28 | ``` 29 | 30 | 🔧 Examples of code **fixed** by this rule: 31 | ```js 32 | $.proxy( this.fn, context ); /* → */ this.fn.bind( context ); 33 | $.proxy( fn, context, arg1, arg2 ); /* → */ fn.bind( context, arg1, arg2 ); 34 | ``` 35 | 36 | ## Resources 37 | 38 | * [Rule source](/src/rules/no-proxy.js) 39 | * [Test source](/tests/rules/no-proxy.js) 40 | -------------------------------------------------------------------------------- /docs/rules/no-ready-shorthand.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-ready-shorthand 4 | 5 | Disallows the [`.ready`](https://api.jquery.com/ready/) method. Prefer `$()`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.0`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $( document ).ready( fn ); 18 | $div.ready( fn ); 19 | $( 'div' ).first().ready( fn ); 20 | $( 'div' ).append( $( 'input' ).ready( fn ) ); 21 | $div = $( 'div' ).ready( fn ); 22 | ``` 23 | 24 | ✔️ Examples of **correct** code: 25 | ```js 26 | ready( fn ); 27 | [].ready( fn ); 28 | div.ready( fn ); 29 | div.ready; 30 | $.ready( fn ); 31 | $( document ).on( 'ready', fn ); 32 | $( fn ); 33 | ``` 34 | 35 | 🔧 Examples of code **fixed** by this rule: 36 | ```js 37 | $( document ).ready( fn ); /* → */ $( fn ); 38 | $div.ready( fn ); /* → */ $( fn ); 39 | $( 'div' ).first().ready( fn ); /* → */ $( fn ); 40 | ``` 41 | 42 | ## Resources 43 | 44 | * [Rule source](/src/rules/no-ready-shorthand.js) 45 | * [Test source](/tests/rules/no-ready-shorthand.js) 46 | -------------------------------------------------------------------------------- /docs/rules/no-ready.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-ready 4 | 5 | Disallows the document ready event, either `$( function() {} )` or `$( document ).ready()`. 6 | 7 | ## Rule details 8 | 9 | ❌ Examples of **incorrect** code: 10 | ```js 11 | $( function () { } ); 12 | $( function init() { } ); 13 | $( () => {} ); 14 | $( document ).ready( function () { } ); 15 | $().ready( function () { } ); 16 | $( 'img' ).ready( function () { } ); 17 | $div.ready( function () { } ); 18 | $( 'img' ).first().ready( function () { } ); 19 | ``` 20 | 21 | ✔️ Examples of **correct** code: 22 | ```js 23 | ready( function () { } ); 24 | ready( () => {} ); 25 | ready(); 26 | [].ready(); 27 | div.ready(); 28 | div.ready; 29 | $.ready(); 30 | $( 'div' ); 31 | $( document ); 32 | $(); 33 | ``` 34 | 35 | ## Resources 36 | 37 | * [Rule source](/src/rules/no-ready.js) 38 | * [Test source](/tests/rules/no-ready.js) 39 | -------------------------------------------------------------------------------- /docs/rules/no-selector-prop.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-selector-prop 4 | 5 | Disallows the [`.selector`](https://api.jquery.com/selector/) property. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.7`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).selector; 14 | $div.selector; 15 | $div.selector.prop; 16 | $div.selector.method(); 17 | $( 'div' ).first().selector; 18 | f( $div.selector ); 19 | $( 'div' ).append( $( 'input' ).selector ); 20 | ``` 21 | 22 | ✔️ Examples of **correct** code: 23 | ```js 24 | selector; 25 | div.selector; 26 | $div.prop.selector; 27 | $div.selector(); 28 | $div.selector( arg ); 29 | ``` 30 | 31 | ## Resources 32 | 33 | * [Rule source](/src/rules/no-selector-prop.js) 34 | * [Test source](/tests/rules/no-selector-prop.js) 35 | -------------------------------------------------------------------------------- /docs/rules/no-serialize.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-serialize 4 | 5 | Disallows the [`.serialize`](https://api.jquery.com/serialize/)/[`.serializeArray`](https://api.jquery.com/serializeArray/) methods. Prefer `FormData` or `URLSearchParams`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).serialize(); 14 | $div.serialize(); 15 | $( 'div' ).first().serialize(); 16 | $( 'div' ).append( $( 'input' ).serialize() ); 17 | $( 'div' ).serializeArray(); 18 | $div.serializeArray(); 19 | $( 'div' ).first().serializeArray(); 20 | $( 'div' ).append( $( 'input' ).serializeArray() ); 21 | ``` 22 | 23 | ✔️ Examples of **correct** code: 24 | ```js 25 | serialize(); 26 | [].serialize(); 27 | div.serialize(); 28 | div.serialize; 29 | serializeArray(); 30 | [].serializeArray(); 31 | div.serializeArray(); 32 | div.serializeArray; 33 | ``` 34 | 35 | ## Resources 36 | 37 | * [Rule source](/src/rules/no-serialize.js) 38 | * [Test source](/tests/rules/no-serialize.js) 39 | -------------------------------------------------------------------------------- /docs/rules/no-show.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-show 4 | 5 | Disallows the [`.show`](https://api.jquery.com/show/) method. 6 | 7 | ⚠️ This rule is deprecated. Use [`no-visibility`](no-visibility.md) instead. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).show(); 14 | $div.show(); 15 | $( 'div' ).first().show(); 16 | $( 'div' ).append( $( 'input' ).show() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | show(); 22 | [].show(); 23 | div.show(); 24 | div.show; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-show.js) 30 | * [Test source](/tests/rules/no-show.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-size.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-size 4 | 5 | Disallows the [`.size`](https://api.jquery.com/size/) method. Prefer `.length`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.8`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $( 'div' ).size(); 18 | $div.size(); 19 | $( 'div' ).first().size(); 20 | $( 'div' ).append( $( 'input' ).size() ); 21 | ``` 22 | 23 | ✔️ Examples of **correct** code: 24 | ```js 25 | size(); 26 | [].size(); 27 | div.size(); 28 | div.size; 29 | ``` 30 | 31 | 🔧 Examples of code **fixed** by this rule: 32 | ```js 33 | $( 'div' ).size(); /* → */ $( 'div' ).length; 34 | $div.size(); /* → */ $div.length; 35 | $( 'div' ).first().size(); /* → */ $( 'div' ).first().length; 36 | $( 'div' ).append( $( 'input' ).size() ); /* → */ $( 'div' ).append( $( 'input' ).length ); 37 | ``` 38 | 39 | ## Resources 40 | 41 | * [Rule source](/src/rules/no-size.js) 42 | * [Test source](/tests/rules/no-size.js) 43 | -------------------------------------------------------------------------------- /docs/rules/no-slide.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-slide 4 | 5 | Disallows the [`.slideDown`](https://api.jquery.com/slideDown/)/[`.slideToggle`](https://api.jquery.com/slideToggle/)/[`.slideUp`](https://api.jquery.com/slideUp/) methods. Prefer CSS transitions. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/slim`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $( 'div' ).slideDown(); 16 | $div.slideDown(); 17 | $( 'div' ).first().slideDown(); 18 | $( 'div' ).append( $( 'input' ).slideDown() ); 19 | $( 'div' ).slideToggle(); 20 | $div.slideToggle(); 21 | $( 'div' ).first().slideToggle(); 22 | $( 'div' ).append( $( 'input' ).slideToggle() ); 23 | $( 'div' ).slideUp(); 24 | $div.slideUp(); 25 | $( 'div' ).first().slideUp(); 26 | $( 'div' ).append( $( 'input' ).slideUp() ); 27 | ``` 28 | 29 | ✔️ Examples of **correct** code: 30 | ```js 31 | slideDown(); 32 | [].slideDown(); 33 | div.slideDown(); 34 | div.slideDown; 35 | slideToggle(); 36 | [].slideToggle(); 37 | div.slideToggle(); 38 | div.slideToggle; 39 | slideUp(); 40 | [].slideUp(); 41 | div.slideUp(); 42 | div.slideUp; 43 | ``` 44 | 45 | ## Resources 46 | 47 | * [Rule source](/src/rules/no-slide.js) 48 | * [Test source](/tests/rules/no-slide.js) 49 | -------------------------------------------------------------------------------- /docs/rules/no-sub.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-sub 4 | 5 | Disallows the [`$.sub`](https://api.jquery.com/jQuery.sub/) utility. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.7`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.sub(); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | sub(); 21 | 'test'.sub(); 22 | 'test'.sub; 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-sub.js) 28 | * [Test source](/tests/rules/no-sub.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-submit.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-submit 4 | 5 | Disallows the [`.submit`](https://api.jquery.com/submit/) method. Prefer `EventTarget#dispatchEvent` + `HTMLFormElement#submit`. 6 | 7 | ⚠️ This rule is deprecated. Use [`no-event-shorthand`](no-event-shorthand.md) instead. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'form' ).submit(); 14 | $form.submit(); 15 | $( 'form' ).first().submit(); 16 | $( 'form' ).append( $( 'input' ).submit() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | submit(); 22 | [].submit(); 23 | form.submit(); 24 | form.submit; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-submit.js) 30 | * [Test source](/tests/rules/no-submit.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-support.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-support 4 | 5 | Disallows the [`$.support`](https://api.jquery.com/jQuery.support/) property. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-1.9`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.support; 14 | $.support.style; 15 | ``` 16 | 17 | ✔️ Examples of **correct** code: 18 | ```js 19 | support; 20 | a.support; 21 | support.foo; 22 | a.support.foo; 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-support.js) 28 | * [Test source](/tests/rules/no-support.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-text.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-text 4 | 5 | Disallows the [`.text`](https://api.jquery.com/text/) method and `$.text` utility. Prefer `Node#textContent`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.text(); 14 | $( 'div' ).text(); 15 | $div.text(); 16 | $( 'div' ).first().text(); 17 | $( 'div' ).append( $( 'input' ).text() ); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | text(); 23 | [].text(); 24 | div.text(); 25 | div.text; 26 | ``` 27 | 28 | ## Resources 29 | 30 | * [Rule source](/src/rules/no-text.js) 31 | * [Test source](/tests/rules/no-text.js) 32 | -------------------------------------------------------------------------------- /docs/rules/no-toggle.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-toggle 4 | 5 | Disallows the [`.toggle`](https://api.jquery.com/toggle/) method. 6 | 7 | ⚠️ This rule is deprecated. Use [`no-visibility`](no-visibility.md) instead. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).toggle(); 14 | $div.toggle(); 15 | $( 'div' ).first().toggle(); 16 | $( 'div' ).append( $( 'input' ).toggle() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | toggle(); 22 | [].toggle(); 23 | div.toggle(); 24 | div.toggle; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-toggle.js) 30 | * [Test source](/tests/rules/no-toggle.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-trigger.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-trigger 4 | 5 | Disallows the [`.trigger`](https://api.jquery.com/trigger/) method. Prefer `EventTarget#dispatchEvent`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).trigger(); 14 | $div.trigger(); 15 | $( 'div' ).first().trigger(); 16 | $( 'div' ).append( $( 'input' ).trigger() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | trigger(); 22 | [].trigger(); 23 | div.trigger(); 24 | div.trigger; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-trigger.js) 30 | * [Test source](/tests/rules/no-trigger.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-trim.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-trim 4 | 5 | Disallows the [`$.trim`](https://api.jquery.com/jQuery.trim/) utility. Prefer `String#trim`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.5`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.trim( ' test ' ); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | trim( ' test ' ); 21 | ' test '.trim(); 22 | ' test '.trim; 23 | $( 'input' ).text().trim(); 24 | $( 'input' ).data( 'foo' ).trim(); 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-trim.js) 30 | * [Test source](/tests/rules/no-trim.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-type.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-type 4 | 5 | Disallows the [`$.type`](https://api.jquery.com/jQuery.type/) utility. Prefer `typeof`/`instanceof`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.3`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | ## Rule details 12 | 13 | ❌ Examples of **incorrect** code: 14 | ```js 15 | $.type(); 16 | ``` 17 | 18 | ✔️ Examples of **correct** code: 19 | ```js 20 | type(); 21 | myMethod.type(); 22 | myMethod.type; 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-type.js) 28 | * [Test source](/tests/rules/no-type.js) 29 | -------------------------------------------------------------------------------- /docs/rules/no-unbind.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-unbind 4 | 5 | Disallows the [`.unbind`](https://api.jquery.com/unbind/) method. Prefer `.off`/`EventTarget#removeEventListener`. 6 | 7 | ⚠️ This rule is deprecated. Use [`no-bind`](no-bind.md) instead. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).unbind(); 14 | $div.unbind(); 15 | $( 'div' ).first().unbind(); 16 | $( 'div' ).append( $( 'input' ).unbind() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | unbind(); 22 | [].unbind(); 23 | div.unbind(); 24 | div.unbind; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-unbind.js) 30 | * [Test source](/tests/rules/no-unbind.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-undelegate.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-undelegate 4 | 5 | Disallows the [`.undelegate`](https://api.jquery.com/undelegate/) method. Prefer `.off`/`EventTarget#removeEventListener`. 6 | 7 | ⚠️ This rule is deprecated. Use [`no-delegate`](no-delegate.md) instead. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).undelegate(); 14 | $div.undelegate(); 15 | $( 'div' ).first().undelegate(); 16 | $( 'div' ).append( $( 'input' ).undelegate() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | undelegate(); 22 | [].undelegate(); 23 | div.undelegate(); 24 | div.undelegate; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-undelegate.js) 30 | * [Test source](/tests/rules/no-undelegate.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-unique.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-unique 4 | 5 | Disallows the [`$.unique`](https://api.jquery.com/jQuery.unique/) utility. Prefer `$.uniqueSort`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/deprecated-3.0`. 8 | 9 | 📋 This rule is enabled in `plugin:no-jquery/all`. 10 | 11 | 🔧 The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. 12 | 13 | ## Rule details 14 | 15 | ❌ Examples of **incorrect** code: 16 | ```js 17 | $.unique( [] ); 18 | ``` 19 | 20 | ✔️ Examples of **correct** code: 21 | ```js 22 | unique(); 23 | 'test'.unique(); 24 | 'test'.unique; 25 | ``` 26 | 27 | 🔧 Examples of code **fixed** by this rule: 28 | ```js 29 | $.unique( [] ); /* → */ $.uniqueSort( [] ); 30 | ``` 31 | 32 | ## Resources 33 | 34 | * [Rule source](/src/rules/no-unique.js) 35 | * [Test source](/tests/rules/no-unique.js) 36 | -------------------------------------------------------------------------------- /docs/rules/no-val.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-val 4 | 5 | Disallows the [`.val`](https://api.jquery.com/val/) method. Prefer `HTMLInputElement#value`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).val(); 14 | $div.val(); 15 | $( 'div' ).first().val(); 16 | $( 'div' ).append( $( 'input' ).val() ); 17 | ``` 18 | 19 | ✔️ Examples of **correct** code: 20 | ```js 21 | val(); 22 | [].val(); 23 | div.val(); 24 | div.val; 25 | ``` 26 | 27 | ## Resources 28 | 29 | * [Rule source](/src/rules/no-val.js) 30 | * [Test source](/tests/rules/no-val.js) 31 | -------------------------------------------------------------------------------- /docs/rules/no-visibility.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-visibility 4 | 5 | Disallows the [`.show`](https://api.jquery.com/show/)/[`.hide`](https://api.jquery.com/hide/)/[`.toggle`](https://api.jquery.com/toggle/) methods. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $( 'div' ).show(); 14 | $div.show(); 15 | $( 'div' ).first().show(); 16 | $( 'div' ).append( $( 'input' ).show() ); 17 | $( 'div' ).hide(); 18 | $div.hide(); 19 | $( 'div' ).first().hide(); 20 | $( 'div' ).append( $( 'input' ).hide() ); 21 | $( 'div' ).toggle(); 22 | $div.toggle(); 23 | $( 'div' ).first().toggle(); 24 | $( 'div' ).append( $( 'input' ).toggle() ); 25 | ``` 26 | 27 | ✔️ Examples of **correct** code: 28 | ```js 29 | show(); 30 | [].show(); 31 | div.show(); 32 | div.show; 33 | hide(); 34 | [].hide(); 35 | div.hide(); 36 | div.hide; 37 | toggle(); 38 | [].toggle(); 39 | div.toggle(); 40 | div.toggle; 41 | ``` 42 | 43 | ## Resources 44 | 45 | * [Rule source](/src/rules/no-visibility.js) 46 | * [Test source](/tests/rules/no-visibility.js) 47 | -------------------------------------------------------------------------------- /docs/rules/no-when.md: -------------------------------------------------------------------------------- 1 | [//]: # (This file is generated by eslint-docgen. Do not edit it directly.) 2 | 3 | # no-when 4 | 5 | Disallows the [`$.when`](https://api.jquery.com/jQuery.when/) utility. Prefer `Promise.all`. 6 | 7 | 📋 This rule is enabled in `plugin:no-jquery/all`. 8 | 9 | ## Rule details 10 | 11 | ❌ Examples of **incorrect** code: 12 | ```js 13 | $.when( a, b ); 14 | ``` 15 | 16 | ✔️ Examples of **correct** code: 17 | ```js 18 | When(); 19 | new When(); 20 | 'test'.when(); 21 | 'test'.when; 22 | $when(); 23 | ``` 24 | 25 | ## Resources 26 | 27 | * [Rule source](/src/rules/no-when.js) 28 | * [Test source](/tests/rules/no-when.js) 29 | -------------------------------------------------------------------------------- /src/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "overrides": [ 3 | { 4 | // Rules applying to index.js are used to autofix documentation 5 | "files": [ 6 | "index.js" 7 | ], 8 | "rules": { 9 | // Allow non-arrow functions in examples 10 | "prefer-arrow-callback": "off", 11 | // Allow compact single line functions 12 | "max-statements-per-line": "off", 13 | "brace-style": "off" 14 | } 15 | } 16 | ] 17 | }; 18 | -------------------------------------------------------------------------------- /src/rules/no-ajax-events.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | const disallowedEvents = [ 6 | 'ajaxComplete', 7 | 'ajaxError', 8 | 'ajaxSend', 9 | 'ajaxStart', 10 | 'ajaxStop', 11 | 'ajaxSuccess' 12 | ]; 13 | 14 | module.exports = { 15 | meta: { 16 | type: 'suggestion', 17 | docs: { 18 | description: 'Disallows global ajax events handlers: ' + disallowedEvents.map( utils.jQueryCollectionLink ).join( '/' ) + '. Prefer local events.' 19 | }, 20 | schema: [] 21 | }, 22 | 23 | create: ( context ) => ( { 24 | 'CallExpression:exit': ( node ) => { 25 | if ( node.callee.type !== 'MemberExpression' ) { 26 | return; 27 | } 28 | let usedMethod; 29 | if ( 30 | node.callee.property.name === 'on' && 31 | node.arguments.length >= 1 32 | ) { 33 | const arg = node.arguments[ 0 ]; 34 | if ( 35 | arg.type === 'Literal' && 36 | disallowedEvents.includes( arg.value ) 37 | ) { 38 | usedMethod = arg.value; 39 | } 40 | } 41 | if ( disallowedEvents.includes( node.callee.property.name ) ) { 42 | usedMethod = node.callee.property.name; 43 | } 44 | if ( usedMethod && utils.isjQuery( context, node ) ) { 45 | context.report( { 46 | node, 47 | message: 'Prefer local event to {{method}}', 48 | data: { method: usedMethod } 49 | } ); 50 | } 51 | } 52 | } ) 53 | }; 54 | -------------------------------------------------------------------------------- /src/rules/no-ajax.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | [ 'ajax', 'get', 'getJSON', 'getScript', 'post' ], 7 | ( node ) => node === true ? 8 | 'Prefer `Window.fetch`' : 9 | `Prefer Window.fetch to $.${ node.callee.property.name }` 10 | ); 11 | -------------------------------------------------------------------------------- /src/rules/no-and-self.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'andSelf', 7 | 'Prefer `.addBack` to `.andSelf`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node.callee.property, 'addBack' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-attr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | [ 'attr', 'removeAttr' ], 7 | ( node ) => node === true ? 8 | 'Prefer `Element#getAttribute`/`setAttribute`/`removeAttribute`' : 9 | 'Prefer Element#' + 10 | ( 11 | node.callee.property.name === 'removeAttr' ? 'removeAttribute' : 12 | node.arguments.length === 2 ? 'setAttribute' : 'getAttribute' 13 | ) + 14 | ' to .' + node.callee.property.name + '/$.' + node.callee.property.name 15 | ); 16 | -------------------------------------------------------------------------------- /src/rules/no-bind.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'bind', 'unbind' ], 7 | ( node ) => node === true ? 8 | 'Prefer `.on`/`.off` or `EventTarget#addEventListener`/`removeEventListener`' : ( 9 | node.callee.property.name === 'bind' ? 10 | 'Prefer .on/EventTarget#addEventListener to .bind' : 11 | 'Prefer .off/EventTarget#removeEventListener to .unbind' 12 | ) 13 | ); 14 | -------------------------------------------------------------------------------- /src/rules/no-box-model.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilPropertyRule( 'boxModel' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-browser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilPropertyRule( 'browser' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-camel-case.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'camelCase' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-class-state.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows ' + utils.jQueryCollectionLink( 'hasClass' ) + 10 | ' and ' + utils.jQueryCollectionLink( 'toggleClass' ) + 11 | ' to discourage querying the DOM for state information. ' + 12 | utils.jQueryCollectionLink( 'toggleClass' ) + ' may be used with a boolean argument as then it behaves like ' + 13 | utils.jQueryCollectionLink( 'addClass' ) + '/' + utils.jQueryCollectionLink( 'removeClass' ) + '.' 14 | }, 15 | schema: [] 16 | }, 17 | 18 | create: ( context ) => ( { 19 | 'CallExpression:exit': ( node ) => { 20 | if ( !( 21 | node.callee.type === 'MemberExpression' && ( 22 | node.callee.property.name === 'hasClass' || 23 | // toggleClass with one argument will check if the 24 | // class is already in the DOM before deciding what to do, 25 | // so it is equivalent to using hasClass. 26 | ( 27 | node.callee.property.name === 'toggleClass' && 28 | node.arguments.length === 1 29 | ) 30 | ) 31 | ) ) { 32 | return; 33 | } 34 | 35 | if ( utils.isjQuery( context, node.callee ) ) { 36 | context.report( { 37 | node, 38 | message: 'Where possible, maintain application state in JS to avoid slower DOM queries' 39 | } ); 40 | } 41 | } 42 | } ) 43 | }; 44 | -------------------------------------------------------------------------------- /src/rules/no-class.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'addClass', 'hasClass', 'removeClass', 'toggleClass' ], 7 | ( node ) => node === true ? 8 | 'Prefer `Element#classList`' : 9 | `Prefer Element#classList to .${ node.callee.property.name }` 10 | ); 11 | -------------------------------------------------------------------------------- /src/rules/no-clone.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | 'clone', 7 | 'Prefer `Node#cloneNode` to `.clone`/`$.clone`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-closest.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'closest', 7 | 'Prefer `Element#closest` to `.closest`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-constructor-attributes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows passing attributes to the jQuery constructor. Prefer `.attr`.' 10 | }, 11 | schema: [] 12 | }, 13 | 14 | create: ( context ) => ( { 15 | 'CallExpression:exit': ( node ) => { 16 | if ( node.callee.type === 'MemberExpression' ) { 17 | if ( !( 18 | node.callee.property.name === 'add' && 19 | utils.isjQuery( context, node.callee ) && 20 | node.arguments[ 1 ] && 21 | node.arguments[ 1 ].type === 'ObjectExpression' 22 | ) ) { 23 | return; 24 | } 25 | } else if ( node.callee.type === 'Identifier' ) { 26 | if ( !( 27 | utils.isjQueryConstructor( context, node.callee.name ) && 28 | node.arguments[ 1 ] && 29 | node.arguments[ 1 ].type === 'ObjectExpression' 30 | ) ) { 31 | return; 32 | } 33 | } else { 34 | return; 35 | } 36 | 37 | context.report( { 38 | node, 39 | message: 'Prefer .attr to constructor attributes' 40 | } ); 41 | } 42 | } ) 43 | }; 44 | -------------------------------------------------------------------------------- /src/rules/no-contains.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'contains', 7 | 'Prefer `Node#contains` to `$.contains`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-context-prop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionPropertyRule( 'context' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-css.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | 'css', 7 | 'Prefer `Window#getComputedStyle` to `.css`/`$.css`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-data.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | [ 'data', 'removeData', 'hasData' ], 7 | ( node ) => node === true ? 8 | 'Prefer `WeakMap`' : 9 | `Prefer WeakMap to .${ node.callee.property.name }/$.${ node.callee.property.name }` 10 | ); 11 | -------------------------------------------------------------------------------- /src/rules/no-deferred.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows ' + utils.jQueryGlobalLink( 'Deferred' ) + ' constructor. Prefer `Promise`.' 10 | }, 11 | schema: [] 12 | }, 13 | 14 | create: ( context ) => { 15 | function enforce( node ) { 16 | if ( 17 | node.callee.type !== 'MemberExpression' || 18 | !utils.isjQueryConstructor( context, node.callee.object.name ) || 19 | node.callee.property.name !== 'Deferred' 20 | ) { 21 | return; 22 | } 23 | 24 | context.report( { 25 | node, 26 | message: 'Prefer Promise to $.Deferred' 27 | } ); 28 | } 29 | 30 | return { 31 | 'CallExpression:exit': enforce, 32 | NewExpression: enforce 33 | }; 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /src/rules/no-delegate.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'delegate', 'undelegate' ], 7 | ( node ) => node === true ? 8 | 'Prefer `.on`/`.off` or `EventTarget#addEventListener`/`removeEventListener`' : ( 9 | node.callee.property.name === 'delegate' ? 10 | 'Prefer .on/EventTarget#addEventListener to .delegate' : 11 | 'Prefer .off/EventTarget#removeEventListener to .undelegate' 12 | ) 13 | ); 14 | -------------------------------------------------------------------------------- /src/rules/no-die.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'die', 7 | 'Prefer `.off`/`EventTarget#removeEventListener` to `.die`', 8 | { deprecated: [ 'no-live' ] } 9 | ); 10 | -------------------------------------------------------------------------------- /src/rules/no-done-fail.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUniversalMethodRule( 6 | [ 'done', 'fail' ], 7 | ( node ) => node === true ? 8 | 'Prefer `.then`' : 9 | `Prefer .then to .${ node.callee.property.name }`, 10 | ( method ) => `[\`.${ method }\`](https://api.jquery.com/deferred.${ method }/)` 11 | ); 12 | -------------------------------------------------------------------------------- /src/rules/no-each-collection.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'each', 7 | 'Prefer `Array#forEach` to `.each`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-each-util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'each', 7 | 'Prefer `Array#forEach` to `$.each`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-each.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | 'each', 7 | 'Prefer `Array#forEach` to `.each`/`$.each`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-error-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'error', 7 | 'Prefer `.on` or `.trigger` to `.error`', 8 | { 9 | fixable: 'code', 10 | fix: utils.eventShorthandFixer 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-error.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'error', 7 | 'Prefer `throw` to `$.error`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'throw new Error' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-escape-selector.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'escapeSelector', 7 | 'Prefer `CSS.escape` to `$.escapeSelector`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'CSS.escape' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-fade.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'fadeIn', 'fadeOut', 'fadeTo', 'fadeToggle' ], 7 | ( node ) => node === true ? 8 | 'Prefer CSS transitions' : 9 | `Prefer CSS transitions to .${ node.callee.property.name }` 10 | ); 11 | -------------------------------------------------------------------------------- /src/rules/no-filter.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | 'filter', 7 | 'Prefer `Array#filter` to `.filter`/`$.filter`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-find-collection.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'find', 7 | 'Prefer `Document#querySelectorAll` to `.find`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-find-util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'find', 7 | 'Prefer `Document#querySelectorAll` to `$.find`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-find.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | 'find', 7 | 'Prefer `Document#querySelectorAll` to `.find`/`$.find`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-fx-interval.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows ' + utils.jQueryGlobalLink( 'fx.interval' ) + '.' 10 | }, 11 | schema: [] 12 | }, 13 | 14 | create: ( context ) => ( { 15 | MemberExpression: ( node ) => { 16 | if ( 17 | !utils.isjQueryConstructor( context, node.object.name ) || 18 | node.property.name !== 'fx' || 19 | !node.parent.property || 20 | node.parent.property.name !== 'interval' 21 | ) { 22 | return; 23 | } 24 | 25 | context.report( { 26 | node, 27 | message: '$.fx.interval is not allowed' 28 | } ); 29 | } 30 | } ) 31 | }; 32 | -------------------------------------------------------------------------------- /src/rules/no-fx.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows `$.fx`.' 10 | }, 11 | schema: [] 12 | }, 13 | 14 | create: ( context ) => ( { 15 | MemberExpression: ( node ) => { 16 | if ( 17 | !utils.isjQueryConstructor( context, node.object.name ) || 18 | node.property.name !== 'fx' 19 | ) { 20 | return; 21 | } 22 | 23 | context.report( { 24 | node, 25 | message: '$.fx is not allowed' 26 | } ); 27 | } 28 | } ) 29 | }; 30 | -------------------------------------------------------------------------------- /src/rules/no-global-eval.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'globalEval' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-grep.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'grep', 7 | 'Prefer `Array#filter` to `$.grep`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-has.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 'has' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-hide.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 'hide', '', { deprecated: [ 'no-visibility' ] } ); 6 | -------------------------------------------------------------------------------- /src/rules/no-hold-ready.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'holdReady' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-html.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'html', 7 | 'Prefer `Element#innerHTML` to `.html`', 8 | { getAndSetOptions: true } 9 | ); 10 | -------------------------------------------------------------------------------- /src/rules/no-in-array.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'inArray', 7 | 'Prefer `Array#indexOf` to `$.inArray`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-is-array.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'isArray', 7 | 'Prefer `Array.isArray` to `$.isArray`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'Array.isArray' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-is-empty-object.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'isEmptyObject' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-is-function.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'isFunction', 7 | 'Prefer `typeof` to `$.isFunction`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => { 11 | const calleeRange = node.callee.range; 12 | return [ 13 | fixer.replaceTextRange( [ calleeRange[ 0 ], calleeRange[ 1 ] + 1 ], 'typeof ' ), 14 | fixer.replaceTextRange( [ node.range[ 1 ] - 1, node.range[ 1 ] ], ' === "function"' ) 15 | ]; 16 | } 17 | } 18 | ); 19 | -------------------------------------------------------------------------------- /src/rules/no-is-numeric.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'isNumeric', 7 | 'Prefer `typeof` to `$.isNumeric`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-is-plain-object.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'isPlainObject' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-is-window.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'isWindow' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-is.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'is', 7 | 'Prefer `Element#matches` to `.is`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-jquery-constructor.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows the jQuery constructor `$()`.' 10 | }, 11 | schema: [] 12 | }, 13 | 14 | create: ( context ) => ( { 15 | 'CallExpression:exit': ( node ) => { 16 | if ( 17 | node.callee.type !== 'Identifier' || 18 | !utils.isjQueryConstructor( context, node.callee.name ) 19 | ) { 20 | return; 21 | } 22 | 23 | context.report( { 24 | node, 25 | message: 'The jQuery constructor is not allowed' 26 | } ); 27 | } 28 | } ) 29 | }; 30 | -------------------------------------------------------------------------------- /src/rules/no-live.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'live', 'die' ], 7 | ( node ) => node === true ? 8 | 'Prefer `.on`/`.off` or `EventTarget#addEventListener`/`removeEventListener`' : ( 9 | node.callee.property.name === 'live' ? 10 | 'Prefer .on/EventTarget#addEventListener to .live' : 11 | 'Prefer .off/EventTarget#removeEventListener to .die' 12 | ) 13 | ); 14 | -------------------------------------------------------------------------------- /src/rules/no-load-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows the [`.load`](https://api.jquery.com/load-event/) method when used as a shorthand for `.on( \'load\', function )` or `.trigger( \'load\' )`. Prefer `.on` or `.trigger`.' 10 | }, 11 | fixable: 'code', 12 | schema: [] 13 | }, 14 | 15 | create: ( context ) => ( { 16 | 'CallExpression:exit': ( node ) => { 17 | if ( !( 18 | node.callee.type === 'MemberExpression' && 19 | !utils.isjQueryConstructor( context, node.callee.object.name ) && 20 | node.callee.property.name === 'load' && ( 21 | node.arguments.length === 0 || 22 | utils.isFunction( node.arguments[ 0 ] ) 23 | ) 24 | ) ) { 25 | return; 26 | } 27 | 28 | if ( utils.isjQuery( context, node.callee ) ) { 29 | context.report( { 30 | node, 31 | message: 'Prefer .on or .trigger to .load', 32 | fix: utils.eventShorthandFixer.bind( this, node, context ) 33 | } ); 34 | } 35 | } 36 | } ) 37 | }; 38 | -------------------------------------------------------------------------------- /src/rules/no-load.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'load', 7 | 'Prefer `fetch` to `.load`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-map-collection.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'map', 7 | 'Prefer `Array#map` to `.map`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-map-util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'map', 'Prefer `Array#map` to `$.map`' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-map.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | 'map', 7 | 'Prefer `Array#map` to `.map`/`$.map`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-merge.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'merge', 7 | 'Prefer `Array#concat` to `$.merge`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-node-name.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'nodeName' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-noop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilPropertyRule( 6 | 'noop', 7 | 'Prefer `function(){}` to `$.noop`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node, '(function(){})' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-now.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'now', 7 | 'Prefer `Date.now` to `$.now`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'Date.now' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-on-ready.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows using the ready event on the document.' 10 | }, 11 | fixable: 'code', 12 | schema: [] 13 | }, 14 | 15 | create: ( context ) => ( { 16 | 'CallExpression:exit': ( node ) => { 17 | if ( 18 | node.callee.type !== 'MemberExpression' || 19 | node.callee.property.name !== 'on' 20 | ) { 21 | return; 22 | } 23 | const arg = node.arguments[ 0 ]; 24 | if ( !arg || arg.value !== 'ready' ) { 25 | return; 26 | } 27 | 28 | if ( utils.isjQuery( context, node.callee ) ) { 29 | context.report( { 30 | node, 31 | message: '.on("ready") is not allowed', 32 | fix: ( fixer ) => ( node.arguments.length > 1 ) ? 33 | [ 34 | fixer.replaceText( node.callee.property, 'ready' ), 35 | fixer.replaceTextRange( 36 | [ 37 | node.arguments[ 0 ].range[ 0 ], 38 | node.arguments[ 1 ].range[ 0 ] 39 | ], 40 | '' 41 | ) 42 | ] : null 43 | } ); 44 | } 45 | } 46 | } ) 47 | }; 48 | -------------------------------------------------------------------------------- /src/rules/no-param.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'param', 7 | 'Prefer `FormData` or `URLSearchParams` to `$.param`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-parent.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'parent', 7 | 'Prefer `Node#parentElement` to `.parent`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-parents.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'parents', 7 | 'Prefer `Element#closest` to `.parents`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-parse-html.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'parseHTML', 7 | 'Prefer `DOMImplementation#createHTMLDocument` to `$.parseHTML`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-parse-json.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'parseJSON', 7 | 'Prefer `JSON.parse` to `$.parseJSON`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'JSON.parse' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-parse-xml.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'parseXML', 7 | 'Prefer `DOMParser#parseFromString` to `$.parseXML`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => { 11 | if ( node.arguments.length ) { 12 | return [ 13 | fixer.replaceText( node.callee, '( new window.DOMParser() ).parseFromString' ), 14 | fixer.insertTextAfterRange( node.arguments[ 0 ].range, ', "text/xml"' ) 15 | ]; 16 | } 17 | } 18 | } 19 | ); 20 | -------------------------------------------------------------------------------- /src/rules/no-prop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | [ 'prop', 'removeProp' ], 7 | ( node ) => node === true ? 8 | 'Prefer direct property access' : 9 | `Prefer direct property access to .${ node.callee.property.name }/$.${ node.callee.property.name }` 10 | ); 11 | -------------------------------------------------------------------------------- /src/rules/no-proxy.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'proxy', 7 | 'Prefer `Function#bind` to `$.proxy`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => { 11 | if ( 12 | node.arguments.length >= 2 && 13 | node.arguments[ 1 ].type !== 'Literal' 14 | ) { 15 | const fnText = context.getSourceCode().getText( node.arguments[ 0 ] ); 16 | return [ 17 | fixer.replaceText( node.callee, fnText + '.bind' ), 18 | fixer.removeRange( [ 19 | node.arguments[ 0 ].range[ 0 ], 20 | node.arguments[ 1 ].range[ 0 ] 21 | ] ) 22 | ]; 23 | } 24 | } 25 | } 26 | ); 27 | -------------------------------------------------------------------------------- /src/rules/no-ready-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'ready', 7 | 'Prefer `$()` to `.ready`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => { 11 | if ( node.parent.type === 'ExpressionStatement' ) { 12 | return fixer.replaceText( node.callee, '$' ); 13 | } 14 | } 15 | } 16 | ); 17 | -------------------------------------------------------------------------------- /src/rules/no-ready.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | // $(function(){}) 6 | function isDirect( context, node ) { 7 | return ( 8 | node.callee.type === 'Identifier' && 9 | utils.isjQueryConstructor( context, node.callee.name ) && 10 | node.arguments[ 0 ] && 11 | utils.isFunction( node.arguments[ 0 ] ) 12 | ); 13 | } 14 | 15 | // $(document).ready() 16 | function isChained( context, node ) { 17 | return ( 18 | node.callee.type === 'MemberExpression' && 19 | node.callee.property.name === 'ready' && 20 | utils.isjQuery( context, node ) 21 | ); 22 | } 23 | 24 | module.exports = { 25 | meta: { 26 | type: 'suggestion', 27 | docs: { 28 | description: 'Disallows the document ready event, either `$( function() {} )` or `$( document ).ready()`.' 29 | }, 30 | schema: [] 31 | }, 32 | 33 | create: ( context ) => ( { 34 | 'CallExpression:exit': ( node ) => { 35 | if ( isDirect( context, node ) || isChained( context, node ) ) { 36 | context.report( { 37 | node, 38 | message: '.ready is not allowed' 39 | } ); 40 | } 41 | } 42 | } ) 43 | }; 44 | -------------------------------------------------------------------------------- /src/rules/no-selector-prop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionPropertyRule( 'selector' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-serialize.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'serialize', 'serializeArray' ], 7 | ( node ) => node === true ? 8 | 'Prefer `FormData` or `URLSearchParams`' : 9 | `Prefer FormData or URLSearchParams to .${ node.callee.property.name }` 10 | ); 11 | -------------------------------------------------------------------------------- /src/rules/no-show.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 'show', '', { deprecated: [ 'no-visibility' ] } ); 6 | -------------------------------------------------------------------------------- /src/rules/no-size.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'size', 7 | 'Prefer `.length` to `.size`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceTextRange( [ node.callee.property.range[ 0 ], node.range[ 1 ] ], 'length' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-slide.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'slideDown', 'slideToggle', 'slideUp' ], 7 | ( node ) => node === true ? 8 | 'Prefer CSS transitions' : 9 | `Prefer CSS transitions to .${ node.callee.property.name }` 10 | ); 11 | -------------------------------------------------------------------------------- /src/rules/no-sub.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 'sub' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-submit.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'submit', 7 | 'Prefer `EventTarget#dispatchEvent` + `HTMLFormElement#submit` to `.submit`', 8 | { deprecated: [ 'no-event-shorthand' ] } 9 | ); 10 | -------------------------------------------------------------------------------- /src/rules/no-support.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilPropertyRule( 'support' ); 6 | -------------------------------------------------------------------------------- /src/rules/no-text.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionOrUtilMethodRule( 6 | 'text', 7 | 'Prefer `Node#textContent` to `.text`/`$.text`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-toggle.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 'toggle', '', { deprecated: [ 'no-visibility' ] } ); 6 | -------------------------------------------------------------------------------- /src/rules/no-trigger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'trigger', 7 | 'Prefer `EventTarget#dispatchEvent` to `.trigger`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-trim.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'trim', 7 | 'Prefer `String#trim` to `$.trim`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-type.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'type', 7 | 'Prefer `typeof`/`instanceof` to `$.type`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-unbind.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'unbind', 7 | 'Prefer `.off`/`EventTarget#removeEventListener` to `.unbind`', 8 | { deprecated: [ 'no-bind' ] } 9 | ); 10 | -------------------------------------------------------------------------------- /src/rules/no-undelegate.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'undelegate', 7 | 'Prefer `.off`/`EventTarget#removeEventListener` to `.undelegate`', 8 | { deprecated: [ 'no-delegate' ] } 9 | ); 10 | -------------------------------------------------------------------------------- /src/rules/no-unique.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'unique', 7 | 'Prefer `$.uniqueSort` to `$.unique`', 8 | { 9 | fixable: 'code', 10 | fix: ( node, context, fixer ) => fixer.replaceText( node.callee.property, 'uniqueSort' ) 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-unload-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'unload', 7 | 'Prefer `.on` or `.trigger` to `.unload`', 8 | { 9 | fixable: 'code', 10 | fix: utils.eventShorthandFixer 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /src/rules/no-val.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | 'val', 7 | 'Prefer `HTMLInputElement#value` to `.val`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-visibility.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'show', 'hide', 'toggle' ], 7 | ( node ) => node === true ? '' : 8 | `.${ node.callee.property.name } is not allowed` 9 | ); 10 | -------------------------------------------------------------------------------- /src/rules/no-when.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createUtilMethodRule( 6 | 'when', 7 | 'Prefer `Promise.all` to `$.when`' 8 | ); 9 | -------------------------------------------------------------------------------- /src/rules/no-wrap.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = utils.createCollectionMethodRule( 6 | [ 'wrap', 'wrapAll', 'wrapInner', 'unwrap' ], 7 | ( node ) => node === true ? '' : 8 | `.${ node.callee.property.name } is not allowed` 9 | ); 10 | -------------------------------------------------------------------------------- /src/rules/variable-pattern.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const utils = require( '../utils.js' ); 4 | 5 | module.exports = { 6 | meta: { 7 | type: 'suggestion', 8 | docs: { 9 | description: 'Disallows variable names which don\'t match `variablePattern` in settings (by default a `$`-prefix).' 10 | }, 11 | schema: [] 12 | }, 13 | 14 | create: ( context ) => { 15 | function test( node, left, right ) { 16 | if ( 17 | !utils.isjQuery( context, left ) && 18 | // If the variable name is computed (e.g. foo[bar]) we 19 | // can't be sure this is not correctly named. 20 | !left.computed && 21 | // right can be null, e.g. `var x;` 22 | right && utils.isjQuery( context, right ) 23 | ) { 24 | context.report( { 25 | node, 26 | message: 'jQuery collection names must match the variablePattern' 27 | } ); 28 | } 29 | } 30 | 31 | return { 32 | 'AssignmentExpression:exit': ( node ) => { 33 | test( node, node.left, node.right ); 34 | }, 35 | 'VariableDeclarator:exit': ( node ) => { 36 | test( node, node.id, node.init ); 37 | } 38 | }; 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /test-self/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": "wikimedia/client", 4 | "plugins": [ "self" ], 5 | "globals": { 6 | "$": "readonly" 7 | }, 8 | "rules": { 9 | "no-implicit-globals": "off", 10 | "no-restricted-properties": "off", 11 | "no-undef": "off", 12 | "no-underscore-dangle": "off", 13 | "no-unused-expressions": "off", 14 | "no-unused-vars": "off" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test-self/all/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/all" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/all/constructor.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line self/no-jquery-constructor 2 | $( () => {} ); 3 | 4 | // eslint-disable-next-line self/no-jquery-constructor 5 | $( '.selector' ); 6 | 7 | // eslint-disable-next-line self/no-jquery-constructor 8 | $( '
foo
' ); 9 | -------------------------------------------------------------------------------- /test-self/deprecated-1.10/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-1.10" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-1.10/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | $x.click(); 9 | 10 | /* 3.2 */ 11 | $.holdReady(); 12 | 13 | /* 3.0 */ 14 | $x.bind(); 15 | 16 | /* 1.10 */ 17 | // eslint-disable-next-line self/no-context-prop 18 | $x.context; 19 | 20 | /* 1.9 */ 21 | // eslint-disable-next-line self/no-support 22 | $.support; 23 | 24 | /* 1.8 */ 25 | // eslint-disable-next-line self/no-and-self 26 | $x.andSelf(); 27 | 28 | /* 1.7 */ 29 | // eslint-disable-next-line self/no-live 30 | $x.live( fn ); 31 | 32 | /* 1.3 */ 33 | // eslint-disable-next-line self/no-browser 34 | $.browser; 35 | -------------------------------------------------------------------------------- /test-self/deprecated-1.3/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-1.3" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-1.3/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | $x.click(); 9 | 10 | /* 3.2 */ 11 | $.holdReady(); 12 | 13 | /* 3.0 */ 14 | $x.bind(); 15 | 16 | /* 1.10 */ 17 | $x.context; 18 | 19 | /* 1.9 */ 20 | $.support; 21 | 22 | /* 1.8 */ 23 | $x.andSelf(); 24 | 25 | /* 1.7 */ 26 | $x.live( fn ); 27 | 28 | /* 1.3 */ 29 | // eslint-disable-next-line self/no-box-model 30 | $.boxModel.style; 31 | 32 | // eslint-disable-next-line self/no-browser 33 | $.browser; 34 | -------------------------------------------------------------------------------- /test-self/deprecated-1.7/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-1.7" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-1.7/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | $x.click(); 9 | 10 | /* 3.2 */ 11 | $.holdReady(); 12 | 13 | /* 3.0 */ 14 | $x.bind(); 15 | 16 | /* 1.10 */ 17 | $x.context; 18 | 19 | /* 1.9 */ 20 | $.support; 21 | 22 | /* 1.8 */ 23 | $x.andSelf(); 24 | 25 | /* 1.7 */ 26 | // eslint-disable-next-line self/no-live 27 | $x.live( fn ); 28 | 29 | // eslint-disable-next-line self/no-sub 30 | $.sub(); 31 | 32 | // eslint-disable-next-line self/no-selector-prop 33 | $x.selector; 34 | 35 | /* 1.3 */ 36 | // eslint-disable-next-line self/no-browser 37 | $.browser; 38 | -------------------------------------------------------------------------------- /test-self/deprecated-1.8/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-1.8" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-1.8/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | $x.click(); 9 | 10 | /* 3.2 */ 11 | $.holdReady(); 12 | 13 | /* 3.0 */ 14 | $x.bind(); 15 | 16 | /* 1.10 */ 17 | $x.context; 18 | 19 | /* 1.9 */ 20 | $.support; 21 | 22 | /* 1.8 */ 23 | // eslint-disable-next-line self/no-and-self 24 | $x.andSelf(); 25 | 26 | // eslint-disable-next-line self/no-error-shorthand 27 | $x.error( fn ); 28 | 29 | // eslint-disable-next-line self/no-load-shorthand 30 | $x.load( () => {} ); 31 | 32 | // eslint-disable-next-line self/no-on-ready 33 | $( document ).on( 'ready', () => {} ); 34 | 35 | // eslint-disable-next-line self/no-size 36 | $x.size(); 37 | 38 | // eslint-disable-next-line self/no-unload-shorthand 39 | $x.unload( () => {} ); 40 | 41 | /* 1.7 */ 42 | // eslint-disable-next-line self/no-live 43 | $x.live( fn ); 44 | 45 | /* 1.3 */ 46 | // eslint-disable-next-line self/no-browser 47 | $.browser; 48 | -------------------------------------------------------------------------------- /test-self/deprecated-1.9/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-1.9" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-1.9/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | $x.click(); 9 | 10 | /* 3.2 */ 11 | $.holdReady(); 12 | 13 | /* 3.0 */ 14 | $x.bind(); 15 | 16 | /* 1.10 */ 17 | $x.context; 18 | 19 | /* 1.9 */ 20 | // eslint-disable-next-line self/no-support 21 | $.support; 22 | 23 | /* 1.8 */ 24 | // eslint-disable-next-line self/no-and-self 25 | $x.andSelf(); 26 | 27 | /* 1.7 */ 28 | // eslint-disable-next-line self/no-live 29 | $x.live( fn ); 30 | 31 | /* 1.3 */ 32 | // eslint-disable-next-line self/no-browser 33 | $.browser; 34 | -------------------------------------------------------------------------------- /test-self/deprecated-3.0/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-3.0" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-3.0/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | $x.click(); 9 | 10 | /* 3.2 */ 11 | $.holdReady(); 12 | 13 | /* 3.0 */ 14 | // eslint-disable-next-line self/no-bind 15 | $x.bind(); 16 | 17 | // eslint-disable-next-line self/no-delegate 18 | $x.delegate(); 19 | 20 | // eslint-disable-next-line self/no-fx-interval 21 | $.fx.interval; 22 | 23 | // eslint-disable-next-line self/no-parse-json 24 | $.parseJSON(); 25 | 26 | // eslint-disable-next-line self/no-ready-shorthand 27 | $x.ready(); 28 | 29 | // eslint-disable-next-line self/no-unique 30 | $.unique(); 31 | 32 | /* 1.10 */ 33 | // eslint-disable-next-line self/no-context-prop 34 | $x.context; 35 | 36 | /* 1.9 */ 37 | // eslint-disable-next-line self/no-support 38 | $.support; 39 | 40 | /* 1.8 */ 41 | // eslint-disable-next-line self/no-and-self 42 | $x.andSelf(); 43 | 44 | /* 1.7 */ 45 | // eslint-disable-next-line self/no-live 46 | $x.live( fn ); 47 | 48 | /* 1.3 */ 49 | // eslint-disable-next-line self/no-browser 50 | $.browser; 51 | -------------------------------------------------------------------------------- /test-self/deprecated-3.2/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-3.2" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-3.2/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | $x.click(); 9 | 10 | /* 3.2 */ 11 | // eslint-disable-next-line self/no-hold-ready 12 | $.holdReady(); 13 | 14 | // eslint-disable-next-line self/no-is-array 15 | $.isArray(); 16 | 17 | // eslint-disable-next-line self/no-node-name 18 | $.nodeName(); 19 | 20 | /* 3.0 */ 21 | // eslint-disable-next-line self/no-bind 22 | $x.bind(); 23 | 24 | /* 1.10 */ 25 | // eslint-disable-next-line self/no-context-prop 26 | $x.context; 27 | 28 | /* 1.9 */ 29 | // eslint-disable-next-line self/no-support 30 | $.support; 31 | 32 | /* 1.8 */ 33 | // eslint-disable-next-line self/no-and-self 34 | $x.andSelf(); 35 | 36 | /* 1.7 */ 37 | // eslint-disable-next-line self/no-live 38 | $x.live( fn ); 39 | 40 | /* 1.3 */ 41 | // eslint-disable-next-line self/no-browser 42 | $.browser; 43 | -------------------------------------------------------------------------------- /test-self/deprecated-3.3/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-3.3" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-3.3/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | $( ':first' ); 6 | 7 | /* 3.3 */ 8 | // eslint-disable-next-line self/no-camel-case 9 | $.camelCase(); 10 | 11 | // eslint-disable-next-line self/no-event-shorthand 12 | $x.click(); 13 | 14 | // eslint-disable-next-line self/no-is-function 15 | $.isFunction(); 16 | 17 | // eslint-disable-next-line self/no-is-numeric 18 | $.isNumeric(); 19 | 20 | // eslint-disable-next-line self/no-is-window 21 | $.isWindow(); 22 | 23 | // eslint-disable-next-line self/no-now 24 | $.now(); 25 | 26 | // eslint-disable-next-line self/no-proxy 27 | $.proxy(); 28 | 29 | // eslint-disable-next-line self/no-type 30 | $.type(); 31 | 32 | /* 3.2 */ 33 | // eslint-disable-next-line self/no-hold-ready 34 | $.holdReady(); 35 | 36 | /* 3.0 */ 37 | // eslint-disable-next-line self/no-bind 38 | $x.bind(); 39 | 40 | /* 1.10 */ 41 | // eslint-disable-next-line self/no-context-prop 42 | $x.context; 43 | 44 | /* 1.9 */ 45 | // eslint-disable-next-line self/no-support 46 | $.support; 47 | 48 | /* 1.8 */ 49 | // eslint-disable-next-line self/no-and-self 50 | $x.andSelf(); 51 | 52 | /* 1.7 */ 53 | // eslint-disable-next-line self/no-live 54 | $x.live( fn ); 55 | 56 | /* 1.3 */ 57 | // eslint-disable-next-line self/no-browser 58 | $.browser; 59 | -------------------------------------------------------------------------------- /test-self/deprecated-3.4/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-3.4" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-3.4/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | $x.ajaxStart(); 3 | 4 | /* 3.4 */ 5 | // eslint-disable-next-line self/no-sizzle 6 | $( ':first' ); 7 | 8 | /* 3.3 */ 9 | // eslint-disable-next-line self/no-event-shorthand 10 | $x.click(); 11 | 12 | /* 3.2 */ 13 | // eslint-disable-next-line self/no-hold-ready 14 | $.holdReady(); 15 | 16 | /* 3.0 */ 17 | // eslint-disable-next-line self/no-bind 18 | $x.bind(); 19 | 20 | /* 1.10 */ 21 | // eslint-disable-next-line self/no-context-prop 22 | $x.context; 23 | 24 | /* 1.9 */ 25 | // eslint-disable-next-line self/no-support 26 | $.support; 27 | 28 | /* 1.8 */ 29 | // eslint-disable-next-line self/no-and-self 30 | $x.andSelf(); 31 | 32 | /* 1.7 */ 33 | // eslint-disable-next-line self/no-live 34 | $x.live( fn ); 35 | 36 | /* 1.3 */ 37 | // eslint-disable-next-line self/no-browser 38 | $.browser; 39 | -------------------------------------------------------------------------------- /test-self/deprecated-3.5/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/deprecated-3.5" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/deprecated-3.5/test.js: -------------------------------------------------------------------------------- 1 | /* 3.5 */ 2 | // eslint-disable-next-line self/no-event-shorthand 3 | $x.ajaxStart(); 4 | 5 | /* 3.4 */ 6 | // eslint-disable-next-line self/no-sizzle 7 | $( ':first' ); 8 | 9 | /* 3.3 */ 10 | // eslint-disable-next-line self/no-event-shorthand 11 | $x.click(); 12 | 13 | /* 3.2 */ 14 | // eslint-disable-next-line self/no-hold-ready 15 | $.holdReady(); 16 | 17 | /* 3.0 */ 18 | // eslint-disable-next-line self/no-bind 19 | $x.bind(); 20 | 21 | /* 1.10 */ 22 | // eslint-disable-next-line self/no-context-prop 23 | $x.context; 24 | 25 | /* 1.9 */ 26 | // eslint-disable-next-line self/no-support 27 | $.support; 28 | 29 | /* 1.8 */ 30 | // eslint-disable-next-line self/no-and-self 31 | $x.andSelf(); 32 | 33 | /* 1.7 */ 34 | // eslint-disable-next-line self/no-live 35 | $x.live( fn ); 36 | 37 | /* 1.3 */ 38 | // eslint-disable-next-line self/no-browser 39 | $.browser; 40 | -------------------------------------------------------------------------------- /test-self/recommended/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/recommended" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/recommended/test.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line self/variable-pattern 2 | const foo = $( '.foo' ); 3 | -------------------------------------------------------------------------------- /test-self/slim/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "plugin:self/slim" 3 | } 4 | -------------------------------------------------------------------------------- /test-self/slim/test.js: -------------------------------------------------------------------------------- 1 | // Effects 2 | // eslint-disable-next-line self/no-animate 3 | $x.animate(); 4 | // eslint-disable-next-line self/no-animate-toggle 5 | $x.show( 500 ); 6 | // eslint-disable-next-line self/no-fade 7 | $x.fadeOut(); 8 | // eslint-disable-next-line self/no-slide 9 | $x.slideDown(); 10 | 11 | // Ajax 12 | // eslint-disable-next-line self/no-ajax 13 | $.get( 'url' ); 14 | // eslint-disable-next-line self/no-ajax-events 15 | $x.on( 'ajaxComplete', () => {} ); 16 | // eslint-disable-next-line self/no-load 17 | $x.load(); 18 | // eslint-disable-next-line self/no-parse-xml 19 | $.parseXML(); 20 | -------------------------------------------------------------------------------- /tests/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ "wikimedia/mocha" ] 3 | } 4 | -------------------------------------------------------------------------------- /tests/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const index = require( '../src/index' ); 4 | const assert = require( 'assert' ); 5 | const fs = require( 'fs' ); 6 | 7 | describe( 'index', () => { 8 | it( 'index.js contains all rules', ( done ) => { 9 | fs.readdir( './src/rules', ( error, files ) => { 10 | assert.strictEqual( files.length, Object.keys( index.rules ).length ); 11 | done(); 12 | } ); 13 | } ); 14 | } ); 15 | -------------------------------------------------------------------------------- /tests/rules/no-ajax.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-ajax' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const ajaxError = 'Prefer Window.fetch to $.ajax'; 7 | const getError = 'Prefer Window.fetch to $.get'; 8 | const jsonError = 'Prefer Window.fetch to $.getJSON'; 9 | const scriptError = 'Prefer Window.fetch to $.getScript'; 10 | const postError = 'Prefer Window.fetch to $.post'; 11 | 12 | const ruleTester = new RuleTester(); 13 | ruleTester.run( 'no-ajax', rule, { 14 | valid: [ 15 | 'ajax()', 16 | 'div.ajax()', 17 | 'div.ajax', 18 | 19 | 'get()', 20 | 'div.get()', 21 | 'div.get', 22 | 23 | 'getJSON()', 24 | 'div.getJSON()', 25 | 'div.getJSON', 26 | 27 | 'getScript()', 28 | 'div.getScript()', 29 | 'div.getScript', 30 | 31 | 'post()', 32 | 'div.post()', 33 | 'div.post' 34 | ], 35 | invalid: [ 36 | { 37 | code: '$.ajax()', 38 | errors: [ ajaxError ] 39 | }, 40 | { 41 | code: '$.get()', 42 | errors: [ getError ] 43 | }, 44 | { 45 | code: '$.getJSON()', 46 | errors: [ jsonError ] 47 | }, 48 | { 49 | code: '$.getScript()', 50 | errors: [ scriptError ] 51 | }, 52 | { 53 | code: '$.post()', 54 | errors: [ postError ] 55 | } 56 | ] 57 | } ); 58 | -------------------------------------------------------------------------------- /tests/rules/no-and-self.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-and-self' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .addBack to .andSelf'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-and-self', rule, { 10 | valid: [ 'andSelf()', '[].andSelf()', 'div.andSelf()', 'div.andSelf' ], 11 | invalid: [ 12 | { 13 | code: '$("div").andSelf(".foo")', 14 | errors: [ error ], 15 | output: '$("div").addBack(".foo")' 16 | }, 17 | { 18 | code: '$div.andSelf(".foo")', 19 | errors: [ error ], 20 | output: '$div.addBack(".foo")' 21 | }, 22 | { 23 | code: '$("div").first().andSelf()', 24 | errors: [ error ], 25 | output: '$("div").first().addBack()' 26 | }, 27 | { 28 | code: '$("div").append($("input").andSelf())', 29 | errors: [ error ], 30 | output: '$("div").append($("input").addBack())' 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-attr.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-attr' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const getError = 'Prefer Element#getAttribute to .attr/$.attr'; 7 | const setError = 'Prefer Element#setAttribute to .attr/$.attr'; 8 | const removeError = 'Prefer Element#removeAttribute to .removeAttr/$.removeAttr'; 9 | 10 | const ruleTester = new RuleTester(); 11 | ruleTester.run( 'no-attr', rule, { 12 | valid: [ 'attr()', '[].attr()', 'div.attr()', 'div.attr', 'removeAttr()', 'div.removeAttr' ], 13 | invalid: [ 14 | { 15 | code: '$.attr()', 16 | errors: [ getError ] 17 | }, 18 | { 19 | code: '$("div").attr()', 20 | errors: [ getError ] 21 | }, 22 | { 23 | code: '$div.attr()', 24 | errors: [ getError ] 25 | }, 26 | { 27 | code: '$("div").first().attr()', 28 | errors: [ getError ] 29 | }, 30 | { 31 | code: '$("div").append($("input").attr())', 32 | errors: [ getError ] 33 | }, 34 | { 35 | code: '$("div").attr("name")', 36 | errors: [ getError ] 37 | }, 38 | { 39 | code: '$("div").attr("name", "random")', 40 | errors: [ setError ] 41 | }, 42 | { 43 | code: '$.removeAttr()', 44 | errors: [ removeError ] 45 | }, 46 | { 47 | code: '$("div").removeAttr("name")', 48 | errors: [ removeError ] 49 | } 50 | ] 51 | } ); 52 | -------------------------------------------------------------------------------- /tests/rules/no-bind.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-bind' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const bindError = 'Prefer .on/EventTarget#addEventListener to .bind'; 7 | const unbindError = 'Prefer .off/EventTarget#removeEventListener to .unbind'; 8 | 9 | const ruleTester = new RuleTester(); 10 | ruleTester.run( 'no-bind', rule, { 11 | valid: [ 12 | 'bind()', 13 | '[].bind()', 14 | 'div.bind()', 15 | 'div.bind', 16 | '$div.remove.bind($div)', 17 | 18 | 'unbind()', 19 | '[].unbind()', 20 | 'div.unbind()', 21 | 'div.unbind', 22 | '$div.remove.unbind($div)' 23 | ], 24 | invalid: [ 25 | [ '$("div").bind()', bindError ], 26 | [ '$div.bind()', bindError ], 27 | [ '$("div").first().bind()', bindError ], 28 | [ '$("div").append($("input").bind())', bindError ], 29 | 30 | [ '$("div").unbind()', unbindError ], 31 | [ '$div.unbind()', unbindError ], 32 | [ '$("div").first().unbind()', unbindError ], 33 | [ '$("div").append($("input").unbind())', unbindError ] 34 | ].map( ( codeError ) => ( { 35 | code: codeError[ 0 ], 36 | errors: [ codeError[ 1 ] ] 37 | } ) ) 38 | } ); 39 | -------------------------------------------------------------------------------- /tests/rules/no-box-model.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-box-model' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.boxModel is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-box-model', rule, { 10 | valid: [ 'boxModel', 'a.boxModel', 'boxModel.foo', 'a.boxModel.foo' ], 11 | invalid: [ 12 | { 13 | code: '$.boxModel', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$.boxModel.style', 18 | errors: [ error ] 19 | } 20 | ] 21 | } ); 22 | -------------------------------------------------------------------------------- /tests/rules/no-browser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-browser' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.browser is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-browser', rule, { 10 | valid: [ 'browser', 'a.browser', 'browser.foo', 'a.browser.foo', '$.browsers' ], 11 | invalid: [ 12 | { 13 | code: '$.browser', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$.browser.style', 18 | errors: [ error ] 19 | } 20 | ] 21 | } ); 22 | -------------------------------------------------------------------------------- /tests/rules/no-camel-case.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-camel-case' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.camelCase is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-camel-case', rule, { 10 | valid: [ 'camelCase()', 'myClass.camelCase()', '$div.camelCase()' ], 11 | invalid: [ 12 | { 13 | code: '$.camelCase()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-clone.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-clone' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Node#cloneNode to .clone/$.clone'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-clone', rule, { 10 | valid: [ 11 | 'clone()', 12 | '[].clone()', 13 | 'div.clone()', 14 | 'div.clone', 15 | '$div.prop.clone()', 16 | { 17 | code: '$div["prop"].clone()', 18 | docgen: false 19 | }, 20 | '$div[0].clone()' 21 | ], 22 | invalid: [ 23 | { 24 | code: '$.clone()', 25 | errors: [ error ] 26 | }, 27 | { 28 | code: '$("div").clone()', 29 | errors: [ error ] 30 | }, 31 | { 32 | code: '$div.clone()', 33 | errors: [ error ] 34 | }, 35 | { 36 | code: 'this.prop.$div.clone()', 37 | errors: [ error ] 38 | }, 39 | { 40 | code: '$("div").first().clone()', 41 | errors: [ error ] 42 | }, 43 | { 44 | code: '$("div").append($("input").clone())', 45 | errors: [ error ] 46 | } 47 | ] 48 | } ); 49 | -------------------------------------------------------------------------------- /tests/rules/no-closest.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-closest' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Element#closest to .closest'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-closest', rule, { 10 | valid: [ 'closest()', '[].closest()', 'div.closest()', 'div.closest' ], 11 | invalid: [ 12 | { 13 | code: '$("div").closest()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.closest()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().closest()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").closest())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-constructor-attributes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-constructor-attributes' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .attr to constructor attributes'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-constructor-attributes', rule, { 10 | valid: [ 11 | '$(".div")', 12 | '$("
")', 13 | '$(".div", context)', 14 | '$("
", ownerDocument)', 15 | '$("
", ownerDocument)', 16 | '$div.add("
", context)', 17 | { 18 | code: '(function(){$(".div")})()', 19 | docgen: false 20 | } 21 | ], 22 | invalid: [ 23 | { 24 | code: '$("
", {width:100, class:"foo"})', 25 | errors: [ error ] 26 | }, 27 | { 28 | code: '$("
", {on: {click:function(){}}})', 29 | errors: [ error ] 30 | }, 31 | { 32 | code: '$("
", {data:{foo:"bar"}})', 33 | errors: [ error ] 34 | }, 35 | // This isn't a documented signature of $.add, but due to the 36 | // way it is implemented it does work 37 | { 38 | code: '$div.add("
", {width:100, class:"foo"})', 39 | errors: [ error ] 40 | } 41 | ] 42 | } ); 43 | -------------------------------------------------------------------------------- /tests/rules/no-contains.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-contains' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Node#contains to $.contains'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-contains', rule, { 10 | valid: [ 'contains()', 'myClass.contains()', '$div.contains()' ], 11 | invalid: [ 12 | { 13 | code: '$.contains()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-context-prop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-context-prop' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.context is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-context-prop', rule, { 10 | valid: [ 11 | 'context', 12 | 'div.context', 13 | '$div.prop.context', 14 | '$div.context()', 15 | '$div.context(arg)' 16 | ], 17 | invalid: [ 18 | { 19 | code: '$("div").context', 20 | errors: [ error ] 21 | }, 22 | { 23 | code: '$div.context', 24 | errors: [ error ] 25 | }, 26 | { 27 | code: '$div.context.prop', 28 | errors: [ error ] 29 | }, 30 | { 31 | code: '$div.context.method()', 32 | errors: [ error ] 33 | }, 34 | { 35 | code: '$("div").first().context', 36 | errors: [ error ] 37 | }, 38 | { 39 | code: 'f($div.context)', 40 | errors: [ error ] 41 | }, 42 | { 43 | code: '$("div").append($("input").context)', 44 | errors: [ error ] 45 | } 46 | ] 47 | } ); 48 | -------------------------------------------------------------------------------- /tests/rules/no-css.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-css' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Window#getComputedStyle to .css/$.css'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-css', rule, { 10 | valid: [ 'css()', '[].css()', 'div.css()', 'div.css' ], 11 | invalid: [ 12 | { 13 | code: '$.css()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$("div").css()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$div.css()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").first().css()', 26 | errors: [ error ] 27 | }, 28 | { 29 | code: '$("div").append($("input").css())', 30 | errors: [ error ] 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-deferred.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-deferred' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Promise to $.Deferred'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-deferred', rule, { 10 | valid: [ 11 | 'Deferred()', 12 | 'new Deferred()', 13 | '"test".Deferred()', 14 | '"test".Deferred' 15 | ], 16 | invalid: [ 17 | { 18 | code: '$.Deferred()', 19 | errors: [ error ] 20 | }, 21 | { 22 | code: 'new $.Deferred()', 23 | errors: [ error ] 24 | } 25 | ] 26 | } ); 27 | -------------------------------------------------------------------------------- /tests/rules/no-die.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-die' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .off/EventTarget#removeEventListener to .die. This rule is deprecated, use no-live.'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-die', rule, { 10 | valid: [ 'die()', '[].die()', 'div.die()', 'div.die' ], 11 | invalid: [ 12 | { 13 | code: '$("div").die()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.die()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().die()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").die())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-done-fail.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-done-fail' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = ( method ) => `Prefer .then to .${ method }`; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-done-fail', rule, { 10 | valid: [ 'promise.then( doneCallback, failCallback )', 'done()', 'fail()' ], 11 | invalid: [ 12 | { 13 | code: 'promise.done( callback )', 14 | errors: [ error( 'done' ) ] 15 | }, 16 | { 17 | code: 'promise.fail( callback )', 18 | errors: [ error( 'fail' ) ] 19 | } 20 | ] 21 | } ); 22 | -------------------------------------------------------------------------------- /tests/rules/no-each-collection.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-each-collection' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#forEach to .each'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-each-collection', rule, { 10 | valid: [ 'each()', '[].each()', 'div.each()', 'div.each', '$.each()' ], 11 | invalid: [ 12 | { 13 | code: '$("div").each()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.each()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().each()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").each())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-each-util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-each-util' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#forEach to $.each'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-each-util', rule, { 10 | valid: [ 11 | 'each()', 12 | '[].each()', 13 | 'div.each()', 14 | 'div.each', 15 | '$("div").each()', 16 | '$div.each()', 17 | '$("div").first().each()', 18 | '$("div").append($("input").each())' 19 | ], 20 | invalid: [ 21 | { 22 | code: '$.each()', 23 | errors: [ error ] 24 | } 25 | ] 26 | } ); 27 | -------------------------------------------------------------------------------- /tests/rules/no-each.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-each' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#forEach to .each/$.each'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-each', rule, { 10 | valid: [ 'each()', '[].each()', 'div.each()', 'div.each' ], 11 | invalid: [ 12 | { 13 | code: '$.each()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$("div").each()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$div.each()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").first().each()', 26 | errors: [ error ] 27 | }, 28 | { 29 | code: '$("div").append($("input").each())', 30 | errors: [ error ] 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-error-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-error-shorthand' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .on or .trigger to .error'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-error-shorthand', rule, { 10 | valid: [ 'error()', '[].error()', 'div.error()', 'div.error', '$.error()' ], 11 | invalid: [ 12 | { 13 | code: '$("div").error(handler)', 14 | errors: [ error ], 15 | output: '$("div").on("error", handler)' 16 | }, 17 | { 18 | code: '$div.error()', 19 | errors: [ error ], 20 | output: '$div.trigger("error")' 21 | }, 22 | { 23 | code: '$("div").first().error()', 24 | errors: [ error ], 25 | output: '$("div").first().trigger("error")' 26 | }, 27 | { 28 | code: '$("div").append($("input").error())', 29 | errors: [ error ], 30 | output: '$("div").append($("input").trigger("error"))' 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-error.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-error' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer throw to $.error'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-error', rule, { 10 | valid: [ 'error(msg)', 'myClass.error(msg)', '$div.error(msg)' ], 11 | invalid: [ 12 | { 13 | code: '$.error(msg)', 14 | errors: [ error ], 15 | output: 'throw new Error(msg)' 16 | } 17 | ] 18 | } ); 19 | -------------------------------------------------------------------------------- /tests/rules/no-escape-selector.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-escape-selector' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer CSS.escape to $.escapeSelector'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-escape-selector', rule, { 10 | valid: [ 'escapeSelector(".foo>")', 'myClass.escapeSelector(".foo>")', '$div.escapeSelector(".foo>")' ], 11 | invalid: [ 12 | { 13 | code: '$.escapeSelector(".foo>")', 14 | errors: [ error ], 15 | output: 'CSS.escape(".foo>")' 16 | } 17 | ] 18 | } ); 19 | -------------------------------------------------------------------------------- /tests/rules/no-extend.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-extend' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Object.assign or the spread operator to $.extend'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-extend', rule, { 10 | valid: [ 11 | 'extend()', 12 | 'myMethod.extend()', 13 | 'myMethod.extend', 14 | { 15 | code: '$.extend(true, {}, foo)', 16 | options: [ { allowDeep: true } ] 17 | }, 18 | '$.extend({myUtil:fn})' 19 | ], 20 | invalid: [ 21 | { 22 | code: '$.extend({}, foo)', 23 | errors: [ error ], 24 | output: 'Object.assign({}, foo)' 25 | }, 26 | { 27 | code: '$.extend(true, {}, foo)', 28 | errors: [ error ] 29 | }, 30 | { 31 | code: '$.extend({}, foo)', 32 | options: [ { allowDeep: true } ], 33 | errors: [ error ], 34 | output: 'Object.assign({}, foo)' 35 | }, 36 | { 37 | code: '$.extend(fooCouldBeNull, doesNotAutofix)', 38 | options: [ { allowDeep: true } ], 39 | errors: [ error ] 40 | } 41 | ] 42 | } ); 43 | -------------------------------------------------------------------------------- /tests/rules/no-filter.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-filter' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#filter to .filter/$.filter'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-filter', rule, { 10 | valid: [ 'filter()', '[].filter()', 'div.filter()', 'div.filter' ], 11 | invalid: [ 12 | { 13 | code: '$.filter()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$("div").filter()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$div.filter()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").first().filter()', 26 | errors: [ error ] 27 | }, 28 | { 29 | code: '$("div").append($("input").filter())', 30 | errors: [ error ] 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-find-collection.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-find-collection' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Document#querySelectorAll to .find'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-find-collection', rule, { 10 | valid: [ '$.find()', 'find()', '[].find()', 'div.find()', 'div.find', '$.extend().find()', '$div.myPlugin("foo").find()' ], 11 | invalid: [ 12 | { 13 | code: '$("div").find()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.find()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().find()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").find())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-find-util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-find-util' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Document#querySelectorAll to $.find'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-find-util', rule, { 10 | valid: [ 11 | 'find()', 12 | '[].find()', 13 | 'div.find()', 14 | 'div.find', 15 | '$.extend().find()', 16 | '$div.myPlugin("foo").find()', 17 | '$("div").find()', 18 | '$div.find()', 19 | '$("div").first().find()', 20 | '$("div").append($("input").find())' 21 | ], 22 | invalid: [ 23 | { 24 | code: '$.find()', 25 | errors: [ error ] 26 | } 27 | ] 28 | } ); 29 | -------------------------------------------------------------------------------- /tests/rules/no-find.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-find' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Document#querySelectorAll to .find/$.find'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-find', rule, { 10 | valid: [ 'find()', '[].find()', 'div.find()', 'div.find', '$.extend().find()', '$div.myPlugin("foo").find()' ], 11 | invalid: [ 12 | { 13 | code: '$.find()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$("div").find()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$div.find()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").first().find()', 26 | errors: [ error ] 27 | }, 28 | { 29 | code: '$("div").append($("input").find())', 30 | errors: [ error ] 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-fx-interval.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-fx-interval' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.fx.interval is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-fx-interval', rule, { 10 | valid: [ 'interval', 'fx.interval', '$.interval', 'a.fx.interval', '$.fx' ], 11 | invalid: [ 12 | { 13 | code: '$.fx.interval', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-fx.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-fx' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.fx is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-fx', rule, { 10 | valid: [ 'fx', 'fx.interval', 'a.fx' ], 11 | invalid: [ 12 | { 13 | code: '$.fx', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$.fx.interval', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$.fx.off', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$.fx.speeds.slow', 26 | errors: [ error ] 27 | }, 28 | { 29 | code: '$.fx.start()', 30 | errors: [ error ] 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-global-eval.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-global-eval' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.globalEval is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-global-eval', rule, { 10 | valid: [ 'globalEval()', '"test".globalEval()', '"test".globalEval' ], 11 | invalid: [ 12 | { 13 | code: '$.globalEval()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-grep.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-grep' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#filter to $.grep'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-grep', rule, { 10 | valid: [ 'grep()', '"test".grep()', '"test".grep' ], 11 | invalid: [ 12 | { 13 | code: '$.grep()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-has.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-has' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.has is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-has', rule, { 10 | valid: [ 'has()', '[].has()', 'div.has()', 'div.has' ], 11 | invalid: [ 12 | { 13 | code: '$("div").has()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.has()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().has()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").has())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-hide.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-hide' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.hide is not allowed. This rule is deprecated, use no-visibility.'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-hide', rule, { 10 | valid: [ 'hide()', '[].hide()', 'div.hide()', 'div.hide' ], 11 | invalid: [ 12 | { 13 | code: '$("div").hide()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.hide()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().hide()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").hide())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-hold-ready.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-hold-ready' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.holdReady is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-hold-ready', rule, { 10 | valid: [ 'holdReady()', '"test".holdReady()', '"test".holdReady' ], 11 | invalid: [ 12 | { 13 | code: '$.holdReady()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-html.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-html' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Element#innerHTML to .html'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-html', rule, { 10 | valid: [ 11 | 'html()', 12 | '[].html()', 13 | 'div.html()', 14 | 'div.html', 15 | { 16 | code: '$div.html()', 17 | options: [ { allowGetOrSet: 'get' } ] 18 | }, 19 | { 20 | code: '$div.html("
")', 21 | options: [ { allowGetOrSet: 'set' } ] 22 | } 23 | ], 24 | invalid: [ 25 | { 26 | code: '$("div").html()', 27 | errors: [ error ] 28 | }, 29 | { 30 | code: '$div.html()', 31 | errors: [ error ] 32 | }, 33 | { 34 | code: '$div.html()', 35 | options: [ { allowGetOrSet: 'set' } ], 36 | errors: [ error ] 37 | }, 38 | { 39 | code: '$div.html("
")', 40 | options: [ { allowGetOrSet: 'get' } ], 41 | errors: [ error ] 42 | }, 43 | { 44 | code: '$("div").first().html()', 45 | errors: [ error ] 46 | }, 47 | { 48 | code: '$("div").append($("input").html())', 49 | errors: [ error ] 50 | } 51 | ] 52 | } ); 53 | -------------------------------------------------------------------------------- /tests/rules/no-in-array.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-in-array' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#indexOf to $.inArray'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-in-array', rule, { 10 | valid: [ 'inArray()', '"test".inArray()', '"test".inArray' ], 11 | invalid: [ 12 | { 13 | code: '$.inArray()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-is-array.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-is-array' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array.isArray to $.isArray'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-is-array', rule, { 10 | valid: [ 'isArray()', '"test".isArray()', '"test".isArray' ], 11 | invalid: [ 12 | { 13 | code: '$.isArray( [] )', 14 | errors: [ error ], 15 | output: 'Array.isArray( [] )' 16 | } 17 | ] 18 | } ); 19 | -------------------------------------------------------------------------------- /tests/rules/no-is-empty-object.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-is-empty-object' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.isEmptyObject is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-is-empty-object', rule, { 10 | valid: [ 'isEmptyObject()', 'myClass.isEmptyObject()', '$div.isEmptyObject()' ], 11 | invalid: [ 12 | { 13 | code: '$.isEmptyObject()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-is-function.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-is-function' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer typeof to $.isFunction'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-is-function', rule, { 10 | valid: [ 'isFunction()', 'myClass.isFunction()', '$div.isFunction()' ], 11 | invalid: [ 12 | { 13 | code: '$.isFunction(expression(arg))', 14 | errors: [ error ], 15 | output: 'typeof expression(arg) === "function"' 16 | }, 17 | { 18 | code: 'if($.isFunction(fn)){g();}', 19 | errors: [ error ], 20 | output: 'if(typeof fn === "function"){g();}' 21 | } 22 | ] 23 | } ); 24 | -------------------------------------------------------------------------------- /tests/rules/no-is-numeric.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-is-numeric' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer typeof to $.isNumeric'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-is-numeric', rule, { 10 | valid: [ 'isNumeric()', 'myClass.isNumeric()', '$div.isNumeric()' ], 11 | invalid: [ 12 | { 13 | code: '$.isNumeric()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-is-plain-object.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-is-plain-object' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.isPlainObject is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-is-plain-object', rule, { 10 | valid: [ 'isPlainObject()', 'myClass.isPlainObject()', '$div.isPlainObject()' ], 11 | invalid: [ 12 | { 13 | code: '$.isPlainObject()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-is-window.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-is-window' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.isWindow is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-is-window', rule, { 10 | valid: [ 'isWindow()', 'myClass.isWindow()' ], 11 | invalid: [ 12 | { 13 | code: '$.isWindow()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-is.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-is' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Element#matches to .is'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-is', rule, { 10 | valid: [ 'is()', '[].is()', 'div.is()', 'div.is' ], 11 | invalid: [ 12 | { 13 | code: '$("div").is()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.is()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().is()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").is())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-jquery-constructor.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-jquery-constructor' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'The jQuery constructor is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-jquery-constructor', rule, { 10 | valid: [ 11 | 'foo.$(".selector")', 12 | 'foo.$("
")', 13 | 'foo.jQuery(".selector")', 14 | 'foo.jQuery("
")', 15 | '$', 16 | 'jQuery' 17 | ], 18 | invalid: [ 19 | '$("div")', 20 | '$("#id")', 21 | '$(".selector")', 22 | '$(".selector", ".context")', 23 | '$(function(){})', 24 | '$([])', 25 | '$(undefined)', 26 | '$(false)', 27 | 'jQuery("div")' 28 | ].map( 29 | ( test ) => Object.assign( { 30 | errors: [ error ] 31 | }, typeof test === 'string' ? { code: test } : test ) 32 | ) 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-live.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-live' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const liveError = 'Prefer .on/EventTarget#addEventListener to .live'; 7 | const dieError = 'Prefer .off/EventTarget#removeEventListener to .die'; 8 | 9 | const ruleTester = new RuleTester(); 10 | ruleTester.run( 'no-live', rule, { 11 | valid: [ 12 | 'live()', 13 | '[].live()', 14 | 'div.live()', 15 | 'div.live', 16 | 17 | 'die()', 18 | '[].die()', 19 | 'div.die()', 20 | 'div.die' 21 | ], 22 | invalid: [ 23 | { 24 | code: '$("div").live()', 25 | errors: [ liveError ] 26 | }, 27 | { 28 | code: '$div.live()', 29 | errors: [ liveError ] 30 | }, 31 | { 32 | code: '$("div").first().live()', 33 | errors: [ liveError ] 34 | }, 35 | { 36 | code: '$("div").append($("input").live())', 37 | errors: [ liveError ] 38 | }, 39 | 40 | { 41 | code: '$("div").die()', 42 | errors: [ dieError ] 43 | }, 44 | { 45 | code: '$div.die()', 46 | errors: [ dieError ] 47 | }, 48 | { 49 | code: '$("div").first().die()', 50 | errors: [ dieError ] 51 | }, 52 | { 53 | code: '$("div").append($("input").die())', 54 | errors: [ dieError ] 55 | } 56 | ] 57 | } ); 58 | -------------------------------------------------------------------------------- /tests/rules/no-load-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-load-shorthand' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .on or .trigger to .load'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-load-shorthand', rule, { 10 | valid: [ 11 | 'load()', 12 | '[].load()', 13 | 'div.load()', 14 | 'div.load', 15 | '$.load()', 16 | '$div.load("url")', 17 | '$div.load(couldBeUrl)' 18 | ], 19 | invalid: [ 20 | { 21 | code: '$("div").load(function(){})', 22 | errors: [ error ], 23 | output: '$("div").on("load", function(){})' 24 | }, 25 | { 26 | code: '$div.load(function(){})', 27 | errors: [ error ], 28 | output: '$div.on("load", function(){})' 29 | }, 30 | { 31 | code: '$div.load()', 32 | errors: [ error ], 33 | output: '$div.trigger("load")' 34 | }, 35 | { 36 | code: '$div.load(() => {})', 37 | errors: [ error ], 38 | output: '$div.on("load", () => {})' 39 | }, 40 | { 41 | code: '$("div").first().load(function(){})', 42 | errors: [ error ], 43 | output: '$("div").first().on("load", function(){})' 44 | }, 45 | { 46 | code: '$("div").append($("input").load(function(){}))', 47 | errors: [ error ], 48 | output: '$("div").append($("input").on("load", function(){}))' 49 | } 50 | ] 51 | } ); 52 | -------------------------------------------------------------------------------- /tests/rules/no-load.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-load' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer fetch to .load'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-load', rule, { 10 | valid: [ 'load()', '[].load()', 'div.load()', 'div.load', '$.load()' ], 11 | invalid: [ 12 | { 13 | code: '$("div").load()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.load()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().load()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").load())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-map-collection.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-map-collection' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#map to .map'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-map-collection', rule, { 10 | valid: [ 'map()', '[].map()', 'div.map()', 'div.map', '$.map()', '$("select").val().map()' ], 11 | invalid: [ 12 | { 13 | code: '$("div").map()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.map()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().map()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").map())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-map-util.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-map-util' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#map to $.map'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-map-util', rule, { 10 | valid: [ 11 | 'map()', 12 | '[].map()', 13 | 'div.map()', 14 | 'div.map', 15 | '$("div").map()', 16 | '$div.map()', 17 | '$("div").first().map()', 18 | '$("div").append($("input").map())', 19 | '$("select").val().map()' 20 | ], 21 | invalid: [ 22 | { 23 | code: '$.map()', 24 | errors: [ error ] 25 | } 26 | ] 27 | } ); 28 | -------------------------------------------------------------------------------- /tests/rules/no-map.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-map' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#map to .map/$.map'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-map', rule, { 10 | valid: [ 'map()', '[].map()', 'div.map()', 'div.map;', '$("div").toArray().map()', '$("select").val().map()' ], 11 | invalid: [ 12 | { 13 | code: '$.map()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$("div").map()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$div.map()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").first().map()', 26 | errors: [ error ] 27 | }, 28 | { 29 | code: '$("div").append($("input").map())', 30 | errors: [ error ] 31 | }, 32 | { 33 | code: '$("select").val([]).map()', 34 | errors: [ error ] 35 | } 36 | ] 37 | } ); 38 | -------------------------------------------------------------------------------- /tests/rules/no-merge.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-merge' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Array#concat to $.merge'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-merge', rule, { 10 | valid: [ 'merge()', '"test".merge()', '"test".merge' ], 11 | invalid: [ 12 | { 13 | code: '$.merge()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-node-name.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-node-name' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.nodeName is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-node-name', rule, { 10 | valid: [ 'nodeName()', 'myClass.nodeName()', '$div.nodeName()' ], 11 | invalid: [ 12 | { 13 | code: '$.nodeName()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-noop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-noop' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer function(){} to $.noop'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-noop', rule, { 10 | valid: [ 'foo.noop', 'foo.noop()', 'foo.noop(bar)', '$.noOp' ], 11 | invalid: [ 12 | { 13 | code: '$.noop', 14 | errors: [ error ], 15 | output: '(function(){})' 16 | }, 17 | { 18 | code: '$.noop()', 19 | errors: [ error ], 20 | output: '(function(){})()' 21 | } 22 | ] 23 | } ); 24 | -------------------------------------------------------------------------------- /tests/rules/no-now.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-now' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Date.now to $.now'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-now', rule, { 10 | valid: [ 'now()', 'myClass.now()', '$div.now()' ], 11 | invalid: [ 12 | { 13 | code: '$.now()', 14 | errors: [ error ], 15 | output: 'Date.now()' 16 | } 17 | ] 18 | } ); 19 | -------------------------------------------------------------------------------- /tests/rules/no-on-ready.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-on-ready' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.on("ready") is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-on-ready', rule, { 10 | valid: [ 11 | '$(document).on("click", function(){})', 12 | '$(document).on()', 13 | '$document.on("click", function(){})', 14 | '$document.on()', 15 | '$document.on(ready)', 16 | '$document.on(ready())', 17 | '$document.ready()', 18 | '$(function(){})', 19 | 'document.on("ready")', 20 | 'document.on("ready", function(){})' 21 | ], 22 | invalid: [ 23 | { 24 | code: '$(document).on("ready", function(){})', 25 | errors: [ error ], 26 | output: '$(document).ready(function(){})' 27 | }, 28 | { 29 | code: '$document.on("ready", function(){})', 30 | errors: [ error ], 31 | output: '$document.ready(function(){})' 32 | }, 33 | { 34 | code: '$document.on("ready")', 35 | errors: [ error ], 36 | docgen: false 37 | } 38 | ] 39 | } ); 40 | -------------------------------------------------------------------------------- /tests/rules/no-other-methods.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-other-methods' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const ruleTester = new RuleTester(); 7 | ruleTester.run( 'no-other-methods', rule, { 8 | valid: [ 9 | '$div.each()', 10 | '$div.find()', 11 | '$div.map()', 12 | '$div.otherProperty', 13 | 'div.otherMethod()', 14 | '$.otherUtil()', 15 | 'method()' 16 | ], 17 | invalid: [ 18 | { 19 | code: '$div.add()', 20 | errors: [ '.add is not allowed' ] 21 | }, 22 | { 23 | code: '$div.height()', 24 | errors: [ '.height is not allowed' ] 25 | }, 26 | { 27 | code: '$div.prepend()', 28 | errors: [ '.prepend is not allowed' ] 29 | }, 30 | { 31 | code: '$div.otherMethod()', 32 | errors: [ '.otherMethod is not allowed' ] 33 | } 34 | ] 35 | } ); 36 | -------------------------------------------------------------------------------- /tests/rules/no-other-utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-other-utils' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const ruleTester = new RuleTester(); 7 | ruleTester.run( 'no-other-utils', rule, { 8 | valid: [ 9 | '$.each()', 10 | '$.find()', 11 | '$.map()', 12 | '$.otherProperty', 13 | '$div.otherMethod()', 14 | 'method()' 15 | ], 16 | invalid: [ 17 | { 18 | code: '$.dequeue()', 19 | errors: [ '$.dequeue is not allowed' ] 20 | }, 21 | { 22 | code: '$.noConflict()', 23 | errors: [ '$.noConflict is not allowed' ] 24 | }, 25 | { 26 | code: '$.uniqueSort()', 27 | errors: [ '$.uniqueSort is not allowed' ] 28 | }, 29 | { 30 | code: '$.otherUtil()', 31 | errors: [ '$.otherUtil is not allowed' ] 32 | } 33 | ] 34 | } ); 35 | -------------------------------------------------------------------------------- /tests/rules/no-param.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-param' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer FormData or URLSearchParams to $.param'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-param', rule, { 10 | valid: [ 'param()', '"test".param()', '"test".param' ], 11 | invalid: [ 12 | { 13 | code: '$.param()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-parent.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-parent' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Node#parentElement to .parent'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-parent', rule, { 10 | valid: [ 'parent()', '[].parent()', 'div.parent()', 'div.parent' ], 11 | invalid: [ 12 | { 13 | code: '$("div").parent()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.parent()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().parent()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").parent())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-parents.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-parents' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Element#closest to .parents'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-parents', rule, { 10 | valid: [ 'parents()', '[].parents()', 'div.parents()', 'div.parents' ], 11 | invalid: [ 12 | { 13 | code: '$("div").parents()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.parents()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().parents()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").parents())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-parse-html.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-parse-html' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer DOMImplementation#createHTMLDocument to $.parseHTML'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-parse-html', rule, { 10 | valid: [ 'parseHTML("test")', '"test".parseHTML("test")', '"test".parseHTML' ], 11 | invalid: [ 12 | { 13 | code: '$.parseHTML("test")', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-parse-json.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-parse-json' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer JSON.parse to $.parseJSON'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-parse-json', rule, { 10 | valid: [ 'parseJSON()', '$div.parseJSON()', '"test".parseJSON' ], 11 | invalid: [ 12 | { 13 | code: '$.parseJSON("{}")', 14 | errors: [ error ], 15 | output: 'JSON.parse("{}")' 16 | } 17 | ] 18 | } ); 19 | -------------------------------------------------------------------------------- /tests/rules/no-parse-xml.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-parse-xml' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer DOMParser#parseFromString to $.parseXML'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-parse-xml', rule, { 10 | valid: [ 'parseXML("test")', '"test".parseXML("test")', '"test".parseXML' ], 11 | invalid: [ 12 | { 13 | code: '$.parseXML("test")', 14 | errors: [ error ], 15 | output: '( new window.DOMParser() ).parseFromString("test", "text/xml")' 16 | }, 17 | // Can't fix if no arguments are passed 18 | { 19 | code: '$.parseXML()', 20 | errors: [ error ], 21 | docgen: false 22 | } 23 | ] 24 | } ); 25 | -------------------------------------------------------------------------------- /tests/rules/no-prop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-prop' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer direct property access to .prop/$.prop'; 7 | const errorRemove = 'Prefer direct property access to .removeProp/$.removeProp'; 8 | 9 | const ruleTester = new RuleTester(); 10 | ruleTester.run( 'no-prop', rule, { 11 | valid: [ 'prop()', '[].prop()', 'div.prop()', 'div.prop', 'removeProp()', 'div.removeProp()' ], 12 | invalid: [ 13 | { 14 | code: '$.prop()', 15 | errors: [ error ] 16 | }, 17 | { 18 | code: '$("div").prop()', 19 | errors: [ error ] 20 | }, 21 | { 22 | code: '$div.prop()', 23 | errors: [ error ] 24 | }, 25 | { 26 | code: '$("div").first().prop()', 27 | errors: [ error ] 28 | }, 29 | { 30 | code: '$("div").append($("input").prop())', 31 | errors: [ error ] 32 | }, 33 | // $.removeProp util is disallowed too as the rule is shared 34 | // with $.prop, but $.removeProp doesn't exist 35 | { 36 | code: '$("div").removeProp()', 37 | errors: [ errorRemove ] 38 | } 39 | ] 40 | } ); 41 | -------------------------------------------------------------------------------- /tests/rules/no-proxy.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-proxy' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Function#bind to $.proxy'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-proxy', rule, { 10 | valid: [ 'proxy(fn, context)', '"test".proxy(fn, context)', '"test".proxy' ], 11 | invalid: [ 12 | { 13 | code: '$.proxy(this.fn, context)', 14 | errors: [ error ], 15 | output: 'this.fn.bind(context)' 16 | }, 17 | { 18 | code: '$.proxy(fn, context, arg1, arg2)', 19 | errors: [ error ], 20 | output: 'fn.bind(context, arg1, arg2)' 21 | }, 22 | { 23 | code: '$.proxy(context, "fnName")', 24 | errors: [ error ] 25 | }, 26 | { 27 | code: '$.proxy(context, "fnName", arg1, arg2)', 28 | errors: [ error ] 29 | }, 30 | { 31 | code: '$.proxy()', 32 | errors: [ error ], 33 | docgen: false 34 | } 35 | ] 36 | } ); 37 | -------------------------------------------------------------------------------- /tests/rules/no-ready-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-ready-shorthand' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer $() to .ready'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-ready-shorthand', rule, { 10 | valid: [ 11 | 'ready(fn)', 12 | '[].ready(fn)', 13 | 'div.ready(fn)', 14 | 'div.ready', 15 | '$.ready(fn)', 16 | '$(document).on("ready", fn)', 17 | '$(fn)' 18 | ], 19 | invalid: [ 20 | { 21 | code: '$(document).ready(fn)', 22 | errors: [ error ], 23 | output: '$(fn)' 24 | }, 25 | { 26 | code: '$div.ready(fn)', 27 | errors: [ error ], 28 | output: '$(fn)' 29 | }, 30 | { 31 | code: '$("div").first().ready(fn)', 32 | errors: [ error ], 33 | output: '$(fn)' 34 | }, 35 | // Can't fix if the result might be used 36 | { 37 | code: '$("div").append($("input").ready(fn))', 38 | errors: [ error ] 39 | }, 40 | { 41 | code: '$div = $("div").ready(fn)', 42 | errors: [ error ] 43 | } 44 | ] 45 | } ); 46 | -------------------------------------------------------------------------------- /tests/rules/no-ready.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-ready' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.ready is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-ready', rule, { 10 | valid: [ 11 | 'ready(function() { })', 12 | 'ready(()=>{})', 13 | 'ready()', 14 | '[].ready()', 15 | 'div.ready()', 16 | 'div.ready', 17 | '$.ready()', 18 | '$("div")', 19 | '$(document)', 20 | '$()' 21 | ], 22 | invalid: [ 23 | { 24 | code: '$(function() { })', 25 | errors: [ error ] 26 | }, 27 | { 28 | code: '$(function init() { })', 29 | errors: [ error ] 30 | }, 31 | { 32 | code: '$(() => {})', 33 | errors: [ error ] 34 | }, 35 | { 36 | code: '$(document).ready(function() { })', 37 | errors: [ error ] 38 | }, 39 | { 40 | code: '$().ready(function() { })', 41 | errors: [ error ] 42 | }, 43 | { 44 | code: '$("img").ready(function() { })', 45 | errors: [ error ] 46 | }, 47 | { 48 | code: '$div.ready(function() { })', 49 | errors: [ error ] 50 | }, 51 | { 52 | code: '$("img").first().ready(function() { })', 53 | errors: [ error ] 54 | } 55 | ] 56 | } ); 57 | -------------------------------------------------------------------------------- /tests/rules/no-selector-prop.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-selector-prop' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.selector is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-selector-prop', rule, { 10 | valid: [ 11 | 'selector', 12 | 'div.selector', 13 | '$div.prop.selector', 14 | '$div.selector()', 15 | '$div.selector(arg)' 16 | ], 17 | invalid: [ 18 | { 19 | code: '$("div").selector', 20 | errors: [ error ] 21 | }, 22 | { 23 | code: '$div.selector', 24 | errors: [ error ] 25 | }, 26 | { 27 | code: '$div.selector.prop', 28 | errors: [ error ] 29 | }, 30 | { 31 | code: '$div.selector.method()', 32 | errors: [ error ] 33 | }, 34 | { 35 | code: '$("div").first().selector', 36 | errors: [ error ] 37 | }, 38 | { 39 | code: 'f($div.selector)', 40 | errors: [ error ] 41 | }, 42 | { 43 | code: '$("div").append($("input").selector)', 44 | errors: [ error ] 45 | } 46 | ] 47 | } ); 48 | -------------------------------------------------------------------------------- /tests/rules/no-show.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-show' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.show is not allowed. This rule is deprecated, use no-visibility.'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-show', rule, { 10 | valid: [ 'show()', '[].show()', 'div.show()', 'div.show' ], 11 | invalid: [ 12 | { 13 | code: '$("div").show()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.show()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().show()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").show())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-size.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-size' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .length to .size'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-size', rule, { 10 | valid: [ 'size()', '[].size()', 'div.size()', 'div.size' ], 11 | invalid: [ 12 | { 13 | code: '$("div").size()', 14 | errors: [ error ], 15 | output: '$("div").length' 16 | }, 17 | { 18 | code: '$div.size()', 19 | errors: [ error ], 20 | output: '$div.length' 21 | }, 22 | { 23 | code: '$("div").first().size()', 24 | errors: [ error ], 25 | output: '$("div").first().length' 26 | }, 27 | { 28 | code: '$("div").append($("input").size())', 29 | errors: [ error ], 30 | output: '$("div").append($("input").length)' 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-sub.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-sub' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.sub is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-sub', rule, { 10 | valid: [ 'sub()', '"test".sub()', '"test".sub' ], 11 | invalid: [ 12 | { 13 | code: '$.sub()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-submit.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-submit' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer EventTarget#dispatchEvent + HTMLFormElement#submit to .submit. This rule is deprecated, use no-event-shorthand.'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-submit', rule, { 10 | valid: [ 'submit()', '[].submit()', 'form.submit()', 'form.submit' ], 11 | invalid: [ 12 | { 13 | code: '$("form").submit()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$form.submit()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("form").first().submit()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("form").append($("input").submit())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-support.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-support' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '$.support is not allowed'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-support', rule, { 10 | valid: [ 'support', 'a.support', 'support.foo', 'a.support.foo' ], 11 | invalid: [ 12 | { 13 | code: '$.support', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$.support.style', 18 | errors: [ error ] 19 | } 20 | ] 21 | } ); 22 | -------------------------------------------------------------------------------- /tests/rules/no-text.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-text' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Node#textContent to .text/$.text'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-text', rule, { 10 | valid: [ 'text()', '[].text()', 'div.text()', 'div.text' ], 11 | invalid: [ 12 | { 13 | code: '$.text()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$("div").text()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$div.text()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").first().text()', 26 | errors: [ error ] 27 | }, 28 | { 29 | code: '$("div").append($("input").text())', 30 | errors: [ error ] 31 | } 32 | ] 33 | } ); 34 | -------------------------------------------------------------------------------- /tests/rules/no-toggle.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-toggle' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = '.toggle is not allowed. This rule is deprecated, use no-visibility.'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-toggle', rule, { 10 | valid: [ 'toggle()', '[].toggle()', 'div.toggle()', 'div.toggle' ], 11 | invalid: [ 12 | { 13 | code: '$("div").toggle()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.toggle()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().toggle()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").toggle())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-trigger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-trigger' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer EventTarget#dispatchEvent to .trigger'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-trigger', rule, { 10 | valid: [ 'trigger()', '[].trigger()', 'div.trigger()', 'div.trigger' ], 11 | invalid: [ 12 | { 13 | code: '$("div").trigger()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.trigger()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().trigger()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").trigger())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-trim.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-trim' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer String#trim to $.trim'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-trim', rule, { 10 | valid: [ 11 | 'trim(" test ")', 12 | '" test ".trim()', 13 | '" test ".trim', 14 | '$("input").text().trim()', 15 | '$("input").data("foo").trim()' 16 | ], 17 | invalid: [ 18 | { 19 | code: '$.trim(" test ")', 20 | errors: [ error ] 21 | } 22 | ] 23 | } ); 24 | -------------------------------------------------------------------------------- /tests/rules/no-type.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-type' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer typeof/instanceof to $.type'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-type', rule, { 10 | valid: [ 'type()', 'myMethod.type()', 'myMethod.type' ], 11 | invalid: [ 12 | { 13 | code: '$.type()', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tests/rules/no-unbind.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-unbind' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .off/EventTarget#removeEventListener to .unbind. This rule is deprecated, use no-bind.'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-unbind', rule, { 10 | valid: [ 'unbind()', '[].unbind()', 'div.unbind()', 'div.unbind' ], 11 | invalid: [ 12 | { 13 | code: '$("div").unbind()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.unbind()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().unbind()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").unbind())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-undelegate.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-undelegate' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .off/EventTarget#removeEventListener to .undelegate. This rule is deprecated, use no-delegate.'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-undelegate', rule, { 10 | valid: [ 11 | 'undelegate()', 12 | '[].undelegate()', 13 | 'div.undelegate()', 14 | 'div.undelegate' 15 | ], 16 | invalid: [ 17 | { 18 | code: '$("div").undelegate()', 19 | errors: [ error ] 20 | }, 21 | { 22 | code: '$div.undelegate()', 23 | errors: [ error ] 24 | }, 25 | { 26 | code: '$("div").first().undelegate()', 27 | errors: [ error ] 28 | }, 29 | { 30 | code: '$("div").append($("input").undelegate())', 31 | errors: [ error ] 32 | } 33 | ] 34 | } ); 35 | -------------------------------------------------------------------------------- /tests/rules/no-unique.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-unique' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer $.uniqueSort to $.unique'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-unique', rule, { 10 | valid: [ 'unique()', '"test".unique()', '"test".unique' ], 11 | invalid: [ 12 | { 13 | code: '$.unique( [] )', 14 | errors: [ error ], 15 | output: '$.uniqueSort( [] )' 16 | } 17 | ] 18 | } ); 19 | -------------------------------------------------------------------------------- /tests/rules/no-unload-shorthand.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-unload-shorthand' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer .on or .trigger to .unload'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-unload-shorthand', rule, { 10 | valid: [ 11 | 'unload()', 12 | '[].unload()', 13 | 'div.unload()', 14 | 'div.unload', 15 | '$.unload()' 16 | ], 17 | invalid: [ 18 | { 19 | code: '$("div").unload(handler)', 20 | errors: [ error ], 21 | output: '$("div").on("unload", handler)' 22 | }, 23 | { 24 | code: '$div.unload()', 25 | errors: [ error ], 26 | output: '$div.trigger("unload")' 27 | }, 28 | { 29 | code: '$("div").first().unload()', 30 | errors: [ error ], 31 | output: '$("div").first().trigger("unload")' 32 | }, 33 | { 34 | code: '$("div").append($("input").unload())', 35 | errors: [ error ], 36 | output: '$("div").append($("input").trigger("unload"))' 37 | } 38 | ] 39 | } ); 40 | -------------------------------------------------------------------------------- /tests/rules/no-val.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-val' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer HTMLInputElement#value to .val'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-val', rule, { 10 | valid: [ 'val()', '[].val()', 'div.val()', 'div.val' ], 11 | invalid: [ 12 | { 13 | code: '$("div").val()', 14 | errors: [ error ] 15 | }, 16 | { 17 | code: '$div.val()', 18 | errors: [ error ] 19 | }, 20 | { 21 | code: '$("div").first().val()', 22 | errors: [ error ] 23 | }, 24 | { 25 | code: '$("div").append($("input").val())', 26 | errors: [ error ] 27 | } 28 | ] 29 | } ); 30 | -------------------------------------------------------------------------------- /tests/rules/no-when.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const rule = require( '../../src/rules/no-when' ); 4 | const RuleTester = require( '../../tools/rule-tester' ); 5 | 6 | const error = 'Prefer Promise.all to $.when'; 7 | 8 | const ruleTester = new RuleTester(); 9 | ruleTester.run( 'no-when', rule, { 10 | valid: [ 'When()', 'new When()', '"test".when()', '"test".when', '$when()' ], 11 | invalid: [ 12 | { 13 | code: '$.when(a,b)', 14 | errors: [ error ] 15 | } 16 | ] 17 | } ); 18 | -------------------------------------------------------------------------------- /tools/build-all-methods.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require( 'fs' ); 4 | const { JSDOM } = require( 'jsdom' ); 5 | const { window } = new JSDOM( '' ); 6 | const $ = require( 'jquery' )( window ); 7 | 8 | // Documented as "For internal use only" 9 | const internalMethods = [ 10 | 'push', 11 | 'sort', 12 | 'splice' 13 | ]; 14 | 15 | const allMethods = Object.keys( $.fn ) 16 | .filter( 17 | ( k ) => typeof $.fn[ k ] === 'function' && 18 | !internalMethods.includes( k ) 19 | ) 20 | .sort(); 21 | 22 | fs.writeFile( 23 | 'src/all-methods.js', 24 | '\'use strict\';\n\n' + 25 | '/* This file is built by build-all-methods.js; do not edit it directly. */\n' + 26 | 'module.exports = ' + 27 | JSON.stringify( allMethods, null, '\t' ).replace( /"/g, '\'' ) + 28 | ';\n', 29 | ( err ) => { 30 | if ( err ) { 31 | throw err; 32 | } 33 | } 34 | ); 35 | -------------------------------------------------------------------------------- /tools/rule-tester.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const RuleTester = require( 'eslint-docgen' ).RuleTester; 4 | 5 | RuleTester.setDefaultConfig( { 6 | parserOptions: { ecmaVersion: 2015 } 7 | } ); 8 | 9 | module.exports = RuleTester; 10 | --------------------------------------------------------------------------------