eslint-plugin-playwright 2.8.0 → 2.9.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/README.md CHANGED
@@ -127,13 +127,13 @@ CLI option\
127
127
  | [no-commented-out-tests](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-commented-out-tests.md) | Disallow commented out tests | | | |
128
128
  | [no-conditional-expect](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-conditional-expect.md) | Disallow calling `expect` conditionally | ✅ | | |
129
129
  | [no-conditional-in-test](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | ✅ | | |
130
- | [no-duplicate-hooks](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | | |
130
+ | [no-duplicate-hooks](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks || | |
131
131
  | [no-duplicate-slow](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-duplicate-slow.md) | Disallow multiple `test.slow()` calls in the same test | ✅ | | |
132
132
  | [no-element-handle](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-element-handle.md) | Disallow usage of element handles | ✅ | | 💡 |
133
133
  | [no-eval](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-eval.md) | Disallow usage of `page.$eval()` and `page.$$eval()` | ✅ | | |
134
134
  | [no-focused-test](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-focused-test.md) | Disallow usage of `.only` annotation | ✅ | | 💡 |
135
135
  | [no-force-option](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-force-option.md) | Disallow usage of the `{ force: true }` option | ✅ | | |
136
- | [no-get-by-title](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-get-by-title.md) | Disallow using `getByTitle()` | | 🔧 | |
136
+ | [no-get-by-title](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-get-by-title.md) | Disallow using `getByTitle()` | | | |
137
137
  | [no-hooks](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | | |
138
138
  | [no-nested-step](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-nested-step.md) | Disallow nested `test.step()` methods | ✅ | | |
139
139
  | [no-networkidle](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-networkidle.md) | Disallow usage of the `networkidle` option | ✅ | | |
@@ -145,7 +145,7 @@ CLI option\
145
145
  | [no-restricted-roles](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-restricted-roles.md) | Disallow specific roles in `getByRole()` | | | |
146
146
  | [no-skipped-test](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-skipped-test.md) | Disallow usage of the `.skip` annotation | ✅ | | 💡 |
147
147
  | [no-slowed-test](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-slowed-test.md) | Disallow usage of the `.slow` annotation | | | 💡 |
148
- | [no-standalone-expect](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-standalone-expect.md) | Disallow using expect outside of `test` blocks | ✅ | | |
148
+ | [no-standalone-expect](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-standalone-expect.md) | Disallow using expect outside of `test` blocks | ✅ | 🔧 | |
149
149
  | [no-unsafe-references](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-unsafe-references.md) | Prevent unsafe variable references in `page.evaluate()` | ✅ | 🔧 | |
150
150
  | [no-unused-locators](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-unused-locators.md) | Disallow usage of page locators that are not used | ✅ | | |
151
151
  | [no-useless-await](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-useless-await.md) | Disallow unnecessary `await`s for Playwright methods | ✅ | 🔧 | |
@@ -155,16 +155,16 @@ CLI option\
155
155
  | [no-wait-for-timeout](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/no-wait-for-timeout.md) | Disallow usage of `page.waitForTimeout()` | ✅ | | 💡 |
156
156
  | [prefer-comparison-matcher](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-comparison-matcher.md) | Suggest using the built-in comparison matchers | | 🔧 | |
157
157
  | [prefer-equality-matcher](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-equality-matcher.md) | Suggest using the built-in equality matchers | | | 💡 |
158
- | [prefer-hooks-in-order](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-hooks-in-order.md) | Prefer having hooks in a consistent order | | | |
159
- | [prefer-hooks-on-top](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases | | | |
158
+ | [prefer-hooks-in-order](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-hooks-in-order.md) | Prefer having hooks in a consistent order || | |
159
+ | [prefer-hooks-on-top](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases || | |
160
160
  | [prefer-lowercase-title](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-lowercase-title.md) | Enforce lowercase test names | | 🔧 | |
161
161
  | [prefer-native-locators](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-native-locators.md) | Suggest built-in locators over `page.locator()` | | 🔧 | |
162
- | [prefer-locator](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-locator.md) | Suggest locators over page methods | | | |
163
- | [prefer-strict-equal](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` | | | 💡 |
162
+ | [prefer-locator](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-locator.md) | Suggest locators over page methods || | |
163
+ | [prefer-strict-equal](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` | | 🔧 | 💡 |
164
164
  | [prefer-to-be](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-be.md) | Suggest using `toBe()` | | 🔧 | |
165
165
  | [prefer-to-contain](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-contain.md) | Suggest using `toContain()` | | 🔧 | |
166
- | [prefer-to-have-count](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-have-count.md) | Suggest using `toHaveCount()` | | 🔧 | |
167
- | [prefer-to-have-length](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` | | 🔧 | |
166
+ | [prefer-to-have-count](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-have-count.md) | Suggest using `toHaveCount()` || 🔧 | |
167
+ | [prefer-to-have-length](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` || 🔧 | |
168
168
  | [prefer-web-first-assertions](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/prefer-web-first-assertions.md) | Suggest using web first assertions | ✅ | 🔧 | |
169
169
  | [require-hook](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/require-hook.md) | Require setup and teardown code to be within a hook | | | |
170
170
  | [require-soft-assertions](https://github.com/mskelton/eslint-plugin-playwright/tree/main/docs/rules/require-soft-assertions.md) | Require assertions to use `expect.soft()` | | 🔧 | |
package/dist/index.cjs CHANGED
@@ -1720,14 +1720,12 @@ var no_raw_locators_default = createRule({
1720
1720
  }
1721
1721
  return {
1722
1722
  CallExpression(node) {
1723
- if (node.callee.type !== "MemberExpression" || node.arguments[0]?.type === "Identifier") {
1723
+ if (node.callee.type !== "MemberExpression" || !isPropertyAccessor(node.callee, "locator")) {
1724
1724
  return;
1725
1725
  }
1726
- const method = getStringValue(node.callee.property);
1727
- const arg = getStringValue(node.arguments[0]);
1728
- const isLocator = isPageMethod(node, "locator") || method === "locator";
1729
- if (isLocator && !isAllowed(arg)) {
1726
+ if ((node.arguments.length === 0 || isStringNode(node.arguments[0])) && !isAllowed(getStringValue(node.arguments[0]))) {
1730
1727
  context.report({ messageId: "noRawLocator", node });
1728
+ return;
1731
1729
  }
1732
1730
  }
1733
1731
  };
@@ -1906,7 +1904,7 @@ var no_restricted_roles_default = createRule({
1906
1904
  }
1907
1905
  return {
1908
1906
  CallExpression(node) {
1909
- if (!isPageMethod(node, "getByRole")) {
1907
+ if (node.callee.type !== "MemberExpression" || !isPropertyAccessor(node.callee, "getByRole")) {
1910
1908
  return;
1911
1909
  }
1912
1910
  const role = getStringValue(node.arguments[0]);
@@ -2285,7 +2283,7 @@ var no_unused_locators_default = createRule({
2285
2283
  create(context) {
2286
2284
  return {
2287
2285
  CallExpression(node) {
2288
- if (!isPageMethod(node, LOCATOR_REGEX)) {
2286
+ if (node.callee.type !== "MemberExpression" || !isPropertyAccessor(node.callee, LOCATOR_REGEX)) {
2289
2287
  return;
2290
2288
  }
2291
2289
  if (node.parent.type === "ExpressionStatement" || node.parent.type === "AwaitExpression") {
@@ -3086,7 +3084,7 @@ var prefer_native_locators_default = createRule({
3086
3084
  return;
3087
3085
  }
3088
3086
  const query = getStringValue(node.arguments[0]);
3089
- if (!isPageMethod(node, "locator")) {
3087
+ if (!isPropertyAccessor(node.callee, "locator")) {
3090
3088
  return;
3091
3089
  }
3092
3090
  for (const pattern of patterns) {
@@ -4797,6 +4795,8 @@ var sharedConfig = {
4797
4795
  "playwright/missing-playwright-await": "error",
4798
4796
  "playwright/no-conditional-expect": "warn",
4799
4797
  "playwright/no-conditional-in-test": "warn",
4798
+ "playwright/no-duplicate-hooks": "warn",
4799
+ "playwright/no-duplicate-slow": "warn",
4800
4800
  "playwright/no-element-handle": "warn",
4801
4801
  "playwright/no-eval": "warn",
4802
4802
  "playwright/no-focused-test": "error",
@@ -4813,6 +4813,11 @@ var sharedConfig = {
4813
4813
  "playwright/no-wait-for-navigation": "error",
4814
4814
  "playwright/no-wait-for-selector": "warn",
4815
4815
  "playwright/no-wait-for-timeout": "warn",
4816
+ "playwright/prefer-hooks-in-order": "warn",
4817
+ "playwright/prefer-hooks-on-top": "warn",
4818
+ "playwright/prefer-locator": "warn",
4819
+ "playwright/prefer-to-have-count": "warn",
4820
+ "playwright/prefer-to-have-length": "warn",
4816
4821
  "playwright/prefer-web-first-assertions": "error",
4817
4822
  "playwright/valid-describe-callback": "error",
4818
4823
  "playwright/valid-expect": "error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-playwright",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "ESLint plugin for Playwright testing.",
5
5
  "license": "MIT",
6
6
  "author": "Mark Skelton <mark@mskelton.dev>",