UNPKG

eslint-plugin-sonarjs

Version:
29 lines (28 loc) • 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDescribe = isDescribe; exports.isExpectFqn = isExpectFqn; const ast_js_1 = require("../ast.js"); const describeModifiers = ['parallel', 'serial']; const EXPECT_FQN_ROOTS = [ '@playwright.test.test.expect', // test.expect alias '@playwright.test.expect', // import { expect } from '@playwright/test' ]; function isDescribe(node) { if (node?.type !== 'MemberExpression' || node.computed) { return false; } const { object, property } = node; return (((0, ast_js_1.isIdentifier)(object, 'test') && (0, ast_js_1.isIdentifier)(property, 'describe')) || ((0, ast_js_1.isIdentifier)(property, ...describeModifiers) && isDescribe(object))); } // Prefix match covers static helpers like `.soft`, `.poll`, and `.configure`. // `.replaceAll('/', '.')` normalizes the scoped-package slash that // getFullyQualifiedNameTS preserves (e.g. '@playwright/test') while ESTree FQNs use dots. function isExpectFqn(fqn) { if (!fqn) { return false; } const normalized = fqn.replaceAll('/', '.'); return EXPECT_FQN_ROOTS.some(root => normalized === root || normalized.startsWith(`${root}.`)); }