Skip to content

fix(sheets): normalize single-cell range in +set-style and +batch-set-style#548

Open
caojie0621 wants to merge 1 commit intomainfrom
fix/sheet_style
Open

fix(sheets): normalize single-cell range in +set-style and +batch-set-style#548
caojie0621 wants to merge 1 commit intomainfrom
fix/sheet_style

Conversation

@caojie0621
Copy link
Copy Markdown
Collaborator

@caojie0621 caojie0621 commented Apr 18, 2026

Summary

The /style and /styles_batch_update endpoints require the full Start:End range form and reject single-cell shorthand like A1 with [90202] wrong range. Neither shortcut was
normalizing:

  • +set-style used normalizeSheetRange, which only prefixes sheetId! but does not expand single cells.
  • +batch-set-style json.Unmarshal(--data) and passed the payload through unchanged, so ranges[] entries were never touched.

Changes

  • +set-style: swap normalizeSheetRangenormalizePointRange (already present in helpers.go and used by +append / +find / +read / +write-image). Single-cell A1 is
    expanded to sheetId!A1:A1.
  • +batch-set-style: add normalizeBatchStyleRanges() and invoke it in both DryRun and Execute, walking each data[].ranges[] entry through normalizePointRange.
  • Multi-cell spans (e.g. A1:B2) are passed through unchanged by normalizePointRange, so existing behavior is preserved.

Test plan

  • +set-style with single cell A1 — dry-run body shows 68ef76!A1:A1; live call succeeds with updatedRange=D1:D1.
  • +set-style with multi-cell A1:B2 — live call succeeds with updatedRange=A1:B2, updatedCells=4.
  • +batch-set-style with single cells ["68ef76!A2","68ef76!B2"] — dry-run shows expansion to A2:A2 / B2:B2; live call succeeds.
  • +batch-set-style mixing ["C1:D2", "E3"] — multi-cell span passes through as C1:D2; single cell expands to E3:E3; both applied in one request.

Refs

N/A

Summary by CodeRabbit

  • Bug Fixes

    • Single-cell ranges for style operations are expanded to explicit single-cell spans and batch range lists are consistently normalized.
    • Multi-cell spans are preserved; malformed or unexpected batch inputs are safely ignored without errors.
  • Documentation

    • Clarified the --data flag now requires sheet-prefixed ranges (e.g., sheet1!A1) for batch style inputs.

@github-actions github-actions bot added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Apr 18, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 219f9235-4ea7-4fa9-acae-242b8badcb61

📥 Commits

Reviewing files that changed from the base of the PR and between 06a10ba and e747016.

📒 Files selected for processing (3)
  • shortcuts/sheets/sheet_batch_set_style.go
  • shortcuts/sheets/sheet_cell_ops_test.go
  • shortcuts/sheets/sheet_set_style.go
✅ Files skipped from review due to trivial changes (1)
  • shortcuts/sheets/sheet_batch_set_style.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/sheets/sheet_set_style.go

📝 Walkthrough

Walkthrough

Batch-style data[].ranges entries are normalized in-place via a new normalizeBatchStyleRanges helper (applied in DryRun and Execute). The single +set-style shortcut now uses normalizePointRange instead of normalizeSheetRange for computing the appendStyle.range.

Changes

Cohort / File(s) Summary
Batch Range Normalization
shortcuts/sheets/sheet_batch_set_style.go
Add normalizeBatchStyleRanges(data) and invoke it in both DryRun and Execute. It treats top-level input as []interface{}, and for each object with a ranges array, converts string entries via normalizePointRange("", s). Non-matching shapes/types are skipped.
Single-Range Normalization Swap
shortcuts/sheets/sheet_set_style.go
Replace normalizeSheetRange(sheet-id, range) with normalizePointRange(sheet-id, range) when setting appendStyle.range in both DryRun and Execute.
Tests: range-expansion coverage
shortcuts/sheets/sheet_cell_ops_test.go
Add tests verifying single-cell ranges are expanded to X#:X# form in both set-style and batch-set-style (DryRun and Execute), preserving multi-cell spans and tolerating malformed/non-string inputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • fangshuyu-768

Poem

🐇 I nibble ranges, tidy and neat,
Turn "A1" to "A1:A1" sweet,
Batch by batch I hop and mend,
Expanding cells from end to end. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: normalizing single-cell ranges in the two style-setting shortcuts, which is the core purpose of the PR.
Description check ✅ Passed The description includes all required template sections: Summary explains the problem, Changes lists the modifications, and Test Plan documents verification steps with specific examples.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sheet_style

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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.93%. Comparing base (5a0e1d3) to head (e747016).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #548      +/-   ##
==========================================
+ Coverage   59.91%   59.93%   +0.01%     
==========================================
  Files         388      388              
  Lines       33147    33163      +16     
==========================================
+ Hits        19859    19875      +16     
  Misses      11420    11420              
  Partials     1868     1868              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shortcuts/sheets/sheet_batch_set_style.go`:
- Around line 87-107: Add unit tests for normalizeBatchStyleRanges to lock its
in-place mutation behavior and edge cases: create tests that call
normalizeBatchStyleRanges with (1) a top-level []interface{} where an entry has
ranges containing the string "xxx!A1" and assert it becomes "xxx!A1:A1"
(single-cell expansion via normalizePointRange), (2) a ranges string "xxx!A1:B2"
remains unchanged, (3) ranges containing non-string entries are ignored, (4) an
entry whose "ranges" is missing or not a []interface{} is skipped without
panicking, and (5) a non-array top-level input (e.g., a map or string) returns
without panic; reference the normalizeBatchStyleRanges function and its use of
normalizePointRange/normalizeSheetRange/splitSheetRange in test names/comments
and assert the original slice objects are mutated in place as expected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 43dbd7e5-fe6f-4bac-a386-7279d94f7994

📥 Commits

Reviewing files that changed from the base of the PR and between 5a0e1d3 and e2b6773.

📒 Files selected for processing (2)
  • shortcuts/sheets/sheet_batch_set_style.go
  • shortcuts/sheets/sheet_set_style.go

Comment thread shortcuts/sheets/sheet_batch_set_style.go
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 18, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@e747016a0b1ba1afe0d5ddb8355e2ca0ea1342b1

🧩 Skill update

npx skills add larksuite/cli#fix/sheet_style -y -g

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
shortcuts/sheets/sheet_cell_ops_test.go (1)

566-609: Consider adding a negative/edge-case test for non-conforming data shapes.

normalizeBatchStyleRanges silently no-ops when data isn't []interface{}, when entries aren't maps, or when ranges isn't []interface{}. A small test confirming that, e.g., a non-string entry in ranges or a missing ranges key passes through unchanged (without panicking) would lock in that defensive behavior and protect against future regressions in the type-assertion chain.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/sheets/sheet_cell_ops_test.go` around lines 566 - 609, Add a
negative/edge-case unit test(s) that exercises normalizeBatchStyleRanges to
ensure it safely no-ops on non-conforming shapes (so we don't regress its
defensive type-assertion behavior); specifically write a test in
shortcuts/sheets/sheet_cell_ops_test.go that calls the same code path (e.g., via
SheetBatchSetStyle.DryRun or by invoking normalizeBatchStyleRanges indirectly)
with inputs where top-level data is not []interface{}, an entry is not a map, a
ranges key is missing, and a ranges array contains a non-string value, and
assert the call completes without panic and the returned value is unchanged (or
equal to the original input) for each scenario. Ensure the test names reference
the behavior (e.g., TestNormalizeBatchStyleRanges_NonConformingData) so future
reviewers can locate normalizeBatchStyleRanges-related tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@shortcuts/sheets/sheet_cell_ops_test.go`:
- Around line 566-609: Add a negative/edge-case unit test(s) that exercises
normalizeBatchStyleRanges to ensure it safely no-ops on non-conforming shapes
(so we don't regress its defensive type-assertion behavior); specifically write
a test in shortcuts/sheets/sheet_cell_ops_test.go that calls the same code path
(e.g., via SheetBatchSetStyle.DryRun or by invoking normalizeBatchStyleRanges
indirectly) with inputs where top-level data is not []interface{}, an entry is
not a map, a ranges key is missing, and a ranges array contains a non-string
value, and assert the call completes without panic and the returned value is
unchanged (or equal to the original input) for each scenario. Ensure the test
names reference the behavior (e.g.,
TestNormalizeBatchStyleRanges_NonConformingData) so future reviewers can locate
normalizeBatchStyleRanges-related tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 99b441dd-70fc-43ec-bb9c-88c4369618ca

📥 Commits

Reviewing files that changed from the base of the PR and between e2b6773 and 06a10ba.

📒 Files selected for processing (3)
  • shortcuts/sheets/sheet_batch_set_style.go
  • shortcuts/sheets/sheet_cell_ops_test.go
  • shortcuts/sheets/sheet_set_style.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • shortcuts/sheets/sheet_set_style.go
  • shortcuts/sheets/sheet_batch_set_style.go

…-style

/style and /styles_batch_update require full "A1:A1" form and reject
single-cell shorthand "A1". +set-style was using normalizeSheetRange
(prefix-only) and +batch-set-style passed --data through unchanged,
so both failed with `wrong range` when callers supplied a single cell.

Switch +set-style to normalizePointRange, and walk each ranges[]
entry in +batch-set-style through normalizePointRange before sending.
Multi-cell spans pass through unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant