Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
👷 Enforce datetime formatting boundaries with lint rules (#2541)
Luke Vellaec06ff0c005a
diff --git a/biome-plugins/no-raw-datetime-formatting.grit b/biome-plugins/no-raw-datetime-formatting.gritnew file mode 100644index 000000000..4bcd9a25e--- /dev/null+++ b/biome-plugins/no-raw-datetime-formatting.grit@@ -0,0 +1,22 @@+// Datetime formatting must go through lib/datetime so locale, timezone,+// and hour-cycle preferences are applied consistently (RAL-1244).+// The allowlist below is the escape hatch: lib/datetime itself, zone+// detection (timezone-schema), zone abbreviations (timezone-utils), and+// files still pending migration. Shrink it as RAL-1247 proceeds.+language js++or {+ `new Intl.DateTimeFormat($_)` as $match,+ `Intl.DateTimeFormat($_)` as $match,+ `$obj.toLocaleString($_)` as $match,+ `$obj.toLocaleDateString($_)` as $match,+ `$obj.toLocaleTimeString($_)` as $match+} where {+ $filename <: not or {+ r".*/src/lib/datetime/.*",+ r".*/src/utils/timezone-schema\.ts",+ r".*/src/components/time-zone-picker/timezone-utils\.ts",+ r".*/src/components/poll/manage-poll/use-csv-exporter\.ts"+ },+ register_diagnostic(span=$match, message="Do not format dates inline. Use the formatters in `@/lib/datetime` so locale, timezone, and hour-cycle preferences are applied consistently.")+}diff --git a/biome.json b/biome.jsonindex ef5326475..aeeafe283 100644--- a/biome.json+++ b/biome.json@@ -1,13 +1,31 @@{"$schema": "https://biomejs.dev/schemas/2.3.14/schema.json","root": true,- "plugins": ["./biome-plugins/use-icon-button-label.grit"],- "assist": { "actions": { "source": { "organizeImports": "on" } } },+ "plugins": [+ "./biome-plugins/use-icon-button-label.grit",+ "./biome-plugins/no-raw-datetime-formatting.grit"+ ],+ "assist": {+ "actions": {+ "source": {+ "organizeImports": "on"+ }+ }+ },"linter": {"enabled": true,"rules": {"recommended": true,"style": {+ "noRestrictedImports": {+ "level": "error",+ "options": {+ "paths": {+ "dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ }+ }+ },"noUselessElse": "off","noParameterAssign": "error","useAsConstAssertion": "error",@@ -42,6 +60,34 @@}}},+ "overrides": [+ {+ "includes": [+ "**/src/lib/dayjs.ts",+ "**/src/lib/datetime/**",+ "**/src/components/forms/poll-options-form/**",+ "**/src/components/headless-date-picker.tsx",+ "**/edit-options/page.tsx",+ "**/src/trpc/routers/polls.ts",+ "**/src/trpc/routers/index.ts",+ "**/api/private/utils/time-slots.ts",+ "**/src/utils/date-time-utils.ts",+ "**/src/components/poll/manage-poll/use-csv-exporter.ts",+ "**/src/app/**/blog/post-preview.tsx",+ "**/src/components/blog/date-formatter.tsx",+ "**/src/test/setup.ts",+ "**/tests/**",+ "packages/screenshots/**"+ ],+ "linter": {+ "rules": {+ "style": {+ "noRestrictedImports": "off"+ }+ }+ }+ }+ ],"formatter": {"enabled": true,"formatWithErrors": false,