eslint-plugin-no-jquery 2.6.0 → 2.7.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.
- package/Changelog.md +17 -0
- package/README.md +30 -26
- package/README.md.template +4 -1
- package/package.json +7 -7
- package/src/index.js +1 -0
- package/src/rules/no-ajax-events.js +5 -5
- package/src/rules/no-append-html.js +53 -0
- package/src/rules/no-event-shorthand.js +4 -4
- package/src/rules/no-html.js +2 -1
- package/src/rules/no-submit.js +2 -1
- package/src/rules/variable-pattern.js +2 -1
- package/src/utils.js +39 -5
package/Changelog.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# eslint-plugin-no-jquery release history
|
|
2
2
|
|
|
3
|
+
## v2.7.0
|
|
4
|
+
* New rule: `no-append-html` (#284) (Ed Sanders)
|
|
5
|
+
* New config: Allow rules to disable get/set separately, starting with no-html (Ed Sanders)
|
|
6
|
+
* Deprecated rule: `no-submit`; use `no-event-shorthand` (Ed Sanders)
|
|
7
|
+
|
|
8
|
+
—
|
|
9
|
+
* Code: Sort ajax events consistently and alphabetically. (Ed Sanders)
|
|
10
|
+
* Code: utils.isjQuery: Improve `Identifier` detection (#283) (Ed Sanders)
|
|
11
|
+
|
|
12
|
+
—
|
|
13
|
+
* Docs: Update eslint-docgen to 0.5.1 (#290) (Ed Sanders)
|
|
14
|
+
* Docs: Show which rules have options, and which are fixable in README (#289) (Ed Sanders)
|
|
15
|
+
* Docs: Fix test links (#280) (Ed Sanders)
|
|
16
|
+
|
|
17
|
+
—
|
|
18
|
+
* Release: Update devDependencies (#278) (Ed Sanders)
|
|
19
|
+
|
|
3
20
|
## v2.6.0
|
|
4
21
|
* New rule: `no-escape-selector` for `$.escapeSelector` util (Ed Sanders)
|
|
5
22
|
* New config: `deprecated-3.6` for new jQuery release (Ed Sanders)
|
package/README.md
CHANGED
|
@@ -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
|
-
|
|
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))
|
package/README.md.template
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Disallow jQuery functions with native equivalents.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"eslint": ">=2.3.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"codecov": "^3.8.
|
|
34
|
-
"eslint-config-wikimedia": "^0.
|
|
35
|
-
"eslint-docgen": "^0.
|
|
36
|
-
"eslint-plugin-eslint-plugin": "^
|
|
33
|
+
"codecov": "^3.8.3",
|
|
34
|
+
"eslint-config-wikimedia": "^0.20.0",
|
|
35
|
+
"eslint-docgen": "^0.5.1",
|
|
36
|
+
"eslint-plugin-eslint-plugin": "^3.6.1",
|
|
37
37
|
"eslint-plugin-self": "^1.2.1",
|
|
38
38
|
"jquery": "3.6.0",
|
|
39
|
-
"jsdom": "^16.
|
|
40
|
-
"mocha": "^8.
|
|
39
|
+
"jsdom": "^16.7.0",
|
|
40
|
+
"mocha": "^8.4.0",
|
|
41
41
|
"nyc": "^15.1.0"
|
|
42
42
|
},
|
|
43
43
|
"bugs": {
|
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' ),
|
|
@@ -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
|
-
'
|
|
7
|
+
'ajaxError',
|
|
8
|
+
'ajaxSend',
|
|
9
|
+
'ajaxStart',
|
|
10
|
+
'ajaxStop',
|
|
11
|
+
'ajaxSuccess'
|
|
12
12
|
];
|
|
13
13
|
|
|
14
14
|
module.exports = {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const utils = require( '../utils.js' );
|
|
4
|
+
const methods = [ 'append', 'prepend', 'before', 'after', 'replaceWith' ];
|
|
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: function ( context ) {
|
|
32
|
+
return {
|
|
33
|
+
'CallExpression:exit': function ( node ) {
|
|
34
|
+
if ( !(
|
|
35
|
+
node.callee.type === 'MemberExpression' &&
|
|
36
|
+
methods.includes( node.callee.property.name )
|
|
37
|
+
) ) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if ( node.arguments.every( ( arg ) => alljQueryOrEmpty( context, arg ) ) ) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if ( utils.isjQuery( context, node.callee ) ) {
|
|
45
|
+
context.report( {
|
|
46
|
+
node: node,
|
|
47
|
+
message: 'Avoid injection of possibly unescaped HTML. Create DOM elements instead, or use .text.'
|
|
48
|
+
} );
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
const utils = require( '../utils.js' );
|
|
4
4
|
|
|
5
5
|
const ajaxEvents = [
|
|
6
|
-
'ajaxStart',
|
|
7
|
-
'ajaxStop',
|
|
8
6
|
'ajaxComplete',
|
|
9
7
|
'ajaxError',
|
|
10
|
-
'
|
|
11
|
-
'
|
|
8
|
+
'ajaxSend',
|
|
9
|
+
'ajaxStart',
|
|
10
|
+
'ajaxStop',
|
|
11
|
+
'ajaxSuccess'
|
|
12
12
|
];
|
|
13
13
|
|
|
14
14
|
const rule = utils.createCollectionMethodRule(
|
package/src/rules/no-html.js
CHANGED
package/src/rules/no-submit.js
CHANGED
|
@@ -4,5 +4,6 @@ const utils = require( '../utils.js' );
|
|
|
4
4
|
|
|
5
5
|
module.exports = utils.createCollectionMethodRule(
|
|
6
6
|
'submit',
|
|
7
|
-
'Prefer `EventTarget#dispatchEvent` + `HTMLFormElement#submit` to `.submit`'
|
|
7
|
+
'Prefer `EventTarget#dispatchEvent` + `HTMLFormElement#submit` to `.submit`',
|
|
8
|
+
{ deprecated: [ 'no-event-shorthand' ] }
|
|
8
9
|
);
|
|
@@ -18,7 +18,8 @@ module.exports = {
|
|
|
18
18
|
// If the variable name is computed (e.g. foo[bar]) we
|
|
19
19
|
// can't be sure this is not correctly named.
|
|
20
20
|
!left.computed &&
|
|
21
|
-
|
|
21
|
+
// right can be null, e.g. `var x;`
|
|
22
|
+
right && utils.isjQuery( context, right )
|
|
22
23
|
) {
|
|
23
24
|
context.report( {
|
|
24
25
|
node: node,
|
package/src/utils.js
CHANGED
|
@@ -113,7 +113,7 @@ function traverse( context, node, variableTest, constructorTest ) {
|
|
|
113
113
|
|
|
114
114
|
break;
|
|
115
115
|
case 'MemberExpression':
|
|
116
|
-
if ( node.property && node.parent.type
|
|
116
|
+
if ( node.property && !( node.parent.type === 'CallExpression' && node.parent.callee === node ) ) {
|
|
117
117
|
if ( node.property.type === 'Identifier' ) {
|
|
118
118
|
if ( node.computed ) {
|
|
119
119
|
// e.g. foo[bar] can't be determined, returns false
|
|
@@ -132,7 +132,7 @@ function traverse( context, node, variableTest, constructorTest ) {
|
|
|
132
132
|
node = node.object;
|
|
133
133
|
break;
|
|
134
134
|
case 'Identifier':
|
|
135
|
-
if ( node.parent && node.parent.type === 'CallExpression' ) {
|
|
135
|
+
if ( node.parent && node.parent.type === 'CallExpression' && node.parent.callee === node ) {
|
|
136
136
|
return constructorTest( node );
|
|
137
137
|
} else {
|
|
138
138
|
return variableTest( node ) || constructorTest( node );
|
|
@@ -141,6 +141,8 @@ function traverse( context, node, variableTest, constructorTest ) {
|
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
/* istanbul ignore next */
|
|
145
|
+
throw new Error( 'Invalid node' );
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
function isjQueryConstructor( context, name ) {
|
|
@@ -193,9 +195,10 @@ function isjQuery( context, node ) {
|
|
|
193
195
|
* @param {string} [fixable] Fixable mode, e.g. 'code'
|
|
194
196
|
* @param {string[]|boolean} [deprecated] Rule is deprecated.
|
|
195
197
|
* If a string list, the replacedBy rules.
|
|
198
|
+
* @param {Array} schema Schema
|
|
196
199
|
* @return {Object} Rule
|
|
197
200
|
*/
|
|
198
|
-
function createRule( create, description, fixable, deprecated ) {
|
|
201
|
+
function createRule( create, description, fixable, deprecated, schema ) {
|
|
199
202
|
return {
|
|
200
203
|
meta: {
|
|
201
204
|
type: 'suggestion',
|
|
@@ -205,7 +208,7 @@ function createRule( create, description, fixable, deprecated ) {
|
|
|
205
208
|
replacedBy: Array.isArray( deprecated ) ? deprecated : undefined
|
|
206
209
|
},
|
|
207
210
|
fixable: fixable,
|
|
208
|
-
schema: []
|
|
211
|
+
schema: schema || []
|
|
209
212
|
},
|
|
210
213
|
create: create
|
|
211
214
|
};
|
|
@@ -296,6 +299,8 @@ function jQueryGlobalLink( name ) {
|
|
|
296
299
|
* @param {Function} [options.fix] Fixing function. First argument is `node`.
|
|
297
300
|
* @param {string[]|boolean} [options.deprecated] Rule is deprecated.
|
|
298
301
|
* If a string list, the replacedBy rules.
|
|
302
|
+
* @param {boolean} [options.getAndSetOptions] Create options to enabled getting and setting
|
|
303
|
+
* separately.
|
|
299
304
|
* @return {Object} Rule
|
|
300
305
|
*/
|
|
301
306
|
function createCollectionMethodRule( methods, message, options ) {
|
|
@@ -310,6 +315,27 @@ function createCollectionMethodRule( methods, message, options ) {
|
|
|
310
315
|
|
|
311
316
|
description += messageSuffix( message );
|
|
312
317
|
|
|
318
|
+
let schema = [];
|
|
319
|
+
if ( options.getAndSetOptions ) {
|
|
320
|
+
schema = [
|
|
321
|
+
{
|
|
322
|
+
type: 'object',
|
|
323
|
+
properties: {
|
|
324
|
+
allowGetOrSet: {
|
|
325
|
+
enum: [ 'none', 'get', 'set' ]
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
additionalProperties: false
|
|
329
|
+
}
|
|
330
|
+
];
|
|
331
|
+
|
|
332
|
+
// TODO: nonCollectionReturningValueAccessors have 1 argument in getter mode
|
|
333
|
+
description += '\n\nUsing this method only as a getter or a setter can be allowed using the `allowGetOrSet` option:\n' +
|
|
334
|
+
'* `"none"` (default) the method can\'t be used at all\n' +
|
|
335
|
+
'* `"get"` the method can only be used as a getter i.e. with no arguments\n' +
|
|
336
|
+
'* `"set"` the method can only be used as a setter i.e. with arguments';
|
|
337
|
+
}
|
|
338
|
+
|
|
313
339
|
return createRule( function ( context ) {
|
|
314
340
|
return {
|
|
315
341
|
'CallExpression:exit': function ( node ) {
|
|
@@ -323,6 +349,14 @@ function createCollectionMethodRule( methods, message, options ) {
|
|
|
323
349
|
) {
|
|
324
350
|
return;
|
|
325
351
|
}
|
|
352
|
+
const allowGetOrSet = ( context.options[ 0 ] && context.options[ 0 ].allowGetOrSet ) || 'none';
|
|
353
|
+
// TODO: nonCollectionReturningValueAccessors have 1 argument in getter mode
|
|
354
|
+
if (
|
|
355
|
+
( allowGetOrSet === 'get' && !node.arguments.length ) ||
|
|
356
|
+
( allowGetOrSet === 'set' && node.arguments.length )
|
|
357
|
+
) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
326
360
|
|
|
327
361
|
if ( isjQuery( context, node.callee ) ) {
|
|
328
362
|
context.report( {
|
|
@@ -333,7 +367,7 @@ function createCollectionMethodRule( methods, message, options ) {
|
|
|
333
367
|
}
|
|
334
368
|
}
|
|
335
369
|
};
|
|
336
|
-
}, description, options.fixable, options.deprecated );
|
|
370
|
+
}, description, options.fixable, options.deprecated, schema );
|
|
337
371
|
}
|
|
338
372
|
|
|
339
373
|
/**
|