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.
- package/README.md +31 -27
- package/README.md.template +5 -2
- package/package.json +13 -10
- package/src/.eslintrc.js +17 -0
- package/src/all-methods.js +2 -1
- package/src/index.js +5 -1
- package/src/rules/no-ajax-events.js +31 -33
- package/src/rules/no-ajax.js +1 -1
- package/src/rules/no-and-self.js +1 -3
- package/src/rules/no-animate-toggle.js +3 -3
- package/src/rules/no-animate.js +28 -30
- package/src/rules/no-append-html.js +51 -0
- package/src/rules/no-class-state.js +16 -18
- package/src/rules/no-class.js +1 -1
- package/src/rules/no-constructor-attributes.js +21 -23
- package/src/rules/no-data.js +1 -1
- package/src/rules/no-deferred.js +2 -2
- package/src/rules/no-error.js +1 -3
- package/src/rules/no-escape-selector.js +1 -3
- package/src/rules/no-event-shorthand.js +7 -7
- package/src/rules/no-extend.js +28 -26
- package/src/rules/no-fade.js +1 -1
- package/src/rules/no-fx-interval.js +13 -15
- package/src/rules/no-global-selector.js +39 -41
- package/src/rules/no-html.js +2 -1
- package/src/rules/no-is-array.js +1 -3
- package/src/rules/no-is-function.js +1 -1
- package/src/rules/no-jquery-constructor.js +13 -15
- package/src/rules/no-load-shorthand.js +17 -19
- package/src/rules/no-noop.js +1 -3
- package/src/rules/no-now.js +1 -3
- package/src/rules/no-on-ready.js +29 -34
- package/src/rules/no-other-methods.js +19 -21
- package/src/rules/no-other-utils.js +18 -20
- package/src/rules/no-parse-html-literal.js +60 -67
- package/src/rules/no-parse-json.js +1 -3
- package/src/rules/no-parse-xml.js +1 -1
- package/src/rules/no-prop.js +1 -1
- package/src/rules/no-proxy.js +1 -1
- package/src/rules/no-ready-shorthand.js +1 -1
- package/src/rules/no-ready.js +9 -11
- package/src/rules/no-serialize.js +1 -1
- package/src/rules/no-size.js +1 -3
- package/src/rules/no-sizzle.js +5 -5
- package/src/rules/no-slide.js +1 -1
- package/src/rules/no-submit.js +2 -1
- package/src/rules/no-unique.js +1 -3
- package/src/rules/no-visibility.js +1 -1
- package/src/rules/no-wrap.js +1 -1
- package/src/rules/variable-pattern.js +6 -5
- package/src/utils.js +138 -114
- package/Changelog.md +0 -342
|
@@ -56,89 +56,82 @@ module.exports = {
|
|
|
56
56
|
]
|
|
57
57
|
},
|
|
58
58
|
|
|
59
|
-
create:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
message = 'Prefer DOM building to parsing HTML literals';
|
|
59
|
+
create: ( context ) => ( {
|
|
60
|
+
'CallExpression:exit': ( node ) => {
|
|
61
|
+
let allowSingle,
|
|
62
|
+
message = 'Prefer DOM building to parsing HTML literals';
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
if ( node.callee.type === 'Identifier' ) {
|
|
65
|
+
if ( !(
|
|
66
|
+
utils.isjQueryConstructor( context, node.callee.name ) &&
|
|
68
67
|
node.arguments[ 0 ] &&
|
|
69
68
|
(
|
|
70
69
|
node.arguments[ 0 ].type === 'Literal' ||
|
|
71
70
|
node.arguments[ 0 ].type === 'BinaryExpression'
|
|
72
71
|
)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
) ) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
allowSingle = true;
|
|
76
|
+
} else if ( node.callee.type === 'MemberExpression' ) {
|
|
77
|
+
if (
|
|
78
|
+
utils.isjQueryConstructor( context, node.callee.object.name ) &&
|
|
80
79
|
node.callee.property.name === 'parseHTML'
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
) {
|
|
81
|
+
allowSingle = false;
|
|
82
|
+
} else if (
|
|
83
|
+
[ 'html', 'append', 'add' ].includes( node.callee.property.name ) &&
|
|
85
84
|
utils.isjQuery( context, node )
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} else {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
85
|
+
) {
|
|
86
|
+
allowSingle = true;
|
|
91
87
|
} else {
|
|
92
88
|
return;
|
|
93
89
|
}
|
|
90
|
+
} else {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
} else {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
} else if ( singleTagStyle === 'self-closing' ) {
|
|
115
|
-
if ( !rsingleTagSelfClosing.exec( value ) ) {
|
|
116
|
-
expectedTag = '<' + match[ 1 ] + '/>';
|
|
117
|
-
message = 'Single tag must use the format: ' + expectedTag;
|
|
118
|
-
} else {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
94
|
+
let expectedTag;
|
|
95
|
+
const arg = node.arguments[ 0 ];
|
|
96
|
+
if ( allowSingle ) {
|
|
97
|
+
const value = arg && allLiteral( arg ) && joinLiterals( arg );
|
|
98
|
+
if ( !( typeof value === 'string' && value ) || !rquickExpr.exec( value ) ) {
|
|
99
|
+
// Empty or non-string, or non-HTML
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
let match;
|
|
103
|
+
if ( ( match = rsingleTag.exec( value ) ) ) {
|
|
104
|
+
// Single tag
|
|
105
|
+
const singleTagStyle = ( context.options[ 0 ] && context.options[ 0 ].singleTagStyle ) || 'minimal';
|
|
106
|
+
if ( singleTagStyle === 'minimal' ) {
|
|
107
|
+
if ( !rsingleTagMinimal.exec( value ) ) {
|
|
108
|
+
expectedTag = '<' + match[ 1 ] + '>';
|
|
109
|
+
message = 'Single tag must use the format: ' + expectedTag;
|
|
121
110
|
} else {
|
|
122
|
-
// singleTagStyle === 'any'
|
|
123
111
|
return;
|
|
124
112
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
context.report( {
|
|
132
|
-
node: node,
|
|
133
|
-
message: message,
|
|
134
|
-
fix: function ( fixer ) {
|
|
135
|
-
if ( expectedTag ) {
|
|
136
|
-
return fixer.replaceText( arg, '"' + expectedTag + '"' );
|
|
113
|
+
} else if ( singleTagStyle === 'self-closing' ) {
|
|
114
|
+
if ( !rsingleTagSelfClosing.exec( value ) ) {
|
|
115
|
+
expectedTag = '<' + match[ 1 ] + '/>';
|
|
116
|
+
message = 'Single tag must use the format: ' + expectedTag;
|
|
117
|
+
} else {
|
|
118
|
+
return;
|
|
137
119
|
}
|
|
138
|
-
|
|
120
|
+
} else {
|
|
121
|
+
// singleTagStyle === 'any'
|
|
122
|
+
return;
|
|
139
123
|
}
|
|
140
|
-
}
|
|
124
|
+
}
|
|
125
|
+
} else if ( !( arg && allLiteral( arg ) ) ) {
|
|
126
|
+
// Non literals passed to $.parseHTML
|
|
127
|
+
return;
|
|
141
128
|
}
|
|
142
|
-
|
|
143
|
-
|
|
129
|
+
|
|
130
|
+
context.report( {
|
|
131
|
+
node,
|
|
132
|
+
message,
|
|
133
|
+
fix: ( fixer ) => expectedTag ? fixer.replaceText( arg, '"' + expectedTag + '"' ) : null
|
|
134
|
+
} );
|
|
135
|
+
}
|
|
136
|
+
} )
|
|
144
137
|
};
|
|
@@ -7,8 +7,6 @@ module.exports = utils.createUtilMethodRule(
|
|
|
7
7
|
'Prefer `JSON.parse` to `$.parseJSON`',
|
|
8
8
|
{
|
|
9
9
|
fixable: 'code',
|
|
10
|
-
fix:
|
|
11
|
-
return fixer.replaceText( node.callee, 'JSON.parse' );
|
|
12
|
-
}
|
|
10
|
+
fix: ( node, context, fixer ) => fixer.replaceText( node.callee, 'JSON.parse' )
|
|
13
11
|
}
|
|
14
12
|
);
|
|
@@ -7,7 +7,7 @@ module.exports = utils.createUtilMethodRule(
|
|
|
7
7
|
'Prefer `DOMParser#parseFromString` to `$.parseXML`',
|
|
8
8
|
{
|
|
9
9
|
fixable: 'code',
|
|
10
|
-
fix:
|
|
10
|
+
fix: ( node, context, fixer ) => {
|
|
11
11
|
if ( node.arguments.length ) {
|
|
12
12
|
return [
|
|
13
13
|
fixer.replaceText( node.callee, '( new window.DOMParser() ).parseFromString' ),
|
package/src/rules/no-prop.js
CHANGED
|
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionOrUtilMethodRule(
|
|
|
6
6
|
[ 'prop', 'removeProp' ],
|
|
7
7
|
( node ) => node === true ?
|
|
8
8
|
'Prefer direct property access' :
|
|
9
|
-
`Prefer direct property access to .${node.callee.property.name}/$.${node.callee.property.name}`
|
|
9
|
+
`Prefer direct property access to .${ node.callee.property.name }/$.${ node.callee.property.name }`
|
|
10
10
|
);
|
package/src/rules/no-proxy.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = utils.createUtilMethodRule(
|
|
|
7
7
|
'Prefer `Function#bind` to `$.proxy`',
|
|
8
8
|
{
|
|
9
9
|
fixable: 'code',
|
|
10
|
-
fix:
|
|
10
|
+
fix: ( node, context, fixer ) => {
|
|
11
11
|
if (
|
|
12
12
|
node.arguments.length >= 2 &&
|
|
13
13
|
node.arguments[ 1 ].type !== 'Literal'
|
|
@@ -7,7 +7,7 @@ module.exports = utils.createCollectionMethodRule(
|
|
|
7
7
|
'Prefer `$()` to `.ready`',
|
|
8
8
|
{
|
|
9
9
|
fixable: 'code',
|
|
10
|
-
fix:
|
|
10
|
+
fix: ( node, context, fixer ) => {
|
|
11
11
|
if ( node.parent.type === 'ExpressionStatement' ) {
|
|
12
12
|
return fixer.replaceText( node.callee, '$' );
|
|
13
13
|
}
|
package/src/rules/no-ready.js
CHANGED
|
@@ -30,16 +30,14 @@ module.exports = {
|
|
|
30
30
|
schema: []
|
|
31
31
|
},
|
|
32
32
|
|
|
33
|
-
create:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} );
|
|
41
|
-
}
|
|
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
|
+
} );
|
|
42
40
|
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
41
|
+
}
|
|
42
|
+
} )
|
|
45
43
|
};
|
|
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionMethodRule(
|
|
|
6
6
|
[ 'serialize', 'serializeArray' ],
|
|
7
7
|
( node ) => node === true ?
|
|
8
8
|
'Prefer `FormData` or `URLSearchParams`' :
|
|
9
|
-
`Prefer FormData or URLSearchParams to .${node.callee.property.name}`
|
|
9
|
+
`Prefer FormData or URLSearchParams to .${ node.callee.property.name }`
|
|
10
10
|
);
|
package/src/rules/no-size.js
CHANGED
|
@@ -7,8 +7,6 @@ module.exports = utils.createCollectionMethodRule(
|
|
|
7
7
|
'Prefer `.length` to `.size`',
|
|
8
8
|
{
|
|
9
9
|
fixable: 'code',
|
|
10
|
-
fix:
|
|
11
|
-
return fixer.replaceTextRange( [ node.callee.property.range[ 0 ], node.range[ 1 ] ], 'length' );
|
|
12
|
-
}
|
|
10
|
+
fix: ( node, context, fixer ) => fixer.replaceTextRange( [ node.callee.property.range[ 0 ], node.range[ 1 ] ], 'length' )
|
|
13
11
|
}
|
|
14
12
|
);
|
package/src/rules/no-sizzle.js
CHANGED
|
@@ -39,8 +39,8 @@ module.exports = {
|
|
|
39
39
|
]
|
|
40
40
|
},
|
|
41
41
|
|
|
42
|
-
create:
|
|
43
|
-
const forbiddenPositional = /:eq|:even|:first([^-]|$)|:gt|:last([^-]|$)|:lt|:nth|:odd/;
|
|
42
|
+
create: ( context ) => {
|
|
43
|
+
const forbiddenPositional = /:eq|:even|:first([^-]|$)|:gt|:last([^-]|$)|:lt|:nth([^-]|$)|:odd/;
|
|
44
44
|
const forbiddenOther = /:animated|:button|:checkbox|:file|:has|:header|:hidden|:image|:input|:parent|:password|:radio|:reset|:selected|:submit|:text|:visible/;
|
|
45
45
|
const traversals = [
|
|
46
46
|
'children',
|
|
@@ -63,7 +63,7 @@ module.exports = {
|
|
|
63
63
|
];
|
|
64
64
|
|
|
65
65
|
return {
|
|
66
|
-
'CallExpression:exit':
|
|
66
|
+
'CallExpression:exit': ( node ) => {
|
|
67
67
|
if (
|
|
68
68
|
!node.arguments[ 0 ] ||
|
|
69
69
|
!utils.isjQuery( context, node.callee ) ||
|
|
@@ -83,12 +83,12 @@ module.exports = {
|
|
|
83
83
|
|
|
84
84
|
if ( !allowPositional && forbiddenPositional.test( value ) ) {
|
|
85
85
|
context.report( {
|
|
86
|
-
node
|
|
86
|
+
node,
|
|
87
87
|
message: 'Positional selector extensions are not allowed'
|
|
88
88
|
} );
|
|
89
89
|
} else if ( !allowOther && forbiddenOther.test( value ) ) {
|
|
90
90
|
context.report( {
|
|
91
|
-
node
|
|
91
|
+
node,
|
|
92
92
|
message: 'Selector extensions are not allowed'
|
|
93
93
|
} );
|
|
94
94
|
}
|
package/src/rules/no-slide.js
CHANGED
|
@@ -6,5 +6,5 @@ module.exports = utils.createCollectionMethodRule(
|
|
|
6
6
|
[ 'slideDown', 'slideToggle', 'slideUp' ],
|
|
7
7
|
( node ) => node === true ?
|
|
8
8
|
'Prefer CSS transitions' :
|
|
9
|
-
`Prefer CSS transitions to .${node.callee.property.name}`
|
|
9
|
+
`Prefer CSS transitions to .${ node.callee.property.name }`
|
|
10
10
|
);
|
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
|
);
|
package/src/rules/no-unique.js
CHANGED
|
@@ -7,8 +7,6 @@ module.exports = utils.createUtilMethodRule(
|
|
|
7
7
|
'Prefer `$.uniqueSort` to `$.unique`',
|
|
8
8
|
{
|
|
9
9
|
fixable: 'code',
|
|
10
|
-
fix:
|
|
11
|
-
return fixer.replaceText( node.callee.property, 'uniqueSort' );
|
|
12
|
-
}
|
|
10
|
+
fix: ( node, context, fixer ) => fixer.replaceText( node.callee.property, 'uniqueSort' )
|
|
13
11
|
}
|
|
14
12
|
);
|
package/src/rules/no-wrap.js
CHANGED
|
@@ -5,5 +5,5 @@ const utils = require( '../utils.js' );
|
|
|
5
5
|
module.exports = utils.createCollectionMethodRule(
|
|
6
6
|
[ 'wrap', 'wrapAll', 'wrapInner', 'unwrap' ],
|
|
7
7
|
( node ) => node === true ? '' :
|
|
8
|
-
`.${node.callee.property.name} is not allowed`
|
|
8
|
+
`.${ node.callee.property.name } is not allowed`
|
|
9
9
|
);
|
|
@@ -11,27 +11,28 @@ module.exports = {
|
|
|
11
11
|
schema: []
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
create:
|
|
14
|
+
create: ( context ) => {
|
|
15
15
|
function test( node, left, right ) {
|
|
16
16
|
if (
|
|
17
17
|
!utils.isjQuery( context, left ) &&
|
|
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
|
-
node
|
|
25
|
+
node,
|
|
25
26
|
message: 'jQuery collection names must match the variablePattern'
|
|
26
27
|
} );
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
return {
|
|
31
|
-
'AssignmentExpression:exit':
|
|
32
|
+
'AssignmentExpression:exit': ( node ) => {
|
|
32
33
|
test( node, node.left, node.right );
|
|
33
34
|
},
|
|
34
|
-
'VariableDeclarator:exit':
|
|
35
|
+
'VariableDeclarator:exit': ( node ) => {
|
|
35
36
|
test( node, node.id, node.init );
|
|
36
37
|
}
|
|
37
38
|
};
|