Skip to content

Commit 45f23d5

Browse files
authored
prefer-dom-node-dataset: Ignore awaited getAttribute call (#2334)
1 parent 1626852 commit 45f23d5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

rules/prefer-dom-node-dataset.js

+11
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ const create = context => ({
9191
return;
9292
}
9393

94+
const method = callExpression.callee.property.name;
95+
// Playwright's `Locator#getAttribute()` returns a promise.
96+
// https://playwright.dev/docs/api/class-locator#locator-get-attribute
97+
if (
98+
callExpression.parent.type === 'AwaitExpression'
99+
&& callExpression.parent.argument === callExpression
100+
&& method === 'getAttribute'
101+
) {
102+
return;
103+
}
104+
94105
const attributeName = callExpression.arguments[0].value.toLowerCase();
95106

96107
if (!attributeName.startsWith('data-')) {

test/prefer-dom-node-dataset.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ test.snapshot({
187187
// First Argument is not startsWith `data-`
188188
'element.getAttribute("foo-unicorn");',
189189
'element.getAttribute("data");',
190+
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2307
191+
'await page.locator("text=Hello").getAttribute("data-foo")',
190192
],
191193
invalid: [
192194
outdent`

0 commit comments

Comments
 (0)