diff --git a/change/@ni-eslint-config-playwright-9c9f29cc-9f05-4cc9-bce6-934610f4b899.json b/change/@ni-eslint-config-playwright-9c9f29cc-9f05-4cc9-bce6-934610f4b899.json new file mode 100644 index 0000000..6fba213 --- /dev/null +++ b/change/@ni-eslint-config-playwright-9c9f29cc-9f05-4cc9-bce6-934610f4b899.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Mark several recommended Playwright rules as errors instead of warnings", + "packageName": "@ni/eslint-config-playwright", + "email": "jattasNI@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/package-lock.json b/package-lock.json index 81af6d0..c95d908 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13971,7 +13971,7 @@ "peerDependencies": { "@ni/eslint-config-javascript": "^5.2.0", "@ni/eslint-config-typescript": "^5.0.7", - "eslint-plugin-playwright": "^2.10.2" + "eslint-plugin-playwright": "^2.12.0" } }, "packages/eslint-config-typescript": { diff --git a/packages/eslint-config-playwright/index.js b/packages/eslint-config-playwright/index.js index 606cc32..fb24b77 100644 --- a/packages/eslint-config-playwright/index.js +++ b/packages/eslint-config-playwright/index.js @@ -15,12 +15,30 @@ export const playwrightConfig = defineConfig([ */ 'no-await-in-loop': 'off', + /* + Playwright marks this as recommended but configures it as 'warn'. + A test without an assertion can't fail on incorrect behavior, so it gives a false sense of coverage. + */ + 'playwright/expect-expect': 'error', + /* Playwright marks this as recommended but configures it as 'warn'. Deeply nested describe blocks are likely an indication that test files are too complicated. */ 'playwright/max-nested-describe': 'error', + /* + Commented out tests are easy to forget about and lose coverage silently. + Use a skipped test accompanied by a comment linking to a work item instead. + */ + 'playwright/no-commented-out-tests': 'error', + + /* + Playwright marks this as recommended but configures it as 'warn'. + An assertion that is conditionally skipped can cause a test to pass without verifying anything. + */ + 'playwright/no-conditional-expect': 'error', + /* Playwright marks this as recommended but configures it as 'warn'. Conditional logic in tests is usually an indication that a test is attempting to cover too much, and not testing the logic it intends to. @@ -47,6 +65,12 @@ export const playwrightConfig = defineConfig([ */ 'playwright/no-force-option': 'error', + /* + Playwright marks this as recommended but configures it as 'warn'. + Identical titles make it hard to tell which test failed and can cause tests to be filtered or reported incorrectly. + */ + 'playwright/no-identical-title': 'error', + /* Playwright marks this as recommended but configures it as 'warn'. Using page.pause should be reserved for debugging, not production code. @@ -60,23 +84,53 @@ export const playwrightConfig = defineConfig([ */ 'playwright/no-skipped-test': 'off', + /* + Playwright marks this as recommended but configures it as 'warn'. + Awaiting a value that is not a promise is unnecessary and misleading about what is asynchronous. + */ + 'playwright/no-useless-await': 'error', + /* Playwright marks this as recommended but configures it as 'warn'. Assertions are easier to read when using a dedicated matcher rather than negating the opposite matcher. */ 'playwright/no-useless-not': 'error', + /* + Playwright marks this as recommended but configures it as 'warn'. + page.waitForSelector is discouraged. Instead use locators with web-first assertions, which wait automatically. + */ + 'playwright/no-wait-for-selector': 'error', + /* Playwright marks this as recommended but configures it as 'warn'. Waiting for arbitrary amounts of time can cause test intermittency. Instead wait for a specific condition. */ 'playwright/no-wait-for-timeout': 'error', + /* + Playwright marks this as recommended but configures it as 'warn'. + Locators are auto-waiting and retryable. Instead of page methods like page.click use page.locator().click(). + */ + 'playwright/prefer-locator': 'error', + + /* + Playwright marks this as recommended but configures it as 'warn'. + toHaveCount() retries until the count matches, which avoids intermittency compared to asserting on locator.count(). + */ + 'playwright/prefer-to-have-count': 'error', + /* In order to have a better failure message, toHaveLength() should be used when asserting expectations on objects length property. */ 'playwright/prefer-to-have-length': 'error', + /* + Skipped tests are allowed (see no-skipped-test) but must explain why they are skipped. + The reason should link to a work item that tracks re-enabling the test. + */ + 'playwright/require-annotation-reason': 'error', + /* Having a top-level describe block in each test file is common practice which aligns with patterns we use in Jasmine */ diff --git a/packages/eslint-config-playwright/package.json b/packages/eslint-config-playwright/package.json index 1a214e9..2efd6fd 100644 --- a/packages/eslint-config-playwright/package.json +++ b/packages/eslint-config-playwright/package.json @@ -39,6 +39,6 @@ "peerDependencies": { "@ni/eslint-config-typescript": "^5.0.7", "@ni/eslint-config-javascript": "^5.2.0", - "eslint-plugin-playwright": "^2.10.2" + "eslint-plugin-playwright": "^2.12.0" } }