refactor: spell control characters as escapes, and lint for raw ones - #29948
Open
veksa wants to merge 2 commits into
Open
refactor: spell control characters as escapes, and lint for raw ones#29948veksa wants to merge 2 commits into
veksa wants to merge 2 commits into
Conversation
Signed-off-by: Aleksandr Khizhnyi <mendler88@gmail.com>
Signed-off-by: Aleksandr Khizhnyi <mendler88@gmail.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe pull request adds a control-byte lint script, tests its detection and reporting behavior, wires it into package scripts and CI, and replaces raw control-character source occurrences with escaped or named representations. ChangesControl-byte linting
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
n/a — nothing filed. Say the word if you'd rather talk the check over first.
Summary
Two files hold a control character as a raw byte where an escape was meant. Same string at runtime, so nothing misbehaves. The cost is all in the tooling around the code.
packages/2-sql/1-core/contract/src/validators.tsseparates the halves of a(tableName, name)key with a NUL. Git reads a file containing a NUL as binary, so GitHub shows no diff for 1100 lines of validation logic, and blame,log -Sand grep skip it.packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.tshas a raw BEL in a test input. That test is about escaping control characters, every neighbouring line writes its own character as an escape, and the expectation on the same line asks for the escaped form — so the intent isn't in question.The separator itself is a good idea and a house pattern.
schema-diff.tshasSIBLING_KEY_DELIMITER,psl-field-resolution.tshasMODEL_COORDINATE_SEPARATOR,migration-graph.tsspells out the reasoning in a comment: no identifier can contain a NUL, so("a_b", "c")can never collide with("a", "b_c"). Only the spelling was off.The second commit adds
pnpm lint:control-bytesso nobody has to catch this by eye next time.Testing performed
Finding them meant scanning all 6711 tracked files byte by byte. Git's own binary flag wasn't enough — it only reads the first 8000 bytes, so a NUL further down a long file never shows up.
pnpm lint:control-bytesagainst the pre-fix files exits 1 and names both, with line and byte; on the fixed tree it exits 0node --test scripts/lint-control-bytes.test.mjs— 7 cases: NUL, the rest of the C0 range, an already-escaped character, tab/LF/CR, binary formats, and both exit codespnpm test:scripts— 395 tests, 371 pass. Without this branch it's 388/364 with the same 24 failures, so nothing here adds one. Those 24 are path-separator assertions in unrelated scripts that only fail on Windowspnpm --filter @internal/emitter test208/208 andpnpm --filter @internal/sql-contract test322/322, plus typecheck and lint on bothpnpm lint:workflowsafter adding the CI stepgit ls-files --eolnow callsvalidators.tsi/lf, where it wasi/-text. It's a text file again.Skill update
n/a — internal tooling, plus two literals rewritten to the same value.
Checklist
git commit -s) per the DCO.Notes for the reviewer
The check skips binaries by file extension rather than by sniffing content, which is the one call worth arguing about. A NUL byte is what makes a file look binary in the first place, so sniffing would skip exactly the files this is meant to find. The cost is that a new binary format has to be added to the list, and until it is the check complains instead of going quiet. I'd rather have it that way round, but it's your call.
It also only looks at tracked files, so a violation in a file you haven't added yet is invisible. I walked into that myself while writing it: the script picked up a raw NUL in its own doc comment and reported the tree clean, because it wasn't tracked. CI runs against a commit, so everything is tracked there.
In
validators.tsI named a constant instead of inlining the escape, following the two sites that already do that. Both styles exist in the tree, so switch me if you prefer the inline one.Two commits, literals first and the check second, so you can drop the CI step without losing the fix.
Summary by CodeRabbit
New Features
Bug Fixes
Tests