Skip to content

R0: clippy refuses the en-US entry points; the 23 callers it found read the workbook region - #4002

Draft
danilo-aguiar-br wants to merge 47 commits into
storytold:mainfrom
danilo-aguiar-br:region/r-root-cause
Draft

danilo-aguiar-br wants to merge 47 commits into
storytold:mainfrom
danilo-aguiar-br:region/r-root-cause

Conversation

@danilo-aguiar-br

Copy link
Copy Markdown

Stacked on the region series (#3718, #3989, #3990, #3992, #3993, #3994, #3997, #3998, #3999, #4000). Draft until they land; review the last three commits, R0, R2 and R1.

Root cause of the region bugs: every operation has a region-less entry point that hard-codes en-US (parse_input, parse_number_text, format_value, text_function, format_general_fit, Value::to_number), and a caller that picks it by mistake gets no warning.

  • R0: clippy.toml refuses those entry points (disallowed-methods, each with a reason). Every remaining en-US use carries #[allow(clippy::disallowed_methods)] // en-US on purpose: <why> (file syntax, canonical formulas and API, NUMBERVALUE, tests). cargo xtask ci already runs clippy with -D warnings, so a forgotten region now fails the build.
  • The guard found 23 callers that still read numeric text in en-US:
    • R1 (functions): argument helpers (num, numbers, int…) take the context and read text in the workbook's region, so in pt-BR ABS("-1,5"), SUM("1,5";2), ROUND("2,345";"2"), DAY("15/03/2026") and AGGREGATE's k work.
    • R2 (calc, engine): CHOOSE/INDEX/OFFSET/TRIMRANGE positions, typing -R$ 10 (became a formula), validation and conditional-format thresholds from formula text, and Paste Special on numbers stored as text.

en-US results are unchanged. Tests: text_arguments_read_in_the_workbook_region, position_arguments_read_numeric_text_in_the_workbook_region, typing_validation_and_paste_special_read_numeric_text_in_the_workbook_region; each fails without the change. cargo clippy --workspace --all-targets -- -D warnings: exit 0. nextest --workspace: 3737 run, 3735 passed; the 2 failures are glyph tests that fail on main without ẞ/ẻ fonts.

Note: date text in function arguments now also follows the workbook's date system (1904 workbooks read it in 1904).

@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

crates/numfmt wrote '.' and ',' as constants, so the Region data merged in storytold#3048 could not reach a cell. This threads a &Region through the formatter:

- format_value_in is the new entry point; format_value keeps its signature and delegates with EN_US, so current callers are unchanged.
- render_number, render_fraction and the General path take the decimal point and the thousands separator from the region.
- TEXT() stays en-US, because a worksheet function locale is its own decision.

Refs storytold#967.
Excel stores the canonical '.' decimal and ',' grouping, but people type the code their region uses: #.##0,00 in it-IT, #.##0,00 in pt-BR. NumberFormat::parse_in translates a hand-typed code to the canonical one before parsing, leaving quoted text, bracket tags and escaped characters alone.

The test covers the three paths in one place: format_value stays en-US, format_value_in shows the region, and parse_in reads the typed code with that region. It fails without the change, because neither parse_in nor format_value_in exists.
The Format Cells dialog needs the same translation in both directions: it shows a stored code with the region's separators and reads the edited code back. regional_code is public for that, and its own inverse is what makes one call serve both.
regional_code only swapped . and , so a region that groups with a
non-breaking space (fr-FR, pt-PT, ru-RU, cs-CZ) showed a code it does
not use and typed one it could not read back as grouping. Translate
region.group as well, in both directions, because the translation is no
longer its own inverse when the group is not ,.
A separator is one only between two digit placeholders, so the . of
dd.mm.yyyy and of hh:mm:ss.000 stays a date separator instead of
becoming a comma in a region that groups with it.
A grouping separator right after the digits scales the value by 1,000, and it has no digit after it, so regional_code and canonical_code left it in the other region's character: 0.0, stayed with a canonical comma in Italy and NumberFormat::parse_in("0,0.", it) kept a trailing dot the parser ignores. remap_separators now tracks that trailing run and converts it in both directions, including a run of them, so 0.0, shows as 0,0. and 0.0,, as 0,0..
- `cell.set` takes a JSON number in the workbook's region, so `3.141` stays
  3.141 in pt-BR instead of becoming 3141.
- A ribbon number format stores its canonical code once: `set_fmt` no longer
  canonicalizes a code it already converted, and the Format Cells dialog sends
  what the user sees.
- Criteria read numbers with the workbook region: `SUMIF`, `COUNTIF`, the
  database functions and the autofilter.
- Charts format their numbers with the workbook region through `render_in`;
  `render` keeps the en-US reading.
- Undo and redo keep the current region through `DocState::adopt_region`,
  which also leaves a clean workbook clean when the region changes.
Saving a workbook that was opened with a password as .xlsx now encrypts it again with that password through craft_offcrypto::encrypt (Agile, AES-256, SHA-512). The password stays in memory only, in DocState, and Debug redacts it. A decrypted workbook still has no path, so Save asks where to write and never replaces the original.
# Conflicts:
#	crates/core/src/parse.rs
#	crates/engine/src/tests.rs
…guage

The Conditional Formatting menu, More Borders and the title bar's More
commands and Share menus built their buttons from English text without
the translation every other ribbon menu uses, so they stayed English in
Portuguese. They now go through the language table, with the Portuguese
names added.
…ed as the engine's

With nothing copied in GridCraft, Paste Special refused with "the
clipboard is empty" even when another program, or a GridCraft window
running as another process, had copied text. It now pastes that text,
read in the workbook region, as Excel's Text paste format does.

A formula the cell editor can't read is reported as "There's a problem
with this formula: ...", translated, as cell.set reports it, instead of
the parser's bare token.
…ion's decimal

The cell editor rewrote a number typed with the formula language's decimal
separator to a dot. Since typed input is read in the workbook region, a
pt-BR or es-ES workbook then read 1,5 as the date 1 May. The number now
goes on with the region's own decimal separator.
…rder

The numpad's decimal key types the region's decimal separator (a comma in
pt-BR), whatever the keyboard layout, as a US layout sends a dot from it.

Keystrokes that arrive in one frame keep their order: text after Enter,
Tab, Esc or an arrow waits for the next frame instead of landing in the
cell being committed, and with no cell being edited the keys after the
first character are no longer dropped.
# Conflicts:
#	crates/ui-egui/src/formula_locale.rs

This branch has not been deployed

No deployments
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