eslint-plugin-jest-dom 5.10.0 → 5.10.1
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/dist/assignment-ast.js
CHANGED
|
@@ -41,7 +41,9 @@ function getInnerNodeFrom(context, node, expression) {
|
|
|
41
41
|
*/
|
|
42
42
|
function getAssignmentForIdentifier(context, node, identifierName) {
|
|
43
43
|
const variable = (0, _context.getScope)(context, node).set.get(identifierName);
|
|
44
|
-
if (!variable)
|
|
44
|
+
if (!variable) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
45
47
|
const init = variable.defs[0].node.init;
|
|
46
48
|
let assignmentNode;
|
|
47
49
|
if (init) {
|
|
@@ -70,7 +70,9 @@ var _default = ({
|
|
|
70
70
|
const {
|
|
71
71
|
isDTLQuery
|
|
72
72
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
|
|
73
|
-
if (!isDTLQuery)
|
|
73
|
+
if (!isDTLQuery) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
74
76
|
const isNegated = matcher.endsWith("Falsy") || (matcher === "toBe" || matcher === "toEqual") && matcherArg !== true;
|
|
75
77
|
const correctFunction = getCorrectFunctionFor(node.callee.object, isNegated);
|
|
76
78
|
context.report({
|
|
@@ -102,7 +104,9 @@ var _default = ({
|
|
|
102
104
|
const {
|
|
103
105
|
isDTLQuery
|
|
104
106
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
|
|
105
|
-
if (!isDTLQuery)
|
|
107
|
+
if (!isDTLQuery) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
106
110
|
const correctFunction = getCorrectFunctionFor(node);
|
|
107
111
|
const incorrectFunction = node.callee.property.name;
|
|
108
112
|
const message = `Use ${correctFunction}() instead of ${incorrectFunction}(${node.arguments.map(({
|
|
@@ -82,7 +82,9 @@ const create = context => {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// only report on dom nodes which we can resolve to RTL queries.
|
|
85
|
-
if (!queryNode || !queryNode.name && !queryNode.property)
|
|
85
|
+
if (!queryNode || !queryNode.name && !queryNode.property) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
86
88
|
|
|
87
89
|
// *By* query with .toHaveLength(0/1) matcher are considered violations
|
|
88
90
|
//
|
|
@@ -56,7 +56,9 @@ const create = context => ({
|
|
|
56
56
|
messageId,
|
|
57
57
|
fix(fixer) {
|
|
58
58
|
//can't autofix here as it toHaveClass doesn't have a partial matcher / regex for class names.
|
|
59
|
-
if (matcher.name === "toContain")
|
|
59
|
+
if (matcher.name === "toContain") {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
60
62
|
return [fixer.removeRange([classNameProp.object.range[1], expectArg.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(classValue, (0, _context.getSourceCode)(context).getText(classValue))];
|
|
61
63
|
}
|
|
62
64
|
});
|
|
@@ -78,7 +80,9 @@ const create = context => ({
|
|
|
78
80
|
const {
|
|
79
81
|
isDTLQuery
|
|
80
82
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, classNameProp);
|
|
81
|
-
if (!isDTLQuery)
|
|
83
|
+
if (!isDTLQuery) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
82
86
|
// don't report here if using `expect.foo()`
|
|
83
87
|
|
|
84
88
|
if (classValue.type === "CallExpression" && classValue.callee.type === "MemberExpression" && classValue.callee.object.name === "expect") {
|
|
@@ -105,12 +109,16 @@ const create = context => ({
|
|
|
105
109
|
const {
|
|
106
110
|
isDTLQuery
|
|
107
111
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, classNameProp);
|
|
108
|
-
if (!isDTLQuery)
|
|
112
|
+
if (!isDTLQuery) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
109
115
|
context.report({
|
|
110
116
|
node: matcher,
|
|
111
117
|
messageId,
|
|
112
118
|
fix(fixer) {
|
|
113
|
-
if (matcherArg.name !== "stringContaining")
|
|
119
|
+
if (matcherArg.name !== "stringContaining") {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
114
122
|
return [fixer.removeRange([classNameProp.range[1], className.range[1]]), fixer.replaceText(matcher, "toHaveClass"), fixer.replaceText(node.arguments[0], `${(0, _context.getSourceCode)(context).getText(classValue)}`)];
|
|
115
123
|
}
|
|
116
124
|
});
|
|
@@ -124,7 +132,9 @@ const create = context => ({
|
|
|
124
132
|
const {
|
|
125
133
|
isDTLQuery
|
|
126
134
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, classNameProp);
|
|
127
|
-
if (!isDTLQuery)
|
|
135
|
+
if (!isDTLQuery) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
128
138
|
context.report({
|
|
129
139
|
node: matcher,
|
|
130
140
|
messageId,
|
|
@@ -148,7 +158,9 @@ const create = context => ({
|
|
|
148
158
|
const {
|
|
149
159
|
isDTLQuery
|
|
150
160
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
|
|
151
|
-
if (!isDTLQuery)
|
|
161
|
+
if (!isDTLQuery) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
152
164
|
context.report({
|
|
153
165
|
node: matcher,
|
|
154
166
|
messageId,
|
|
@@ -170,7 +182,9 @@ const create = context => ({
|
|
|
170
182
|
const {
|
|
171
183
|
isDTLQuery
|
|
172
184
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.object.arguments[0]);
|
|
173
|
-
if (!isDTLQuery)
|
|
185
|
+
if (!isDTLQuery) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
174
188
|
context.report({
|
|
175
189
|
node: matcher,
|
|
176
190
|
messageId,
|
|
@@ -192,7 +206,9 @@ const create = context => ({
|
|
|
192
206
|
const {
|
|
193
207
|
isDTLQuery
|
|
194
208
|
} = (0, _assignmentAst.getQueryNodeFrom)(context, node.callee.object.arguments[0]);
|
|
195
|
-
if (!isDTLQuery)
|
|
209
|
+
if (!isDTLQuery) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
196
212
|
context.report({
|
|
197
213
|
node: matcher,
|
|
198
214
|
messageId,
|
|
@@ -33,7 +33,7 @@ const create = context => {
|
|
|
33
33
|
}
|
|
34
34
|
return {
|
|
35
35
|
//expect(el.style.foo).toBe("bar");
|
|
36
|
-
[`MemberExpression[property.name=style][parent.computed=false][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal/][parent.parent.parent.parent.arguments.0.type=/(Template)?Literal/][parent.parent.callee.name=expect]`](node) {
|
|
36
|
+
[`MemberExpression[property.name=style][parent.computed=false][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal/][parent.parent.parent.parent.arguments.0.type=/((Template)?Literal)|Identifier/][parent.parent.callee.name=expect]`](node) {
|
|
37
37
|
const styleName = node.parent.property;
|
|
38
38
|
const [styleValue] = node.parent.parent.parent.parent.arguments;
|
|
39
39
|
const matcher = node.parent.parent.parent.property;
|
|
@@ -46,7 +46,7 @@ const create = context => {
|
|
|
46
46
|
});
|
|
47
47
|
},
|
|
48
48
|
//expect(el.style.foo).not.toBe("bar");
|
|
49
|
-
[`MemberExpression[property.name=style][parent.computed=false][parent.parent.parent.property.name=not][parent.parent.parent.parent.property.name=/toBe$|to(Strict)?Equal/][parent.parent.parent.parent.parent.arguments.0.type=/(Template)?Literal$/][parent.parent.callee.name=expect]`](node) {
|
|
49
|
+
[`MemberExpression[property.name=style][parent.computed=false][parent.parent.parent.property.name=not][parent.parent.parent.parent.property.name=/toBe$|to(Strict)?Equal/][parent.parent.parent.parent.parent.arguments.0.type=/(((Template)?Literal)|Identifier)$/][parent.parent.callee.name=expect]`](node) {
|
|
50
50
|
const styleName = node.parent.property;
|
|
51
51
|
const styleValue = node.parent.parent.parent.parent.parent.arguments[0];
|
|
52
52
|
const matcher = node.parent.parent.parent.parent.property;
|
|
@@ -59,7 +59,7 @@ const create = context => {
|
|
|
59
59
|
});
|
|
60
60
|
},
|
|
61
61
|
// expect(el.style).toContain("foo-bar")
|
|
62
|
-
[`MemberExpression[property.name=style][parent.parent.property.name=toContain][parent.parent.parent.arguments.0.type=/(Template)?Literal$/][parent.callee.name=expect]`](node) {
|
|
62
|
+
[`MemberExpression[property.name=style][parent.parent.property.name=toContain][parent.parent.parent.arguments.0.type=/(((Template)?Literal)|Identifier)$/][parent.callee.name=expect]`](node) {
|
|
63
63
|
const [styleName] = node.parent.parent.parent.arguments;
|
|
64
64
|
const matcher = node.parent.parent.property;
|
|
65
65
|
context.report({
|
|
@@ -71,7 +71,7 @@ const create = context => {
|
|
|
71
71
|
});
|
|
72
72
|
},
|
|
73
73
|
// expect(el.style).not.toContain("foo-bar")
|
|
74
|
-
[`MemberExpression[property.name=style][parent.parent.property.name=not][parent.parent.parent.property.name=toContain][parent.parent.parent.parent.arguments.0.type=/(Template)?Literal$/]`](node) {
|
|
74
|
+
[`MemberExpression[property.name=style][parent.parent.property.name=not][parent.parent.parent.property.name=toContain][parent.parent.parent.parent.arguments.0.type=/(((Template)?Literal)|Identifier)$/]`](node) {
|
|
75
75
|
const [styleName] = node.parent.parent.parent.parent.arguments;
|
|
76
76
|
const matcher = node.parent.parent.parent.property;
|
|
77
77
|
context.report({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest-dom",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.1",
|
|
4
4
|
"description": "ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "babel src --out-dir dist --delete-dir-on-start --copy-files --no-copy-ignored",
|
|
35
35
|
"regenerate-docs": "npm run build && eslint-doc-generator",
|
|
36
|
-
"lint": "eslint
|
|
36
|
+
"lint": "eslint",
|
|
37
37
|
"setup": "npm install",
|
|
38
38
|
"test": "jest",
|
|
39
39
|
"test:coverage": "npm test -- --coverage",
|
|
@@ -46,19 +46,19 @@
|
|
|
46
46
|
"@babel/cli": "^7.29.7",
|
|
47
47
|
"@babel/preset-env": "^7.29.7",
|
|
48
48
|
"@testing-library/dom": "^10.4.1",
|
|
49
|
-
"@typescript-eslint/parser": "^
|
|
50
|
-
"eslint": "^
|
|
49
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
50
|
+
"eslint": "^9.0.0",
|
|
51
51
|
"eslint-config-prettier": "^8.10.2",
|
|
52
52
|
"eslint-doc-generator": "^3.0.0",
|
|
53
53
|
"eslint-plugin-import": "^2.32.0",
|
|
54
54
|
"eslint-plugin-jest": "^29.16.0",
|
|
55
|
-
"eslint-remote-tester": "^
|
|
56
|
-
"eslint-remote-tester-repositories": "^
|
|
55
|
+
"eslint-remote-tester": "^4.0.0",
|
|
56
|
+
"eslint-remote-tester-repositories": "^2.0.0",
|
|
57
|
+
"globals": "^17.8.0",
|
|
57
58
|
"jest": "^28.1.3",
|
|
58
59
|
"jest-snapshot-serializer-raw": "^1.2.0",
|
|
59
60
|
"prettier": "^3.9.6",
|
|
60
|
-
"semver": "^7.6.0"
|
|
61
|
-
"typescript": "^5.1.3"
|
|
61
|
+
"semver": "^7.6.0"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"@testing-library/dom": "^8.0.0 || ^9.0.0 || ^10.0.0",
|