-
Notifications
You must be signed in to change notification settings - Fork 8
/
no-class-state.js
60 lines (55 loc) · 1.24 KB
/
no-class-state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const rule = require( '../../src/rules/no-class-state' );
const RuleTester = require( '../../tools/rule-tester' );
const error = 'Where possible, maintain application state in JS to avoid slower DOM queries';
const ruleTester = new RuleTester();
ruleTester.run( 'no-class-state', rule, {
valid: [
'hasClass()',
'[].hasClass()',
'div.hasClass()',
'div.hasClass',
'toggleClass()',
'[].toggleClass()',
'div.toggleClass()',
'div.toggleClass',
// These are equivalent to addClass/removeClass and so
// don't query the DOM for state information.
'$div.toggleClass("myClass", true)',
'$div.toggleClass("myClass", false)'
],
invalid: [
{
code: '$("div").hasClass()',
errors: [ error ]
},
{
code: '$div.hasClass()',
errors: [ error ]
},
{
code: '$("div").first().hasClass()',
errors: [ error ]
},
{
code: '$("div").append($("input").hasClass())',
errors: [ error ]
},
{
code: '$("div").toggleClass("myClass")',
errors: [ error ]
},
{
code: '$div.toggleClass("myClass")',
errors: [ error ]
},
{
code: '$("div").first().toggleClass("myClass")',
errors: [ error ]
},
{
code: '$("div").append($("input").toggleClass("myClass"))',
errors: [ error ]
}
]
} );