Skip to content

Commit

Permalink
prefer-dom-node-dataset: Ignore awaited getAttribute call (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored May 7, 2024
1 parent 1626852 commit 45f23d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rules/prefer-dom-node-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ const create = context => ({
return;
}

const method = callExpression.callee.property.name;
// Playwright's `Locator#getAttribute()` returns a promise.
// https://playwright.dev/docs/api/class-locator#locator-get-attribute
if (
callExpression.parent.type === 'AwaitExpression'
&& callExpression.parent.argument === callExpression
&& method === 'getAttribute'
) {
return;
}

const attributeName = callExpression.arguments[0].value.toLowerCase();

if (!attributeName.startsWith('data-')) {
Expand Down
2 changes: 2 additions & 0 deletions test/prefer-dom-node-dataset.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ test.snapshot({
// First Argument is not startsWith `data-`
'element.getAttribute("foo-unicorn");',
'element.getAttribute("data");',
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2307
'await page.locator("text=Hello").getAttribute("data-foo")',
],
invalid: [
outdent`
Expand Down

0 comments on commit 45f23d5

Please sign in to comment.