From 587e151fbd595f0615aca7b70dcba12839b8bdaa Mon Sep 17 00:00:00 2001 From: igm Date: Mon, 12 Jan 2026 13:45:14 +0800 Subject: [PATCH] Fix ast-grep tests and add no-countall-number test - Update zod-namespace-import snapshot (semicolon fix) - Add test cases for no-countall-number rule - Update rule pattern to match method calls on objects Co-Authored-By: Claude Opus 4.5 --- .../no-countall-number-snapshot.yml | 16 ++++++++++++++++ .../zod-namespace-import-snapshot.yml | 4 ++-- .ast-grep/rule-tests/no-countall-number-test.yml | 9 +++++++++ .ast-grep/rules/no-countall-number.yml | 4 ++-- db/schema.sql | 4 ++-- 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 .ast-grep/rule-tests/__snapshots__/no-countall-number-snapshot.yml create mode 100644 .ast-grep/rule-tests/no-countall-number-test.yml diff --git a/.ast-grep/rule-tests/__snapshots__/no-countall-number-snapshot.yml b/.ast-grep/rule-tests/__snapshots__/no-countall-number-snapshot.yml new file mode 100644 index 0000000..61633c4 --- /dev/null +++ b/.ast-grep/rule-tests/__snapshots__/no-countall-number-snapshot.yml @@ -0,0 +1,16 @@ +id: no-countall-number +snapshots: + countAll(): + fixed: countAll() + labels: + - source: countAll() + style: primary + start: 0 + end: 18 + eb.fn.countAll().as("count"): + fixed: eb.fn.countAll().as("count") + labels: + - source: eb.fn.countAll() + style: primary + start: 0 + end: 24 diff --git a/.ast-grep/rule-tests/__snapshots__/zod-namespace-import-snapshot.yml b/.ast-grep/rule-tests/__snapshots__/zod-namespace-import-snapshot.yml index 07904da..01ec3d2 100644 --- a/.ast-grep/rule-tests/__snapshots__/zod-namespace-import-snapshot.yml +++ b/.ast-grep/rule-tests/__snapshots__/zod-namespace-import-snapshot.yml @@ -3,7 +3,7 @@ snapshots: ? | import { z } from "zod"; : fixed: | - import * as z from "zod" + import * as z from "zod"; labels: - source: import { z } from "zod"; style: primary @@ -12,7 +12,7 @@ snapshots: ? | import { z, ZodError } from "zod"; : fixed: | - import * as z from "zod" + import * as z from "zod"; labels: - source: import { z, ZodError } from "zod"; style: primary diff --git a/.ast-grep/rule-tests/no-countall-number-test.yml b/.ast-grep/rule-tests/no-countall-number-test.yml new file mode 100644 index 0000000..605ea5e --- /dev/null +++ b/.ast-grep/rule-tests/no-countall-number-test.yml @@ -0,0 +1,9 @@ +id: no-countall-number +valid: + # Plain countAll() is fine + - eb.fn.countAll().as("count") + # Other type arguments are fine + - eb.fn.countAll().as("count") +invalid: + # countAll() should be flagged + - eb.fn.countAll().as("count") diff --git a/.ast-grep/rules/no-countall-number.yml b/.ast-grep/rules/no-countall-number.yml index 3835ee8..da99e94 100644 --- a/.ast-grep/rules/no-countall-number.yml +++ b/.ast-grep/rules/no-countall-number.yml @@ -4,5 +4,5 @@ severity: error message: "Don't use countAll() - use countAll() instead. PostgreSQL COUNT returns bigint (string), so the type annotation is misleading." note: "Use Number() to convert the result if you need a number type." rule: - pattern: countAll() -fix: countAll() + pattern: $OBJ.countAll() +fix: $OBJ.countAll() diff --git a/db/schema.sql b/db/schema.sql index 5d58192..4ff9bcd 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1,4 +1,4 @@ -\restrict NNYnwssF6iMx0TXsk1nTprUEDwxna9uejAmsIiUlMLcPLlQlnnRVCusYtzweHXM +\restrict 5BJ290gQyiWozT7xy9KK6gwHkVEhwYWnEDL73SU3eBCj2RT22vojzydS1aJAQfF -- Dumped from database version 17.7 -- Dumped by pg_dump version 17.7 @@ -1084,7 +1084,7 @@ ALTER TABLE ONLY public.user_devices -- PostgreSQL database dump complete -- -\unrestrict NNYnwssF6iMx0TXsk1nTprUEDwxna9uejAmsIiUlMLcPLlQlnnRVCusYtzweHXM +\unrestrict 5BJ290gQyiWozT7xy9KK6gwHkVEhwYWnEDL73SU3eBCj2RT22vojzydS1aJAQfF --