Repository navigation
feat: add script to check for title case - #21484
Conversation
aslilac
left a comment
There was a problem hiding this comment.
I like the idea, and have been pushing for sentence case for my entire tenure, but this script is pretty janky
| // scripts/check-sentence-case.js | ||
| // |
There was a problem hiding this comment.
| // scripts/check-sentence-case.js | |
| // |
There was a problem hiding this comment.
Done. The script moved to site/scripts/check-sentence-case.mjs (next to check-compiler.mjs), and the stale filename header is gone. It now opens with a doc comment that describes what it checks and how to use it.
| // Geographic names (countries, territories, regions) | ||
| "British Indian Ocean Territory", | ||
| "Central African Republic", | ||
| "French Southern Territories", | ||
| "Northern Mariana Islands", | ||
| "Papua New Guinea", | ||
| "South Sandwich Islands", | ||
| "Syrian Arab Republic", | ||
| "United Arab Emirates", | ||
| "United States Minor Outlying Islands", | ||
| "New York City", | ||
| "Former Yugoslav Republic", |
There was a problem hiding this comment.
how often are any of these used in the product?
There was a problem hiding this comment.
Not often enough to keep. The country names only appeared in countriesGenerated.ts, which is excluded as generated code, so I removed the geographic list entirely. PROPER_NOUNS now only holds names that show up in UI text: Coder products and role names, third-party products, protocol names, and the fonts listed in the terminal font picker.
| ]); | ||
|
|
||
| // Words that should NOT be capitalized in title case (unless first word). | ||
| const MINOR_WORDS = new Set([ |
There was a problem hiding this comment.
is this necessary if the goal is to not capitalize words?
There was a problem hiding this comment.
Not necessary, removed. The check now reports any regular capitalized word that follows the first word of a phrase, so "Sign In To Coder" is caught without a special list of minor words.
| // Matches: "Title Case", "ACRONYM Title Case", "Title ACRONYM Case" | ||
| // Word types: [A-Z][a-z]+ (Title) or [A-Z]{2,} (ACRONYM) | ||
| const TITLE_CASE_PATTERN = | ||
| /(?:^|>|\s)((?:[A-Z]{2,}\s+)?[A-Z][a-z]+(?:\s+(?:[A-Z][a-z]+|[A-Z]{2,}))+)(?:\s|<|$|[.!?])/g; |
There was a problem hiding this comment.
I would consider myself pretty familiar with regex but this is nightmarish. I can't even begin to tell myself what this is actually doing, which is not a good sign.
There was a problem hiding this comment.
Agreed, it's gone. Text now comes from the TypeScript AST (JSX text plus string and template literals), which also lets the check skip literals that are code rather than UI text: imports, types, property names, and operands of ===/case comparisons. Detection splits the text on whitespace and walks the words; there is no title case regex anymore. site/scripts/check-sentence-case.test.mjs covers the cases.
|
|
||
| const newLines = lines.map((line, idx) => { | ||
| // Skip lines with ignore comment. | ||
| if (line.includes(IGNORE_COMMENT)) { |
There was a problem hiding this comment.
ignore comments are bad. "expect" (like @ts-expect-error) comments are better.
There was a problem hiding this comment.
Switched to sentence-case-expect. It applies to the next line, and the check fails when that line has nothing to report, so stale exceptions surface the same way an unused @ts-expect-error does. There are two in the tree today, both with a reason: the "Startup Script" log source name that coderd assigns (an API value compared in AgentRow.tsx), and a board column name inside an LLM prompt. Skipping equality and case operands also let me drop the earlier toLowerCase() workarounds for notification group names.
| if (allIssues.length > 0) { | ||
| if (fix) { | ||
| console.info( | ||
| `\x1b[32m✓ Fixed ${allIssues.length} sentence case issue(s):\x1b[0m\n`, |
There was a problem hiding this comment.
inlining escape codes without attempting to check if the output is actually even a tty (as opposed to a file or CI feed) is pretty unfortunate.
There was a problem hiding this comment.
Dropped the colors entirely. Output is now plain path:line:col: message lines like check-compiler.mjs, so it reads the same in a terminal, a file, or CI logs.
Move the checker to site/scripts/check-sentence-case.mjs next to check-compiler.mjs and address review feedback: - Read text from the TypeScript AST (JSX text plus string and template literals) instead of matching quotes with regexes. Literals that are code rather than UI text are skipped: imports, types, property names, and operands of equality checks or case clauses. - Detect title case by walking words instead of a large regex, which also removes the MINOR_WORDS list. - Replace ignore comments with "sentence-case-expect" comments that fail when the next line has nothing to report. - Print plain output without ANSI escapes. - Trim PROPER_NOUNS to names that appear in UI text. - Add unit tests. Re-run the conversion on current main, keep API values such as the "Startup Script" log source name unchanged, and update tests that assert on the converted text.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84137a2576
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…and string-matching patterns
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf0d13c094
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6182df0eb4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ck on entity names
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d097cb878c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abd853c7b9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Restore check-sentence-case.mjs and its tests from 6c77cb7. The later rounds grew the script from 691 to 1773 lines to handle code shapes that do not occur in this codebase; the 691-line version reports the same set of issues on the current tree once "Web Terminal" and "Workspace Proxy" are proper nouns. The UI copy and docs fixes from those rounds stay.
|
Scope reset: The checker is a heuristic. For shapes it misreads, use a |
"Agent hours" is the casing the license pages already use, so the capacity callout and the Coder Agents docs now match it.
Values of JSX attributes such as className, style, or href are code, so the sentence case checker now skips them and --fix cannot rewrite them. Display attributes (title, label, aria-label, and props named like confirmText) are still checked, and so are strings in event handlers. The "Agent Hours" proper noun is dropped in favor of "Agent hours".
Earlier edits renamed labels ("Create Template" to "New template") and
changed wording or formatting. Keep only the casing change for each.
"Agent Hours" is a named license allowance, so the license cards, the capacity callout, their stories, and the Coder Agents docs now spell it with a capital H, and the sentence case checker accepts only that form.
|
Can your agent provide benchmarks on the performance of this script in the description? |
The sentence case check compared every proper noun with every word of every text. Key the nouns by their first word so a word is compared only with the nouns that can start at it.
The terminal preview added on main shows a Go sample in a template literal, and the check reported the function names in its comments. An expect comment could only cover the line below it, so it could not be used for text inside a multi-line literal. A comment above the literal now applies to the whole literal.
Updated |
Historically, much of the UI used title case. This PR adds a lint check that reports title case UI text so it can be converted to sentence case, and converts the existing text.
site/scripts/check-sentence-case.mjsruns aspnpm lint:sentence-caseand is part ofpnpm lint. It reads JSX text and string/template literals from the TypeScript AST and skips literals that are code rather than UI text (imports, types, property names, tagged templates, values of JSX attributes that are not displayed such asclassNameorstyle, and operands of===/casecomparisons). JSX text across inline elements and conditional JSX is checked as one phrase.--fixlowercases the reported words. The checker is a heuristic: it is not meant to model every code shape, so use asentence-case-expectcomment where it guesses wrong.PROPER_NOUNS. For other deliberate exceptions, asentence-case-expectcomment on the line above suppresses the report and fails when that line no longer needs it.useDeploymentOptions) now use CLI flags instead of display names, so they do not depend on UI wording.Performance
pnpm lint:sentence-casetakes 1.6 s and is 2% to 4.5% ofpnpm lint. Measured on 82317c9 in a dev workspace (Xeon Platinum 8375C, 16 vCPUs, Node 22.23.4, TypeScript 6.0.2, warm file cache). CI buffers the output of the lint steps, so its log has no per-step times to compare against.typescriptloaded.tsand.tsxfiles insite/src(the rest are excluded), 210,684 lines, 6.1 MBsrc/api/api.ts, 121 KB)Each step of
pnpm lint, median wall time of 5 runs:lint:check(Biome)lint:oxlintlint:types(tsc)lint:circular-depslint:compilerlint:sentence-caseknippnpm linttsccache, 76 s withoutWhere the time goes, scaling, and limits
Phases of one run, from in-process timers. The split between parsing and checking is approximate.
typescriptmodulets.createSourceFile)Scaling, from synthetic inputs passed to
checkSource(median of 3 to 5 warm runs):main(378 reports in 175 files), a check,--fix, and a second--fixeach take 1.6 s to 1.7 s.Two limits, neither reachable with the current source:
RangeError: Maximum call stack size exceeded, because the phrases are spread intopush.