eslint-plugin-jest-dom 2.0.1 → 2.1.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/.eslintrc.json +3 -4
- package/README.md +1 -0
- package/build/generate-readme-table.js +14 -14
- package/docs/rules/prefer-to-have-text-content.md +40 -0
- package/jest.config.js +5 -5
- package/lib/createBannedAttributeRule.js +13 -13
- package/lib/index.js +7 -7
- package/lib/rules/prefer-checked.js +10 -10
- package/lib/rules/prefer-empty.js +48 -51
- package/lib/rules/prefer-enabled-disabled.js +10 -10
- package/lib/rules/prefer-focus.js +24 -24
- package/lib/rules/prefer-required.js +10 -10
- package/lib/rules/prefer-to-have-attribute.js +28 -28
- package/lib/rules/prefer-to-have-text-content.js +110 -0
- package/package.json +2 -1
- package/tests/__snapshots__/index.test.js.snap +10 -0
- package/tests/fixtures/createBannedAttributeTestCases.js +51 -51
- package/tests/index.test.js +5 -5
- package/tests/lib/rules/no-attribute-checking.js +18 -18
- package/tests/lib/rules/prefer-empty.js +67 -67
- package/tests/lib/rules/prefer-focus.js +57 -57
- package/tests/lib/rules/prefer-to-have-attribute.js +63 -63
- package/tests/lib/rules/prefer-to-have-text-content.js +118 -0
- package/.prettierrc.json +0 -4
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview prefer toHaveFocus over checking activeElementa
|
|
3
3
|
* @author Ben Monro
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
7
|
const variantsOfDoc = [
|
|
8
8
|
// document:
|
|
@@ -10,17 +10,17 @@ const variantsOfDoc = [
|
|
|
10
10
|
// window.document || global.document:
|
|
11
11
|
`[object.object.name=/(global|window)$/][object.property.name=document]`,
|
|
12
12
|
// global.window.document:
|
|
13
|
-
`[object.object.object.name='global'][object.object.property.name='window'][object.property.name=document]
|
|
13
|
+
`[object.object.object.name='global'][object.object.property.name='window'][object.property.name=document]`
|
|
14
14
|
];
|
|
15
15
|
|
|
16
16
|
module.exports = {
|
|
17
17
|
meta: {
|
|
18
18
|
docs: {
|
|
19
|
-
description:
|
|
20
|
-
category:
|
|
21
|
-
recommended: true
|
|
19
|
+
description: "prefer toHaveFocus over checking document.activeElement",
|
|
20
|
+
category: "jest-dom",
|
|
21
|
+
recommended: true
|
|
22
22
|
},
|
|
23
|
-
fixable:
|
|
23
|
+
fixable: "code"
|
|
24
24
|
},
|
|
25
25
|
|
|
26
26
|
create: function(context) {
|
|
@@ -30,7 +30,7 @@ module.exports = {
|
|
|
30
30
|
variant =>
|
|
31
31
|
`MemberExpression${variant}[property.name='activeElement'][parent.parent.object.callee.name='expect'][parent.parent.property.name='not'][parent.parent.parent.property.name=/to(Be|(Strict)?Equal)$/]`
|
|
32
32
|
)
|
|
33
|
-
.join(
|
|
33
|
+
.join(", ")](node) {
|
|
34
34
|
const element =
|
|
35
35
|
node.parent.parent.parent.parent.callee.parent.arguments[0];
|
|
36
36
|
const matcher = node.parent.parent.parent.parent.callee.property;
|
|
@@ -43,18 +43,18 @@ module.exports = {
|
|
|
43
43
|
return [
|
|
44
44
|
fixer.replaceText(node, element.name),
|
|
45
45
|
fixer.remove(element),
|
|
46
|
-
fixer.replaceText(matcher,
|
|
46
|
+
fixer.replaceText(matcher, "toHaveFocus")
|
|
47
47
|
];
|
|
48
48
|
} else {
|
|
49
49
|
return [
|
|
50
50
|
fixer.removeRange([node.range[0], element.range[0]]),
|
|
51
51
|
fixer.insertTextAfterRange(
|
|
52
52
|
[element.range[1], element.range[1] + 1],
|
|
53
|
-
|
|
54
|
-
)
|
|
53
|
+
".not.toHaveFocus()"
|
|
54
|
+
)
|
|
55
55
|
];
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
}
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
60
|
[variantsOfDoc
|
|
@@ -62,7 +62,7 @@ module.exports = {
|
|
|
62
62
|
variant =>
|
|
63
63
|
`MemberExpression${variant}[property.name='activeElement'][parent.callee.object.object.callee.name='expect'][parent.callee.property.name=/to(Be|(Strict)?Equal)$/]`
|
|
64
64
|
)
|
|
65
|
-
.join(
|
|
65
|
+
.join(", ")](node) {
|
|
66
66
|
const matcher = node.parent.callee.property;
|
|
67
67
|
context.report({
|
|
68
68
|
node: node.parent,
|
|
@@ -70,9 +70,9 @@ module.exports = {
|
|
|
70
70
|
fix(fixer) {
|
|
71
71
|
return [
|
|
72
72
|
fixer.remove(node),
|
|
73
|
-
fixer.replaceText(matcher,
|
|
73
|
+
fixer.replaceText(matcher, "toHaveFocus")
|
|
74
74
|
];
|
|
75
|
-
}
|
|
75
|
+
}
|
|
76
76
|
});
|
|
77
77
|
},
|
|
78
78
|
[variantsOfDoc
|
|
@@ -80,7 +80,7 @@ module.exports = {
|
|
|
80
80
|
variant =>
|
|
81
81
|
`MemberExpression${variant}[property.name='activeElement'][parent.callee.name='expect'][parent.parent.property.name=/to(Be|(Strict)?Equal)$/]`
|
|
82
82
|
)
|
|
83
|
-
.join(
|
|
83
|
+
.join(", ")](node) {
|
|
84
84
|
const element = node.parent.parent.parent.arguments[0];
|
|
85
85
|
const matcher = node.parent.parent.property;
|
|
86
86
|
context.report({
|
|
@@ -92,16 +92,16 @@ module.exports = {
|
|
|
92
92
|
fixer.removeRange([node.range[0], element.range[0]]),
|
|
93
93
|
fixer.insertTextAfterRange(
|
|
94
94
|
[element.range[1], element.range[1] + 1],
|
|
95
|
-
|
|
96
|
-
)
|
|
95
|
+
".toHaveFocus()"
|
|
96
|
+
)
|
|
97
97
|
];
|
|
98
98
|
}
|
|
99
99
|
return [
|
|
100
100
|
fixer.replaceText(node, element.name),
|
|
101
101
|
fixer.remove(element),
|
|
102
|
-
fixer.replaceText(matcher,
|
|
102
|
+
fixer.replaceText(matcher, "toHaveFocus")
|
|
103
103
|
];
|
|
104
|
-
}
|
|
104
|
+
}
|
|
105
105
|
});
|
|
106
106
|
},
|
|
107
107
|
[variantsOfDoc
|
|
@@ -109,7 +109,7 @@ module.exports = {
|
|
|
109
109
|
variant =>
|
|
110
110
|
`MemberExpression${variant}[property.name='activeElement'][parent.callee.object.callee.name='expect'][parent.callee.property.name=/to(Be|(Strict)?Equal)$/]`
|
|
111
111
|
)
|
|
112
|
-
.join(
|
|
112
|
+
.join(", ")](node) {
|
|
113
113
|
const matcher = node.parent.callee.property;
|
|
114
114
|
context.report({
|
|
115
115
|
node: node.parent,
|
|
@@ -117,11 +117,11 @@ module.exports = {
|
|
|
117
117
|
fix(fixer) {
|
|
118
118
|
return [
|
|
119
119
|
fixer.remove(node),
|
|
120
|
-
fixer.replaceText(matcher,
|
|
120
|
+
fixer.replaceText(matcher, "toHaveFocus")
|
|
121
121
|
];
|
|
122
|
-
}
|
|
122
|
+
}
|
|
123
123
|
});
|
|
124
|
-
}
|
|
124
|
+
}
|
|
125
125
|
};
|
|
126
|
-
}
|
|
126
|
+
}
|
|
127
127
|
};
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
* @fileoverview prefer toBeDisabled or toBeEnabled over attribute checks
|
|
3
3
|
* @author Ben Monro
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
|
-
const createBannedAttributeRule = require(
|
|
7
|
+
const createBannedAttributeRule = require("../createBannedAttributeRule");
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
10
10
|
meta: {
|
|
11
11
|
docs: {
|
|
12
|
-
description:
|
|
13
|
-
category:
|
|
12
|
+
description: "prefer toBeRequired over checking properties",
|
|
13
|
+
category: "jest-dom",
|
|
14
14
|
recommended: true,
|
|
15
|
-
url:
|
|
15
|
+
url: "prefer-required"
|
|
16
16
|
},
|
|
17
|
-
fixable:
|
|
17
|
+
fixable: "code"
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
create: createBannedAttributeRule({
|
|
21
|
-
preferred:
|
|
22
|
-
negatedPreferred:
|
|
23
|
-
attributes: [
|
|
24
|
-
})
|
|
21
|
+
preferred: "toBeRequired",
|
|
22
|
+
negatedPreferred: "not.toBeRequired",
|
|
23
|
+
attributes: ["required", "aria-required"]
|
|
24
|
+
})
|
|
25
25
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview prefer toHaveAttribute over checking getAttribute/hasAttribute
|
|
3
3
|
* @author Ben Monro
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
"use strict";
|
|
6
6
|
|
|
7
7
|
//------------------------------------------------------------------------------
|
|
8
8
|
// Rule Definition
|
|
@@ -12,10 +12,10 @@ module.exports = {
|
|
|
12
12
|
meta: {
|
|
13
13
|
docs: {
|
|
14
14
|
description:
|
|
15
|
-
|
|
16
|
-
recommended: true
|
|
15
|
+
"prefer toHaveAttribute over checking getAttribute/hasAttribute ",
|
|
16
|
+
recommended: true
|
|
17
17
|
},
|
|
18
|
-
fixable:
|
|
18
|
+
fixable: "code"
|
|
19
19
|
},
|
|
20
20
|
|
|
21
21
|
create: function(context) {
|
|
@@ -32,12 +32,12 @@ module.exports = {
|
|
|
32
32
|
fixer.replaceTextRange(
|
|
33
33
|
[
|
|
34
34
|
node.parent.parent.property.range[0],
|
|
35
|
-
node.parent.parent.parent.range[1]
|
|
35
|
+
node.parent.parent.parent.range[1]
|
|
36
36
|
],
|
|
37
37
|
`not.toHaveAttribute(${node.arguments[0].raw})`
|
|
38
|
-
)
|
|
38
|
+
)
|
|
39
39
|
];
|
|
40
|
-
}
|
|
40
|
+
}
|
|
41
41
|
});
|
|
42
42
|
},
|
|
43
43
|
[`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toContain$|toMatch$/]`](
|
|
@@ -49,7 +49,7 @@ module.exports = {
|
|
|
49
49
|
fix(fixer) {
|
|
50
50
|
return [
|
|
51
51
|
fixer.removeRange([node.callee.object.range[1], node.range[1]]),
|
|
52
|
-
fixer.replaceText(node.parent.parent.property,
|
|
52
|
+
fixer.replaceText(node.parent.parent.property, "toHaveAttribute"),
|
|
53
53
|
fixer.replaceText(
|
|
54
54
|
node.parent.parent.parent.arguments[0],
|
|
55
55
|
`${
|
|
@@ -57,9 +57,9 @@ module.exports = {
|
|
|
57
57
|
}, expect.string${node.parent.parent.property.name.slice(
|
|
58
58
|
2
|
|
59
59
|
)}ing(${node.parent.parent.parent.arguments[0].raw})`
|
|
60
|
-
)
|
|
60
|
+
)
|
|
61
61
|
];
|
|
62
|
-
}
|
|
62
|
+
}
|
|
63
63
|
});
|
|
64
64
|
},
|
|
65
65
|
[`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](
|
|
@@ -67,7 +67,7 @@ module.exports = {
|
|
|
67
67
|
) {
|
|
68
68
|
const arg = node.parent.parent.parent.arguments;
|
|
69
69
|
const isNullOrEmpty =
|
|
70
|
-
arg.length > 0 && (arg[0].value === null || arg[0].value ===
|
|
70
|
+
arg.length > 0 && (arg[0].value === null || arg[0].value === "");
|
|
71
71
|
|
|
72
72
|
context.report({
|
|
73
73
|
node: node.parent,
|
|
@@ -89,11 +89,11 @@ module.exports = {
|
|
|
89
89
|
fixer.removeRange([node.callee.object.range[1], node.range[1]]),
|
|
90
90
|
fixer.replaceText(
|
|
91
91
|
node.parent.parent.property,
|
|
92
|
-
`${isNullOrEmpty ?
|
|
92
|
+
`${isNullOrEmpty ? "not." : ""}toHaveAttribute`
|
|
93
93
|
),
|
|
94
|
-
lastFixer
|
|
94
|
+
lastFixer
|
|
95
95
|
];
|
|
96
|
-
}
|
|
96
|
+
}
|
|
97
97
|
});
|
|
98
98
|
},
|
|
99
99
|
[`CallExpression[callee.property.name='hasAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBeNull|toBeUndefined|toBeDefined/]`](
|
|
@@ -101,7 +101,7 @@ module.exports = {
|
|
|
101
101
|
) {
|
|
102
102
|
context.report({
|
|
103
103
|
node: node.parent.parent.property,
|
|
104
|
-
message:
|
|
104
|
+
message: "Invalid matcher for hasAttribute"
|
|
105
105
|
});
|
|
106
106
|
},
|
|
107
107
|
[`CallExpression[callee.property.name='getAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBeUndefined|toBeDefined/]`](
|
|
@@ -109,13 +109,13 @@ module.exports = {
|
|
|
109
109
|
) {
|
|
110
110
|
context.report({
|
|
111
111
|
node: node.parent.parent.property,
|
|
112
|
-
message:
|
|
112
|
+
message: "Invalid matcher for getAttribute"
|
|
113
113
|
});
|
|
114
114
|
},
|
|
115
115
|
[`CallExpression[callee.property.name='hasAttribute'][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Striclty)?Equal/]`](
|
|
116
116
|
node
|
|
117
117
|
) {
|
|
118
|
-
if (typeof node.parent.parent.parent.arguments[0].value ===
|
|
118
|
+
if (typeof node.parent.parent.parent.arguments[0].value === "boolean") {
|
|
119
119
|
context.report({
|
|
120
120
|
node: node.parent,
|
|
121
121
|
message: `Use toHaveAttribute instead of asserting on hasAttribute`,
|
|
@@ -126,21 +126,21 @@ module.exports = {
|
|
|
126
126
|
node.parent.parent.property,
|
|
127
127
|
`${
|
|
128
128
|
node.parent.parent.parent.arguments[0].value === false
|
|
129
|
-
?
|
|
130
|
-
:
|
|
129
|
+
? "not."
|
|
130
|
+
: ""
|
|
131
131
|
}toHaveAttribute`
|
|
132
132
|
),
|
|
133
133
|
fixer.replaceText(
|
|
134
134
|
node.parent.parent.parent.arguments[0],
|
|
135
135
|
node.arguments[0].raw
|
|
136
|
-
)
|
|
136
|
+
)
|
|
137
137
|
];
|
|
138
|
-
}
|
|
138
|
+
}
|
|
139
139
|
});
|
|
140
140
|
} else {
|
|
141
141
|
context.report({
|
|
142
142
|
node: node.parent.parent.property,
|
|
143
|
-
message:
|
|
143
|
+
message: "Invalid matcher for hasAttribute"
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
},
|
|
@@ -156,16 +156,16 @@ module.exports = {
|
|
|
156
156
|
fixer.replaceTextRange(
|
|
157
157
|
[
|
|
158
158
|
node.parent.parent.property.range[0],
|
|
159
|
-
node.parent.parent.parent.range[1]
|
|
159
|
+
node.parent.parent.parent.range[1]
|
|
160
160
|
],
|
|
161
161
|
`${
|
|
162
|
-
node.parent.parent.property.name ===
|
|
162
|
+
node.parent.parent.property.name === "toBeFalsy" ? "not." : ""
|
|
163
163
|
}toHaveAttribute(${node.arguments[0].raw})`
|
|
164
|
-
)
|
|
164
|
+
)
|
|
165
165
|
];
|
|
166
|
-
}
|
|
166
|
+
}
|
|
167
167
|
});
|
|
168
|
-
}
|
|
168
|
+
}
|
|
169
169
|
};
|
|
170
|
-
}
|
|
170
|
+
}
|
|
171
171
|
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview prefer toHaveAttribute over checking getAttribute/hasAttribute
|
|
3
|
+
* @author Ben Monro
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
meta: {
|
|
9
|
+
docs: {
|
|
10
|
+
description: "Prefer toHaveTextContent over checking element.textContent",
|
|
11
|
+
recommended: true
|
|
12
|
+
},
|
|
13
|
+
fixable: "code"
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
create: function(context) {
|
|
17
|
+
return {
|
|
18
|
+
[`MemberExpression[property.name='textContent'][parent.callee.name='expect'][parent.parent.property.name=/toContain$|toMatch$/]`](
|
|
19
|
+
node
|
|
20
|
+
) {
|
|
21
|
+
const expectedArg = node.parent.parent.parent.arguments[0];
|
|
22
|
+
context.report({
|
|
23
|
+
node: node.parent,
|
|
24
|
+
message: `Use toHaveTextContent instead of asserting on DOM node attributes`,
|
|
25
|
+
fix(fixer) {
|
|
26
|
+
return [
|
|
27
|
+
fixer.removeRange([
|
|
28
|
+
node.property.range[0] - 1,
|
|
29
|
+
node.property.range[1]
|
|
30
|
+
]),
|
|
31
|
+
fixer.replaceTextRange(
|
|
32
|
+
node.parent.parent.property.range,
|
|
33
|
+
"toHaveTextContent"
|
|
34
|
+
),
|
|
35
|
+
fixer.replaceTextRange(
|
|
36
|
+
expectedArg.range,
|
|
37
|
+
`/${expectedArg.value}/`
|
|
38
|
+
)
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
[`MemberExpression[property.name='textContent'][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](
|
|
44
|
+
node
|
|
45
|
+
) {
|
|
46
|
+
context.report({
|
|
47
|
+
node: node.parent,
|
|
48
|
+
message: `Use toHaveTextContent instead of asserting on DOM node attributes`,
|
|
49
|
+
fix(fixer) {
|
|
50
|
+
return [
|
|
51
|
+
fixer.removeRange([
|
|
52
|
+
node.property.range[0] - 1,
|
|
53
|
+
node.property.range[1]
|
|
54
|
+
]),
|
|
55
|
+
fixer.replaceTextRange(
|
|
56
|
+
node.parent.parent.property.range,
|
|
57
|
+
"toHaveTextContent"
|
|
58
|
+
)
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
[`MemberExpression[property.name='textContent'][parent.callee.name='expect'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](
|
|
64
|
+
node
|
|
65
|
+
) {
|
|
66
|
+
context.report({
|
|
67
|
+
node: node.parent,
|
|
68
|
+
message: `Use toHaveTextContent instead of asserting on DOM node attributes`,
|
|
69
|
+
fix(fixer) {
|
|
70
|
+
return [
|
|
71
|
+
fixer.removeRange([
|
|
72
|
+
node.property.range[0] - 1,
|
|
73
|
+
node.property.range[1]
|
|
74
|
+
]),
|
|
75
|
+
fixer.replaceTextRange(
|
|
76
|
+
node.parent.parent.parent.property.range,
|
|
77
|
+
"toHaveTextContent"
|
|
78
|
+
)
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
[`MemberExpression[property.name='textContent'][parent.callee.name='expect'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toContain$|toMatch$/]`](
|
|
84
|
+
node
|
|
85
|
+
) {
|
|
86
|
+
const expectedArg = node.parent.parent.parent.parent.arguments[0];
|
|
87
|
+
context.report({
|
|
88
|
+
node: node.parent,
|
|
89
|
+
message: `Use toHaveTextContent instead of asserting on DOM node attributes`,
|
|
90
|
+
fix(fixer) {
|
|
91
|
+
return [
|
|
92
|
+
fixer.removeRange([
|
|
93
|
+
node.property.range[0] - 1,
|
|
94
|
+
node.property.range[1]
|
|
95
|
+
]),
|
|
96
|
+
fixer.replaceTextRange(
|
|
97
|
+
node.parent.parent.parent.property.range,
|
|
98
|
+
"toHaveTextContent"
|
|
99
|
+
),
|
|
100
|
+
fixer.replaceTextRange(
|
|
101
|
+
expectedArg.range,
|
|
102
|
+
`/${expectedArg.value}/`
|
|
103
|
+
)
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest-dom",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "lint rules for use with jest-dom",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"lint": "eslint .",
|
|
14
14
|
"test": "jest",
|
|
15
|
+
"format": "prettier \"**/*.js\" --write",
|
|
15
16
|
"generate-readme-table": "node build/generate-readme-table.js"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
@@ -71,5 +71,15 @@ Object {
|
|
|
71
71
|
"fixable": "code",
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
|
+
"prefer-to-have-text-content": Object {
|
|
75
|
+
"create": [Function],
|
|
76
|
+
"meta": Object {
|
|
77
|
+
"docs": Object {
|
|
78
|
+
"description": "Prefer toHaveTextContent over checking element.textContent",
|
|
79
|
+
"recommended": true,
|
|
80
|
+
},
|
|
81
|
+
"fixable": "code",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
74
84
|
}
|
|
75
85
|
`;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
module.exports = ({ preferred, negatedPreferred, attribute }) => {
|
|
2
2
|
let doubleNegativeCases = [];
|
|
3
|
-
if (negatedPreferred.startsWith(
|
|
3
|
+
if (negatedPreferred.startsWith("toBe")) {
|
|
4
4
|
doubleNegativeCases = [
|
|
5
5
|
{
|
|
6
6
|
code: `expect(element).not.${negatedPreferred}`,
|
|
7
7
|
errors: [
|
|
8
8
|
{
|
|
9
|
-
message: `Use ${preferred} instead of not.${negatedPreferred}
|
|
10
|
-
}
|
|
9
|
+
message: `Use ${preferred} instead of not.${negatedPreferred}`
|
|
10
|
+
}
|
|
11
11
|
],
|
|
12
|
-
output: `expect(element).${preferred}
|
|
12
|
+
output: `expect(element).${preferred}`
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
code: `expect(element).not.${preferred}`,
|
|
16
16
|
errors: [
|
|
17
17
|
{
|
|
18
|
-
message: `Use ${negatedPreferred} instead of not.${preferred}
|
|
19
|
-
}
|
|
18
|
+
message: `Use ${negatedPreferred} instead of not.${preferred}`
|
|
19
|
+
}
|
|
20
20
|
],
|
|
21
|
-
output: `expect(element).${negatedPreferred}
|
|
22
|
-
}
|
|
21
|
+
output: `expect(element).${negatedPreferred}`
|
|
22
|
+
}
|
|
23
23
|
];
|
|
24
24
|
}
|
|
25
25
|
let directChecks = [];
|
|
@@ -29,29 +29,29 @@ module.exports = ({ preferred, negatedPreferred, attribute }) => {
|
|
|
29
29
|
code: `expect(getByText('foo').${attribute}).toBeTruthy()`,
|
|
30
30
|
errors: [
|
|
31
31
|
{
|
|
32
|
-
message: `Use ${preferred} instead of checking .${attribute} directly
|
|
33
|
-
}
|
|
32
|
+
message: `Use ${preferred} instead of checking .${attribute} directly`
|
|
33
|
+
}
|
|
34
34
|
],
|
|
35
|
-
output: `expect(getByText('foo')).${[preferred]}
|
|
35
|
+
output: `expect(getByText('foo')).${[preferred]}`
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
code: `expect(getByText('foo').${attribute}).toBeFalsy()`,
|
|
39
39
|
errors: [
|
|
40
40
|
{
|
|
41
|
-
message: `Use ${negatedPreferred} instead of checking .${attribute} directly
|
|
42
|
-
}
|
|
41
|
+
message: `Use ${negatedPreferred} instead of checking .${attribute} directly`
|
|
42
|
+
}
|
|
43
43
|
],
|
|
44
|
-
output: `expect(getByText('foo')).${[negatedPreferred]}
|
|
44
|
+
output: `expect(getByText('foo')).${[negatedPreferred]}`
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
code: `expect(getByText('foo').${attribute}).toBe(true)`,
|
|
48
48
|
errors: [
|
|
49
49
|
{
|
|
50
|
-
message: `Use ${preferred} instead of checking .${attribute} directly
|
|
51
|
-
}
|
|
50
|
+
message: `Use ${preferred} instead of checking .${attribute} directly`
|
|
51
|
+
}
|
|
52
52
|
],
|
|
53
|
-
output: `expect(getByText('foo')).${[preferred]}
|
|
54
|
-
}
|
|
53
|
+
output: `expect(getByText('foo')).${[preferred]}`
|
|
54
|
+
}
|
|
55
55
|
];
|
|
56
56
|
}
|
|
57
57
|
return {
|
|
@@ -59,7 +59,7 @@ module.exports = ({ preferred, negatedPreferred, attribute }) => {
|
|
|
59
59
|
`expect(element).not.toHaveProperty('value', 'foo')`,
|
|
60
60
|
`expect(element).${preferred}`,
|
|
61
61
|
`expect(element).${negatedPreferred}`,
|
|
62
|
-
`expect(element).toHaveProperty('value', 'bar')
|
|
62
|
+
`expect(element).toHaveProperty('value', 'bar')`
|
|
63
63
|
],
|
|
64
64
|
invalid: [
|
|
65
65
|
...doubleNegativeCases,
|
|
@@ -68,92 +68,92 @@ module.exports = ({ preferred, negatedPreferred, attribute }) => {
|
|
|
68
68
|
code: `expect(element).toHaveProperty('${attribute}', true)`,
|
|
69
69
|
errors: [
|
|
70
70
|
{
|
|
71
|
-
message: `Use ${preferred} instead of toHaveProperty('${attribute}', true)
|
|
72
|
-
}
|
|
71
|
+
message: `Use ${preferred} instead of toHaveProperty('${attribute}', true)`
|
|
72
|
+
}
|
|
73
73
|
],
|
|
74
|
-
output: `expect(element).${preferred}
|
|
74
|
+
output: `expect(element).${preferred}`
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
77
|
code: `expect(element).toHaveProperty('${attribute}', false)`,
|
|
78
78
|
errors: [
|
|
79
79
|
{
|
|
80
|
-
message: `Use ${negatedPreferred} instead of toHaveProperty('${attribute}', false)
|
|
81
|
-
}
|
|
80
|
+
message: `Use ${negatedPreferred} instead of toHaveProperty('${attribute}', false)`
|
|
81
|
+
}
|
|
82
82
|
],
|
|
83
|
-
output: `expect(element).${negatedPreferred}
|
|
83
|
+
output: `expect(element).${negatedPreferred}`
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
86
|
code: `expect(element).toHaveAttribute('${attribute}', false)`,
|
|
87
87
|
errors: [
|
|
88
88
|
{
|
|
89
|
-
message: `Use ${negatedPreferred} instead of toHaveAttribute('${attribute}', false)
|
|
90
|
-
}
|
|
89
|
+
message: `Use ${negatedPreferred} instead of toHaveAttribute('${attribute}', false)`
|
|
90
|
+
}
|
|
91
91
|
],
|
|
92
|
-
output: `expect(element).${negatedPreferred}
|
|
92
|
+
output: `expect(element).${negatedPreferred}`
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
95
|
code: `expect(element).toHaveProperty('${attribute}')`,
|
|
96
96
|
errors: [
|
|
97
97
|
{
|
|
98
|
-
message: `Use ${preferred} instead of toHaveProperty('${attribute}')
|
|
99
|
-
}
|
|
98
|
+
message: `Use ${preferred} instead of toHaveProperty('${attribute}')`
|
|
99
|
+
}
|
|
100
100
|
],
|
|
101
|
-
output: `expect(element).${preferred}
|
|
101
|
+
output: `expect(element).${preferred}`
|
|
102
102
|
},
|
|
103
103
|
{
|
|
104
104
|
code: `expect(element).toHaveAttribute('${attribute}')`,
|
|
105
105
|
errors: [
|
|
106
106
|
{
|
|
107
|
-
message: `Use ${preferred} instead of toHaveAttribute('${attribute}')
|
|
108
|
-
}
|
|
107
|
+
message: `Use ${preferred} instead of toHaveAttribute('${attribute}')`
|
|
108
|
+
}
|
|
109
109
|
],
|
|
110
|
-
output: `expect(element).${preferred}
|
|
110
|
+
output: `expect(element).${preferred}`
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
113
|
code: `expect(element).not.toHaveAttribute('${attribute}')`,
|
|
114
114
|
errors: [
|
|
115
115
|
{
|
|
116
|
-
message: `Use ${negatedPreferred} instead of not.toHaveAttribute('${attribute}')
|
|
117
|
-
}
|
|
116
|
+
message: `Use ${negatedPreferred} instead of not.toHaveAttribute('${attribute}')`
|
|
117
|
+
}
|
|
118
118
|
],
|
|
119
|
-
output: `expect(element).${negatedPreferred}
|
|
119
|
+
output: `expect(element).${negatedPreferred}`
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
122
|
code: `expect(element).not.toHaveProperty('${attribute}')`,
|
|
123
123
|
errors: [
|
|
124
124
|
{
|
|
125
|
-
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')
|
|
126
|
-
}
|
|
125
|
+
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')`
|
|
126
|
+
}
|
|
127
127
|
],
|
|
128
|
-
output: `expect(element).${negatedPreferred}
|
|
128
|
+
output: `expect(element).${negatedPreferred}`
|
|
129
129
|
},
|
|
130
130
|
{
|
|
131
131
|
code: `expect(element).toHaveAttribute("${attribute}", "")`,
|
|
132
132
|
errors: [
|
|
133
133
|
{
|
|
134
|
-
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")
|
|
135
|
-
}
|
|
134
|
+
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")`
|
|
135
|
+
}
|
|
136
136
|
],
|
|
137
|
-
output: `expect(element).${preferred}
|
|
137
|
+
output: `expect(element).${preferred}`
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
code: `expect(getByText("foo")).toHaveAttribute("${attribute}", "")`,
|
|
141
141
|
errors: [
|
|
142
142
|
{
|
|
143
|
-
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")
|
|
144
|
-
}
|
|
143
|
+
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")`
|
|
144
|
+
}
|
|
145
145
|
],
|
|
146
|
-
output: `expect(getByText("foo")).${preferred}
|
|
146
|
+
output: `expect(getByText("foo")).${preferred}`
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
code: `expect(getByText("foo")).not.toHaveProperty("${attribute}")`,
|
|
150
150
|
errors: [
|
|
151
151
|
{
|
|
152
|
-
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')
|
|
153
|
-
}
|
|
152
|
+
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')`
|
|
153
|
+
}
|
|
154
154
|
],
|
|
155
|
-
output: `expect(getByText("foo")).${negatedPreferred}
|
|
156
|
-
}
|
|
157
|
-
]
|
|
155
|
+
output: `expect(getByText("foo")).${negatedPreferred}`
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
158
|
};
|
|
159
159
|
};
|