eslint-plugin-no-jquery 2.6.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +31 -27
  2. package/README.md.template +5 -2
  3. package/package.json +13 -10
  4. package/src/.eslintrc.js +17 -0
  5. package/src/all-methods.js +2 -1
  6. package/src/index.js +5 -1
  7. package/src/rules/no-ajax-events.js +31 -33
  8. package/src/rules/no-ajax.js +1 -1
  9. package/src/rules/no-and-self.js +1 -3
  10. package/src/rules/no-animate-toggle.js +3 -3
  11. package/src/rules/no-animate.js +28 -30
  12. package/src/rules/no-append-html.js +51 -0
  13. package/src/rules/no-class-state.js +16 -18
  14. package/src/rules/no-class.js +1 -1
  15. package/src/rules/no-constructor-attributes.js +21 -23
  16. package/src/rules/no-data.js +1 -1
  17. package/src/rules/no-deferred.js +2 -2
  18. package/src/rules/no-error.js +1 -3
  19. package/src/rules/no-escape-selector.js +1 -3
  20. package/src/rules/no-event-shorthand.js +7 -7
  21. package/src/rules/no-extend.js +28 -26
  22. package/src/rules/no-fade.js +1 -1
  23. package/src/rules/no-fx-interval.js +13 -15
  24. package/src/rules/no-global-selector.js +39 -41
  25. package/src/rules/no-html.js +2 -1
  26. package/src/rules/no-is-array.js +1 -3
  27. package/src/rules/no-is-function.js +1 -1
  28. package/src/rules/no-jquery-constructor.js +13 -15
  29. package/src/rules/no-load-shorthand.js +17 -19
  30. package/src/rules/no-noop.js +1 -3
  31. package/src/rules/no-now.js +1 -3
  32. package/src/rules/no-on-ready.js +29 -34
  33. package/src/rules/no-other-methods.js +19 -21
  34. package/src/rules/no-other-utils.js +18 -20
  35. package/src/rules/no-parse-html-literal.js +60 -67
  36. package/src/rules/no-parse-json.js +1 -3
  37. package/src/rules/no-parse-xml.js +1 -1
  38. package/src/rules/no-prop.js +1 -1
  39. package/src/rules/no-proxy.js +1 -1
  40. package/src/rules/no-ready-shorthand.js +1 -1
  41. package/src/rules/no-ready.js +9 -11
  42. package/src/rules/no-serialize.js +1 -1
  43. package/src/rules/no-size.js +1 -3
  44. package/src/rules/no-sizzle.js +5 -5
  45. package/src/rules/no-slide.js +1 -1
  46. package/src/rules/no-submit.js +2 -1
  47. package/src/rules/no-unique.js +1 -3
  48. package/src/rules/no-visibility.js +1 -1
  49. package/src/rules/no-wrap.js +1 -1
  50. package/src/rules/variable-pattern.js +6 -5
  51. package/src/utils.js +138 -114
  52. package/Changelog.md +0 -342
package/README.md CHANGED
@@ -38,7 +38,7 @@ Add `no-jquery` to the plugins section of your `.eslintrc` configuration file. Y
38
38
 
39
39
  The config **`plugin:no-jquery/recommended`** includes the recommended rule [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) which is required for method rules to work correctly.
40
40
 
41
- The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.6`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
41
+ The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.7`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
42
42
 
43
43
  The config **`plugin:no-jquery/slim`** includes all features excluded from the official "slim" build of jQuery, specifically the [ajax](https://api.jquery.com/category/ajax/) and [effects](https://api.jquery.com/category/effects/) modules.
44
44
 
@@ -81,12 +81,16 @@ The following global settings can be used under the `no-jquery` property to conf
81
81
 
82
82
  ## 📖 Rules
83
83
 
84
- Where rules are included in the configs `recommended`, `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included with options this is indicated with a `†`.
84
+ Rules with options are indicated with ⚙️. Rules which are fixable are indicated with 🔧.
85
+
86
+ Where rules are included in the configs `recommended`, `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included in a config with non-default options this is indicated with a `†`.
87
+
85
88
  * [`no-jquery/no-ajax`](docs/rules/no-ajax.md) `slim`, `all`
86
89
  * [`no-jquery/no-ajax-events`](docs/rules/no-ajax-events.md) `slim`
87
- * [`no-jquery/no-and-self`](docs/rules/no-and-self.md) `1.8`
88
- * [`no-jquery/no-animate`](docs/rules/no-animate.md) `slim`, `all`
90
+ * [`no-jquery/no-and-self`](docs/rules/no-and-self.md) 🔧 `1.8`
91
+ * [`no-jquery/no-animate`](docs/rules/no-animate.md) ⚙️ `slim`, `all`
89
92
  * [`no-jquery/no-animate-toggle`](docs/rules/no-animate-toggle.md) `slim`
93
+ * [`no-jquery/no-append-html`](docs/rules/no-append-html.md)
90
94
  * [`no-jquery/no-attr`](docs/rules/no-attr.md) `all`
91
95
  * [`no-jquery/no-bind`](docs/rules/no-bind.md) `3.0`, `all`
92
96
  * [`no-jquery/no-box-model`](docs/rules/no-box-model.md) `1.3`
@@ -106,11 +110,11 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
106
110
  * [`no-jquery/no-each`](docs/rules/no-each.md)
107
111
  * [`no-jquery/no-each-collection`](docs/rules/no-each-collection.md) `all`
108
112
  * [`no-jquery/no-each-util`](docs/rules/no-each-util.md) `all`
109
- * [`no-jquery/no-error`](docs/rules/no-error.md) `all`
110
- * [`no-jquery/no-error-shorthand`](docs/rules/no-error-shorthand.md) `1.8`
111
- * [`no-jquery/no-escape-selector`](docs/rules/no-escape-selector.md) `all`
112
- * [`no-jquery/no-event-shorthand`](docs/rules/no-event-shorthand.md) `3.5`, `3.3†`, `all`
113
- * [`no-jquery/no-extend`](docs/rules/no-extend.md) `all`
113
+ * [`no-jquery/no-error`](docs/rules/no-error.md) 🔧 `all`
114
+ * [`no-jquery/no-error-shorthand`](docs/rules/no-error-shorthand.md) 🔧 `1.8`
115
+ * [`no-jquery/no-escape-selector`](docs/rules/no-escape-selector.md) 🔧 `all`
116
+ * [`no-jquery/no-event-shorthand`](docs/rules/no-event-shorthand.md) ⚙️ 🔧 `3.5`, `3.3†`, `all`
117
+ * [`no-jquery/no-extend`](docs/rules/no-extend.md) ⚙️ 🔧 `all`
114
118
  * [`no-jquery/no-fade`](docs/rules/no-fade.md) `slim`, `all`
115
119
  * [`no-jquery/no-filter`](docs/rules/no-filter.md) `all`
116
120
  * [`no-jquery/no-find`](docs/rules/no-find.md)
@@ -118,58 +122,57 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
118
122
  * [`no-jquery/no-find-util`](docs/rules/no-find-util.md) `all`
119
123
  * [`no-jquery/no-fx-interval`](docs/rules/no-fx-interval.md) `3.0`
120
124
  * [`no-jquery/no-global-eval`](docs/rules/no-global-eval.md) `all`
121
- * [`no-jquery/no-global-selector`](docs/rules/no-global-selector.md)
125
+ * [`no-jquery/no-global-selector`](docs/rules/no-global-selector.md) ⚙️
122
126
  * [`no-jquery/no-grep`](docs/rules/no-grep.md) `all`
123
127
  * [`no-jquery/no-has`](docs/rules/no-has.md) `all`
124
128
  * [`no-jquery/no-hold-ready`](docs/rules/no-hold-ready.md) `3.2`, `all`
125
- * [`no-jquery/no-html`](docs/rules/no-html.md) `all`
129
+ * [`no-jquery/no-html`](docs/rules/no-html.md) ⚙️ `all`
126
130
  * [`no-jquery/no-in-array`](docs/rules/no-in-array.md) `all`
127
131
  * [`no-jquery/no-is`](docs/rules/no-is.md) `all`
128
- * [`no-jquery/no-is-array`](docs/rules/no-is-array.md) `3.2`, `all`
132
+ * [`no-jquery/no-is-array`](docs/rules/no-is-array.md) 🔧 `3.2`, `all`
129
133
  * [`no-jquery/no-is-empty-object`](docs/rules/no-is-empty-object.md) `all`
130
- * [`no-jquery/no-is-function`](docs/rules/no-is-function.md) `3.3`, `all`
134
+ * [`no-jquery/no-is-function`](docs/rules/no-is-function.md) 🔧 `3.3`, `all`
131
135
  * [`no-jquery/no-is-numeric`](docs/rules/no-is-numeric.md) `3.3`, `all`
132
136
  * [`no-jquery/no-is-plain-object`](docs/rules/no-is-plain-object.md) `all`
133
137
  * [`no-jquery/no-is-window`](docs/rules/no-is-window.md) `3.3`, `all`
134
138
  * [`no-jquery/no-jquery-constructor`](docs/rules/no-jquery-constructor.md) `all`
135
139
  * [`no-jquery/no-live`](docs/rules/no-live.md) `1.7`, `all`
136
140
  * [`no-jquery/no-load`](docs/rules/no-load.md) `slim`, `all`
137
- * [`no-jquery/no-load-shorthand`](docs/rules/no-load-shorthand.md) `1.8`
141
+ * [`no-jquery/no-load-shorthand`](docs/rules/no-load-shorthand.md) 🔧 `1.8`
138
142
  * [`no-jquery/no-map`](docs/rules/no-map.md)
139
143
  * [`no-jquery/no-map-collection`](docs/rules/no-map-collection.md) `all`
140
144
  * [`no-jquery/no-map-util`](docs/rules/no-map-util.md) `all`
141
145
  * [`no-jquery/no-merge`](docs/rules/no-merge.md) `all`
142
146
  * [`no-jquery/no-node-name`](docs/rules/no-node-name.md) `3.2`, `all`
143
- * [`no-jquery/no-noop`](docs/rules/no-noop.md) `all`
144
- * [`no-jquery/no-now`](docs/rules/no-now.md) `3.3`, `all`
145
- * [`no-jquery/no-on-ready`](docs/rules/no-on-ready.md) `1.8`
147
+ * [`no-jquery/no-noop`](docs/rules/no-noop.md) 🔧 `all`
148
+ * [`no-jquery/no-now`](docs/rules/no-now.md) 🔧 `3.3`, `all`
149
+ * [`no-jquery/no-on-ready`](docs/rules/no-on-ready.md) 🔧 `1.8`
146
150
  * [`no-jquery/no-other-methods`](docs/rules/no-other-methods.md) `all`
147
151
  * [`no-jquery/no-other-utils`](docs/rules/no-other-utils.md) `all`
148
152
  * [`no-jquery/no-param`](docs/rules/no-param.md) `all`
149
153
  * [`no-jquery/no-parent`](docs/rules/no-parent.md) `all`
150
154
  * [`no-jquery/no-parents`](docs/rules/no-parents.md) `all`
151
155
  * [`no-jquery/no-parse-html`](docs/rules/no-parse-html.md) `all`
152
- * [`no-jquery/no-parse-html-literal`](docs/rules/no-parse-html-literal.md)
153
- * [`no-jquery/no-parse-json`](docs/rules/no-parse-json.md) `3.0`, `all`
154
- * [`no-jquery/no-parse-xml`](docs/rules/no-parse-xml.md) `slim`, `all`
156
+ * [`no-jquery/no-parse-html-literal`](docs/rules/no-parse-html-literal.md) ⚙️ 🔧
157
+ * [`no-jquery/no-parse-json`](docs/rules/no-parse-json.md) 🔧 `3.0`, `all`
158
+ * [`no-jquery/no-parse-xml`](docs/rules/no-parse-xml.md) 🔧 `slim`, `all`
155
159
  * [`no-jquery/no-prop`](docs/rules/no-prop.md) `all`
156
- * [`no-jquery/no-proxy`](docs/rules/no-proxy.md) `3.3`, `all`
160
+ * [`no-jquery/no-proxy`](docs/rules/no-proxy.md) 🔧 `3.3`, `all`
157
161
  * [`no-jquery/no-ready`](docs/rules/no-ready.md)
158
- * [`no-jquery/no-ready-shorthand`](docs/rules/no-ready-shorthand.md) `3.0`, `all`
162
+ * [`no-jquery/no-ready-shorthand`](docs/rules/no-ready-shorthand.md) 🔧 `3.0`, `all`
159
163
  * [`no-jquery/no-selector-prop`](docs/rules/no-selector-prop.md) `1.7`
160
164
  * [`no-jquery/no-serialize`](docs/rules/no-serialize.md) `all`
161
- * [`no-jquery/no-size`](docs/rules/no-size.md) `1.8`, `all`
162
- * [`no-jquery/no-sizzle`](docs/rules/no-sizzle.md) `3.4†`
165
+ * [`no-jquery/no-size`](docs/rules/no-size.md) 🔧 `1.8`, `all`
166
+ * [`no-jquery/no-sizzle`](docs/rules/no-sizzle.md) ⚙️ `3.4†`
163
167
  * [`no-jquery/no-slide`](docs/rules/no-slide.md) `slim`, `all`
164
168
  * [`no-jquery/no-sub`](docs/rules/no-sub.md) `1.7`, `all`
165
- * [`no-jquery/no-submit`](docs/rules/no-submit.md)
166
169
  * [`no-jquery/no-support`](docs/rules/no-support.md) `1.9`
167
170
  * [`no-jquery/no-text`](docs/rules/no-text.md) `all`
168
171
  * [`no-jquery/no-trigger`](docs/rules/no-trigger.md) `all`
169
172
  * [`no-jquery/no-trim`](docs/rules/no-trim.md) `3.5`, `all`
170
173
  * [`no-jquery/no-type`](docs/rules/no-type.md) `3.3`, `all`
171
- * [`no-jquery/no-unique`](docs/rules/no-unique.md) `3.0`, `all`
172
- * [`no-jquery/no-unload-shorthand`](docs/rules/no-unload-shorthand.md) `1.8`
174
+ * [`no-jquery/no-unique`](docs/rules/no-unique.md) 🔧 `3.0`, `all`
175
+ * [`no-jquery/no-unload-shorthand`](docs/rules/no-unload-shorthand.md) 🔧 `1.8`
173
176
  * [`no-jquery/no-val`](docs/rules/no-val.md) `all`
174
177
  * [`no-jquery/no-visibility`](docs/rules/no-visibility.md) `all`
175
178
  * [`no-jquery/no-when`](docs/rules/no-when.md) `all`
@@ -181,6 +184,7 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
181
184
  * [`no-jquery/no-die`](docs/rules/no-die.md) (use [`no-jquery/no-live`](docs/rules/no-live.md))
182
185
  * [`no-jquery/no-hide`](docs/rules/no-hide.md) (use [`no-jquery/no-visibility`](docs/rules/no-visibility.md))
183
186
  * [`no-jquery/no-show`](docs/rules/no-show.md) (use [`no-jquery/no-visibility`](docs/rules/no-visibility.md))
187
+ * [`no-jquery/no-submit`](docs/rules/no-submit.md) (use [`no-jquery/no-event-shorthand`](docs/rules/no-event-shorthand.md))
184
188
  * [`no-jquery/no-toggle`](docs/rules/no-toggle.md) (use [`no-jquery/no-visibility`](docs/rules/no-visibility.md))
185
189
  * [`no-jquery/no-unbind`](docs/rules/no-unbind.md) (use [`no-jquery/no-bind`](docs/rules/no-bind.md))
186
190
  * [`no-jquery/no-undelegate`](docs/rules/no-undelegate.md) (use [`no-jquery/no-delegate`](docs/rules/no-delegate.md))
@@ -37,7 +37,7 @@ Add `no-jquery` to the plugins section of your `.eslintrc` configuration file. Y
37
37
 
38
38
  The config **`plugin:no-jquery/recommended`** includes the recommended rule [`no-jquery/variable-pattern`](docs/rules/variable-pattern.md) which is required for method rules to work correctly.
39
39
 
40
- The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.6`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
40
+ The config **`plugin:no-jquery/deprecated`** includes all known deprecated and removed code, and is updated as new releases of jQuery come out. You can instead use configs targeting specific versions of jQuery if you know the environment in which your code will operate. There is a config for all minor versions from 1.0 to 3.6 (`deprecated-1.0`, ..., `deprecated-3.7`). Deprecation configs are cumulative, so they include all the rules for jQuery versions below them.
41
41
 
42
42
  The config **`plugin:no-jquery/slim`** includes all features excluded from the official "slim" build of jQuery, specifically the [ajax](https://api.jquery.com/category/ajax/) and [effects](https://api.jquery.com/category/effects/) modules.
43
43
 
@@ -80,7 +80,10 @@ The following global settings can be used under the `no-jquery` property to conf
80
80
 
81
81
  ## 📖 Rules
82
82
 
83
- Where rules are included in the configs `recommended`, `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included with options this is indicated with a `†`.
83
+ Rules with options are indicated with ⚙️. Rules which are fixable are indicated with 🔧.
84
+
85
+ Where rules are included in the configs `recommended`, `slim`, `all` or `deprecated-X.X` it is indicated below. Where rules are included in a config with non-default options this is indicated with a `†`.
86
+
84
87
  <!-- rules -->
85
88
 
86
89
  ### ⚠️ Deprecated
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-no-jquery",
3
- "version": "2.6.0",
3
+ "version": "3.0.0",
4
4
  "description": "Disallow jQuery functions with native equivalents.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "pretest": "eslint --report-unused-disable-directives .",
18
18
  "test": "nyc mocha --reporter dot tests/** && git diff --exit-code docs/ src/ README.md",
19
- "onlytest": "mocha --reporter dot tests/** --nofix",
19
+ "onlytest": "mocha --reporter dot tests/**",
20
20
  "report": "nyc report --reporter=text-lcov > coverage.lcov",
21
21
  "reporthtml": "nyc report --reporter=html",
22
22
  "testpath": "mocha",
@@ -26,18 +26,21 @@
26
26
  "files": [
27
27
  "src"
28
28
  ],
29
+ "engine": {
30
+ "node": ">=16"
31
+ },
29
32
  "peerDependencies": {
30
- "eslint": ">=2.3.0"
33
+ "eslint": ">=8.0.0"
31
34
  },
32
35
  "devDependencies": {
33
- "codecov": "^3.8.1",
34
- "eslint-config-wikimedia": "^0.19.0",
35
- "eslint-docgen": "^0.4.5",
36
- "eslint-plugin-eslint-plugin": "^2.3.0",
36
+ "codecov": "^3.8.3",
37
+ "eslint-config-wikimedia": "^0.28.0",
38
+ "eslint-docgen": "^0.7.1",
39
+ "eslint-plugin-eslint-plugin": "^6.1.0",
37
40
  "eslint-plugin-self": "^1.2.1",
38
- "jquery": "3.6.0",
39
- "jsdom": "^16.5.2",
40
- "mocha": "^8.3.2",
41
+ "jquery": "3.7.1",
42
+ "jsdom": "^22.1.0",
43
+ "mocha": "^10.2.0",
41
44
  "nyc": "^15.1.0"
42
45
  },
43
46
  "bugs": {
@@ -0,0 +1,17 @@
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
+ };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- <!-- This file is built by build-all-methods.js; do not edit it directly. -->
3
+ /* This file is built by build-all-methods.js; do not edit it directly. */
4
4
  module.exports = [
5
5
  'add',
6
6
  'addBack',
@@ -135,6 +135,7 @@ module.exports = [
135
135
  'triggerHandler',
136
136
  'unbind',
137
137
  'undelegate',
138
+ 'uniqueSort',
138
139
  'unwrap',
139
140
  'val',
140
141
  'width',
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ module.exports = {
7
7
  'no-and-self': require( './rules/no-and-self' ),
8
8
  'no-animate': require( './rules/no-animate' ),
9
9
  'no-animate-toggle': require( './rules/no-animate-toggle' ),
10
+ 'no-append-html': require( './rules/no-append-html' ),
10
11
  'no-attr': require( './rules/no-attr' ),
11
12
  'no-bind': require( './rules/no-bind' ),
12
13
  'no-box-model': require( './rules/no-box-model' ),
@@ -125,9 +126,12 @@ module.exports = {
125
126
  },
126
127
  // Use this config if you want to avoid all known deprecated jQuery tools.
127
128
  deprecated: {
129
+ extends: 'plugin:no-jquery/deprecated-3.7'
130
+ },
131
+ // Use this config if you're writing code targetting jQuery 3.7.x environments.
132
+ 'deprecated-3.7': {
128
133
  extends: 'plugin:no-jquery/deprecated-3.6'
129
134
  },
130
- // Use this config if you're writing code targetting jQuery 3.6.x environments.
131
135
  'deprecated-3.6': {
132
136
  extends: 'plugin:no-jquery/deprecated-3.5'
133
137
  },
@@ -3,12 +3,12 @@
3
3
  const utils = require( '../utils.js' );
4
4
 
5
5
  const disallowedEvents = [
6
- 'ajaxStart',
7
- 'ajaxSend',
8
- 'ajaxSuccess',
9
- 'ajaxError',
10
6
  'ajaxComplete',
11
- 'ajaxStop'
7
+ 'ajaxError',
8
+ 'ajaxSend',
9
+ 'ajaxStart',
10
+ 'ajaxStop',
11
+ 'ajaxSuccess'
12
12
  ];
13
13
 
14
14
  module.exports = {
@@ -20,36 +20,34 @@ module.exports = {
20
20
  schema: []
21
21
  },
22
22
 
23
- create: function ( context ) {
24
- return {
25
- 'CallExpression:exit': function ( node ) {
26
- if ( node.callee.type !== 'MemberExpression' ) {
27
- return;
28
- }
29
- let usedMethod;
30
- if (
31
- node.callee.property.name === 'on' &&
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' &&
32
31
  node.arguments.length >= 1
33
- ) {
34
- const arg = node.arguments[ 0 ];
35
- if (
36
- arg.type === 'Literal' &&
32
+ ) {
33
+ const arg = node.arguments[ 0 ];
34
+ if (
35
+ arg.type === 'Literal' &&
37
36
  disallowedEvents.includes( arg.value )
38
- ) {
39
- usedMethod = arg.value;
40
- }
41
- }
42
- if ( disallowedEvents.includes( node.callee.property.name ) ) {
43
- usedMethod = node.callee.property.name;
44
- }
45
- if ( usedMethod && utils.isjQuery( context, node ) ) {
46
- context.report( {
47
- node: node,
48
- message: 'Prefer local event to {{method}}',
49
- data: { method: usedMethod }
50
- } );
37
+ ) {
38
+ usedMethod = arg.value;
51
39
  }
52
40
  }
53
- };
54
- }
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
+ } )
55
53
  };
@@ -6,5 +6,5 @@ module.exports = utils.createUtilMethodRule(
6
6
  [ 'ajax', 'get', 'getJSON', 'getScript', 'post' ],
7
7
  ( node ) => node === true ?
8
8
  'Prefer `Window.fetch`' :
9
- `Prefer Window.fetch to $.${node.callee.property.name}`
9
+ `Prefer Window.fetch to $.${ node.callee.property.name }`
10
10
  );
@@ -7,8 +7,6 @@ module.exports = utils.createCollectionMethodRule(
7
7
  'Prefer `.addBack` to `.andSelf`',
8
8
  {
9
9
  fixable: 'code',
10
- fix: function ( node, context, fixer ) {
11
- return fixer.replaceText( node.callee.property, 'addBack' );
12
- }
10
+ fix: ( node, context, fixer ) => fixer.replaceText( node.callee.property, 'addBack' )
13
11
  }
14
12
  );
@@ -14,11 +14,11 @@ module.exports = {
14
14
  schema: []
15
15
  },
16
16
 
17
- create: function ( context ) {
17
+ create: ( context ) => {
18
18
  const forbidden = [ 'show', 'hide', 'toggle' ];
19
19
 
20
20
  return {
21
- 'CallExpression:exit': function ( node ) {
21
+ 'CallExpression:exit': ( node ) => {
22
22
  if (
23
23
  node.callee.type !== 'MemberExpression' ||
24
24
  !forbidden.includes( node.callee.property.name ) ||
@@ -45,7 +45,7 @@ module.exports = {
45
45
 
46
46
  if ( utils.isjQuery( context, node ) ) {
47
47
  context.report( {
48
- node: node,
48
+ node,
49
49
  message: 'Prefer CSS transitions to .{{method}}',
50
50
  data: { method: node.callee.property.name }
51
51
  } );
@@ -23,39 +23,37 @@ module.exports = {
23
23
  ]
24
24
  },
25
25
 
26
- create: function ( context ) {
27
- return {
28
- 'CallExpression:exit': function ( node ) {
29
- if (
30
- node.callee.type !== 'MemberExpression' ||
26
+ create: ( context ) => ( {
27
+ 'CallExpression:exit': ( node ) => {
28
+ if (
29
+ node.callee.type !== 'MemberExpression' ||
31
30
  node.callee.property.name !== 'animate'
32
- ) {
33
- return;
34
- }
35
- const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll;
36
- if ( allowScroll ) {
37
- const arg = node.arguments[ 0 ];
38
- // Check properties list has more than just scrollTop/scrollLeft
39
- if ( arg && arg.type === 'ObjectExpression' ) {
40
- if (
41
- arg.properties.every(
42
- ( prop ) => prop.key.name === 'scrollTop' || prop.key.name === 'scrollLeft'
43
- )
44
- ) {
45
- return;
46
- }
31
+ ) {
32
+ return;
33
+ }
34
+ const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll;
35
+ if ( allowScroll ) {
36
+ const arg = node.arguments[ 0 ];
37
+ // Check properties list has more than just scrollTop/scrollLeft
38
+ if ( arg && arg.type === 'ObjectExpression' ) {
39
+ if (
40
+ arg.properties.every(
41
+ ( prop ) => prop.key.name === 'scrollTop' || prop.key.name === 'scrollLeft'
42
+ )
43
+ ) {
44
+ return;
47
45
  }
48
46
  }
47
+ }
49
48
 
50
- if ( utils.isjQuery( context, node ) ) {
51
- context.report( {
52
- node: node,
53
- message: allowScroll ?
54
- 'Prefer CSS transitions to .animate' :
55
- 'Prefer CSS transitions or CSS scroll-behaviour to .animate'
56
- } );
57
- }
49
+ if ( utils.isjQuery( context, node ) ) {
50
+ context.report( {
51
+ node,
52
+ message: allowScroll ?
53
+ 'Prefer CSS transitions to .animate' :
54
+ 'Prefer CSS transitions or CSS scroll-behaviour to .animate'
55
+ } );
58
56
  }
59
- };
60
- }
57
+ }
58
+ } )
61
59
  };
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ const utils = require( '../utils.js' );
4
+ const methods = [ 'append', 'prepend', 'before', 'after', 'replaceWith', 'add', 'appendTo', 'prependTo' ];
5
+
6
+ function alljQueryOrEmpty( context, node ) {
7
+ if ( node.type === 'ConditionalExpression' ) {
8
+ return alljQueryOrEmpty( context, node.consequent ) &&
9
+ alljQueryOrEmpty( context, node.alternate );
10
+ } else if ( node.type === 'Literal' ) {
11
+ return node.value === null || (
12
+ typeof node.value === 'string' && node.value.match( /^\s*$/ )
13
+ );
14
+ } else if ( node.type === 'Identifier' && node.name === 'undefined' ) {
15
+ return true;
16
+ } else {
17
+ return utils.isjQuery( context, node );
18
+ }
19
+ }
20
+
21
+ module.exports = {
22
+ meta: {
23
+ type: 'suggestion',
24
+ docs: {
25
+ description: 'Disallows using ' + methods.map( utils.jQueryCollectionLink ).join( '/' ) +
26
+ ' to inject HTML, in order to prevent possible XSS bugs.'
27
+ },
28
+ schema: []
29
+ },
30
+
31
+ create: ( context ) => ( {
32
+ 'CallExpression:exit': ( node ) => {
33
+ if ( !(
34
+ node.callee.type === 'MemberExpression' &&
35
+ methods.includes( node.callee.property.name )
36
+ ) ) {
37
+ return;
38
+ }
39
+ if ( node.arguments.every( ( arg ) => alljQueryOrEmpty( context, arg ) ) ) {
40
+ return;
41
+ }
42
+
43
+ if ( utils.isjQuery( context, node.callee ) ) {
44
+ context.report( {
45
+ node,
46
+ message: 'Avoid injection of possibly unescaped HTML. Create DOM elements instead, or use .text.'
47
+ } );
48
+ }
49
+ }
50
+ } )
51
+ };
@@ -15,12 +15,11 @@ module.exports = {
15
15
  schema: []
16
16
  },
17
17
 
18
- create: function ( context ) {
19
- return {
20
- 'CallExpression:exit': function ( node ) {
21
- if ( !(
22
- node.callee.type === 'MemberExpression' && (
23
- node.callee.property.name === 'hasClass' ||
18
+ create: ( context ) => ( {
19
+ 'CallExpression:exit': ( node ) => {
20
+ if ( !(
21
+ node.callee.type === 'MemberExpression' && (
22
+ node.callee.property.name === 'hasClass' ||
24
23
  // toggleClass with one argument will check if the
25
24
  // class is already in the DOM before deciding what to do,
26
25
  // so it is equivalent to using hasClass.
@@ -28,18 +27,17 @@ module.exports = {
28
27
  node.callee.property.name === 'toggleClass' &&
29
28
  node.arguments.length === 1
30
29
  )
31
- )
32
- ) ) {
33
- return;
34
- }
30
+ )
31
+ ) ) {
32
+ return;
33
+ }
35
34
 
36
- if ( utils.isjQuery( context, node.callee ) ) {
37
- context.report( {
38
- node: node,
39
- message: 'Where possible, maintain application state in JS to avoid slower DOM queries'
40
- } );
41
- }
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
+ } );
42
40
  }
43
- };
44
- }
41
+ }
42
+ } )
45
43
  };
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionMethodRule(
6
6
  [ 'addClass', 'hasClass', 'removeClass', 'toggleClass' ],
7
7
  ( node ) => node === true ?
8
8
  'Prefer `Element#classList`' :
9
- `Prefer Element#classList to .${node.callee.property.name}`
9
+ `Prefer Element#classList to .${ node.callee.property.name }`
10
10
  );
@@ -11,35 +11,33 @@ module.exports = {
11
11
  schema: []
12
12
  },
13
13
 
14
- create: function ( context ) {
15
- return {
16
- 'CallExpression:exit': function ( node ) {
17
- if ( node.callee.type === 'MemberExpression' ) {
18
- if ( !(
19
- node.callee.property.name === 'add' &&
14
+ create: ( context ) => ( {
15
+ 'CallExpression:exit': ( node ) => {
16
+ if ( node.callee.type === 'MemberExpression' ) {
17
+ if ( !(
18
+ node.callee.property.name === 'add' &&
20
19
  utils.isjQuery( context, node.callee ) &&
21
20
  node.arguments[ 1 ] &&
22
21
  node.arguments[ 1 ].type === 'ObjectExpression'
23
- ) ) {
24
- return;
25
- }
26
- } else if ( node.callee.type === 'Identifier' ) {
27
- if ( !(
28
- utils.isjQueryConstructor( context, node.callee.name ) &&
22
+ ) ) {
23
+ return;
24
+ }
25
+ } else if ( node.callee.type === 'Identifier' ) {
26
+ if ( !(
27
+ utils.isjQueryConstructor( context, node.callee.name ) &&
29
28
  node.arguments[ 1 ] &&
30
29
  node.arguments[ 1 ].type === 'ObjectExpression'
31
- ) ) {
32
- return;
33
- }
34
- } else {
30
+ ) ) {
35
31
  return;
36
32
  }
37
-
38
- context.report( {
39
- node: node,
40
- message: 'Prefer .attr to constructor attributes'
41
- } );
33
+ } else {
34
+ return;
42
35
  }
43
- };
44
- }
36
+
37
+ context.report( {
38
+ node,
39
+ message: 'Prefer .attr to constructor attributes'
40
+ } );
41
+ }
42
+ } )
45
43
  };
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionOrUtilMethodRule(
6
6
  [ 'data', 'removeData', 'hasData' ],
7
7
  ( node ) => node === true ?
8
8
  'Prefer `WeakMap`' :
9
- `Prefer WeakMap to .${node.callee.property.name}/$.${node.callee.property.name}`
9
+ `Prefer WeakMap to .${ node.callee.property.name }/$.${ node.callee.property.name }`
10
10
  );
@@ -11,7 +11,7 @@ module.exports = {
11
11
  schema: []
12
12
  },
13
13
 
14
- create: function ( context ) {
14
+ create: ( context ) => {
15
15
  function enforce( node ) {
16
16
  if (
17
17
  node.callee.type !== 'MemberExpression' ||
@@ -22,7 +22,7 @@ module.exports = {
22
22
  }
23
23
 
24
24
  context.report( {
25
- node: node,
25
+ node,
26
26
  message: 'Prefer Promise to $.Deferred'
27
27
  } );
28
28
  }