File tree Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Expand file tree Collapse file tree 4 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ Add `jquery` to the plugins section of your `.eslintrc` configuration file. You
49
49
"jquery/no-html" : 2 ,
50
50
"jquery/no-in-array" : 2 ,
51
51
"jquery/no-is" : 2 ,
52
+ "jquery/no-load" : 2 ,
52
53
"jquery/no-map" : 2 ,
53
54
"jquery/no-merge" : 2 ,
54
55
"jquery/no-param" : 2 ,
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ module.exports = {
23
23
'no-html' : require ( './rules/no-html' ) ,
24
24
'no-in-array' : require ( './rules/no-in-array' ) ,
25
25
'no-is' : require ( './rules/no-is' ) ,
26
+ 'no-load' : require ( './rules/no-load' ) ,
26
27
'no-map' : require ( './rules/no-map' ) ,
27
28
'no-merge' : require ( './rules/no-merge' ) ,
28
29
'no-param' : require ( './rules/no-param' ) ,
@@ -70,6 +71,7 @@ module.exports = {
70
71
"jquery/no-html" : 2 ,
71
72
"jquery/no-in-array" : 2 ,
72
73
"jquery/no-is" : 2 ,
74
+ "jquery/no-load" : 2 ,
73
75
"jquery/no-map" : 2 ,
74
76
"jquery/no-merge" : 2 ,
75
77
"jquery/no-param" : 2 ,
@@ -100,6 +102,7 @@ module.exports = {
100
102
"jquery/no-animate" : 2 ,
101
103
"jquery/no-fade" : 2 ,
102
104
"jquery/no-hide" : 2 ,
105
+ "jquery/no-load" : 2 ,
103
106
"jquery/no-param" : 2 ,
104
107
"jquery/no-serialize" : 2 ,
105
108
"jquery/no-show" : 2 ,
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const utils = require ( './utils.js' )
4
+
5
+ module . exports = function ( context ) {
6
+ return {
7
+ CallExpression : function ( node ) {
8
+ if ( node . callee . type !== 'MemberExpression' ) return
9
+ if ( node . callee . property . name !== 'load' ) return
10
+
11
+ if ( utils . isjQuery ( node ) ) {
12
+ context . report ( {
13
+ node : node ,
14
+ message : 'Prefer fetch to $.load'
15
+ } )
16
+ }
17
+ }
18
+ }
19
+ }
20
+
21
+ module . exports . schema = [ ]
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const rule = require ( '../rules/no-load' )
4
+ const RuleTester = require ( 'eslint' ) . RuleTester
5
+
6
+ const error = 'Prefer fetch to $.load'
7
+
8
+ const ruleTester = new RuleTester ( )
9
+ ruleTester . run ( 'no-load' , rule , {
10
+ valid : [
11
+ 'load()' ,
12
+ '[].load()' ,
13
+ 'div.load()' ,
14
+ 'div.load'
15
+ ] ,
16
+ invalid : [
17
+ {
18
+ code : '$("div").load()' ,
19
+ errors : [ { message : error , type : 'CallExpression' } ]
20
+ } ,
21
+ {
22
+ code : '$div.load()' ,
23
+ errors : [ { message : error , type : 'CallExpression' } ]
24
+ } ,
25
+ {
26
+ code : '$("div").first().load()' ,
27
+ errors : [ { message : error , type : 'CallExpression' } ]
28
+ } ,
29
+ {
30
+ code : '$("div").append($("input").load())' ,
31
+ errors : [ { message : error , type : 'CallExpression' } ]
32
+ }
33
+ ]
34
+ } )
You can’t perform that action at this time.
0 commit comments