Skip to content

refactor: extract rules dataset into rules.ts and drop orphaned CSV#6

Merged
pnodet merged 2 commits into
mainfrom
refactor/extract-rules-module
Jul 6, 2026
Merged

refactor: extract rules dataset into rules.ts and drop orphaned CSV#6
pnodet merged 2 commits into
mainfrom
refactor/extract-rules-module

Conversation

@pnodet

@pnodet pnodet commented Jul 4, 2026

Copy link
Copy Markdown
Member

Problem

The 352 normalization rules exist twice in this repo:

  • inline as RULES_DATA in index.ts (~650 of its 1140 lines)
  • as normadresse.csv at the repo root

The CSV is referenced by nothing: no code reads it, and files in package.json only ships dist, so it never reaches the published package either. It is an orphaned duplicate of the dataset that will silently drift the next time someone edits one copy but not the other.

Change

  • New rules.ts containing the CsvRule type and RULES_DATA, moved verbatim from index.ts (byte-for-byte, verified with diff against the previous block) and exported.
  • index.ts imports them from ./rules.ts and drops from 1140 to 490 lines.
  • normadresse.csv deleted — rules.ts is now the single source of truth.
  • README's "Data source & contributions" section now points to rules.ts.

Verification

  • bun test: 19 pass, 0 fail
  • bun run lint, bun run ts: clean
  • bun run build (zshy): dist emits rules.js/rules.cjs with all 352 rules; dist/index.js imports ./rules.js and dist/index.cjs requires ./rules.cjs, so the published package still carries the full dataset.

Pure move — no logic edits, behavior 100% unchanged.

🤖 Generated with Claude Code

The 352 normalization rules existed twice: inline as RULES_DATA in
index.ts and as normadresse.csv at the repo root. Nothing reads the
CSV (only dist is shipped), so it was an orphaned duplicate bound to
drift. Move the CsvRule type and RULES_DATA verbatim into rules.ts,
import them from index.ts, and delete the CSV. index.ts shrinks from
1140 to ~490 lines. No behavior change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pnodet, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7b1e0dc1-247d-4303-8a9c-2bad1960deb6

📥 Commits

Reviewing files that changed from the base of the PR and between fd9138b and 85d9ab7.

⛔ Files ignored due to path filters (1)
  • normadresse.csv is excluded by !**/*.csv
📒 Files selected for processing (3)
  • README.md
  • index.ts
  • rules.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/extract-rules-module

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pnodet

pnodet commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

Thermo-nuclear code quality review — APPROVE

This is exactly the decomposition the codebase needed: index.ts drops from 1140 to 565 lines (well back under the 1k threshold), and the boundary is the right one — a pure-data module. No structural regressions, no missed code-judo move; the simpler framing is this PR.

Verified (programmatically, not by eyeball)

  • Dataset byte-identical: extracted the RULES_DATA block from origin/main:index.ts and from rules.ts, diffed after stripping the export keyword — 569 lines each, zero diff. CsvRule type likewise identical. 352 rules in both.
  • CSV deletion is safe: parsed the deleted normadresse.csv and compared row-by-row against RULES_DATA — all 352 rows match (including the \g<N> backreference rows), so no information was lost; it was a true orphaned duplicate, and files: ["dist"] never shipped it anyway. Deleting it removes a real drift hazard.
  • Module boundary clean: rules.ts exports only CsvRule + RULES_DATA, no logic leaked. index.ts's only added line is the import; CsvRule is still genuinely used (line 99).
  • Build/dist correct: bun run build emits dist/rules.js / dist/rules.cjs with all 352 rules; dist/index.js imports ./rules.js, dist/index.cjs requires ./rules.cjs. Runtime smoke-tested both formats (BOULEVARD DU MARECHAL JEAN MARIE DE LATTRE DE TASSIGNYBD MAL J M DE LATTRE DE TASSIGNY).
  • Checks: bun test 19/19 pass, bun run lint clean, bun run ts clean.
  • README edit accurate; no stale .csv references remain anywhere.

Findings

None blocking, no fixes needed. rules.ts at 576 lines is fine — it is homogeneous data, not logic, and splitting a flat dataset would add indirection without buying clarity.

Verdict: approve — pure move confirmed, behavior 100% unchanged, dataset integrity verified programmatically.

🤖 Generated with Claude Code

* main:
  refactor!: compile rules eagerly and drop clearRulesCache (#5)
  refactor: remove dead regex-escape fallback in compileRules (#4)
  fix: anchor first-name abbreviation matching to whole words (#3)
  docs: document unapplied rule groups in RULES_DATA (#2)

# Conflicts:
#	index.ts

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@pnodet
pnodet merged commit b25884f into main Jul 6, 2026
4 checks passed
@pnodet
pnodet deleted the refactor/extract-rules-module branch July 6, 2026 14:36
pnodet added a commit that referenced this pull request Jul 6, 2026
* main:
  refactor: extract rules dataset into rules.ts and drop orphaned CSV (#6)
  refactor!: compile rules eagerly and drop clearRulesCache (#5)
  refactor: remove dead regex-escape fallback in compileRules (#4)
  fix: anchor first-name abbreviation matching to whole words (#3)
  docs: document unapplied rule groups in RULES_DATA (#2)

# Conflicts:
#	index.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant