Skip to content

refactor: move the shadow token into a colorset - #37

Merged
romchornyi merged 6 commits into
masterfrom
refactor/shadow-colorset
Oct 30, 2026
Merged

romchornyi merged 6 commits into
masterfrom
refactor/shadow-colorset

Conversation

@romchornyi

@romchornyi romchornyi commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Every Color.dash token is a colorset with light and dark variants, except shadow. That token was built in code as UIColor(red: 0.72, green: 0.76, blue: 0.8, alpha: 0.1), wrapped in a trait switch that returns .clear in dark mode. Because of it, conventions.sh rule 5 ("no colors built from components") exempted all of Color+DashUI.swift, so any other color built from components in that file would also have passed.

Stacked on #36 (both change conventions.sh). Once #36 merges, this PR's base becomes master.

What was done?

  • New Shadow.colorset (Colors/Shadow/): light is sRGB 0.72 / 0.76 / 0.80 at alpha 0.10, dark is fully transparent. Color.dash.shadow is now dashAsset("Shadow"); its public name and type do not change.
  • Color+DashUI.swift no longer builds colors in code or imports UIKit.
  • conventions.sh:
    • Rule 5 now covers Color+DashUI.swift.
    • That file's only remaining exemption is from the computed-name check, since it holds the token resolver. The variable is renamed to tokens / tokens_file to say so.
    • A fixture checks that a Color(red:…) appended to the file fails, at that line.
  • Docs: foundation.md and navigation-and-containers.md describe the token as the Shadow colorset.
  • macOS: the macOS build, which only serves swift build and previews, now gets the light shadow in light appearance, where it used to get .clear. Dark appearance stays clear.

How Has This Been Tested?

  • swift build (macOS), the iOS Release device build, and xcodebuild test on the iOS 27 simulator: 18 tests, 0 failures.
  • conventions.sh passes (161 imagesets, 162 colorsets). On the tree before this change, the updated script reports exactly the old UIColor(red:).
  • tests/conventions-test.sh passes all cases, and shellcheck is clean.
  • api-check.sh against refactor: route asset names through DashIcon #36's head reports no breaking changes.
  • Pixels: MenuViewModifier, the only user of the token, was rendered on the iOS simulator in light and dark with a test harness, before and after this change. The PNGs are byte-identical: the 10 % shadow in light, nothing in dark.

Before / After

  • No visual change (refactor, tests, docs). Say why in "What was done?".

On iOS the same color now comes from the asset catalog. The before and after renders of MenuViewModifier are byte-identical in light and dark (see "How Has This Been Tested?").

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • The shadow color now uses the Shadow asset across supported platforms, replacing platform-specific behavior.
  • Documentation

    • Updated color and navigation guidance to describe the shadow color as an asset and removed its previous light- and dark-mode behavior description.
  • Tests

    • Added coverage to detect hardcoded colors in the color-token definitions.

romchornyi and others added 2 commits October 27, 2026 10:59
The toast, nav bar and converter badge drew their icons from string names
that conventions.sh could not see; they now use DashIcon cases.
NavigationBarElement keeps its public raw values and draws through
DashIcon.NavigationBar; a test keeps the two in step.

conventions.sh flags a package-bundle lookup whose name is not one
literal (outside the Icon_DashUI / Color+DashUI resolvers), a computed
name in the host bundle, an empty name and a computed dashAsset() name.
A unit test checks that every DashIcon case resolves in the package
bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Color.dash.shadow was the only token built in code (UIColor(red:) behind
a trait switch), which kept Color+DashUI.swift exempt from the
"no colors from components" rule. It is now the Shadow colorset, subtle
on light and clear on dark, and the rule covers that file too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 9c8cc0c and 8a4c584.

Files ignored due to path filters: 2
  • Sources/DashUIKit/Resources/Media.xcassets/Colors/Shadow/Contents.json is excluded by !**/*.xcassets/**
  • Sources/DashUIKit/Resources/Media.xcassets/Colors/Shadow/Shadow.colorset/Contents.json is excluded by !**/*.xcassets/**
Files selected for processing: 5
  • .github/scripts/conventions.sh
  • .github/scripts/tests/conventions-test.sh
  • Sources/DashUIKit/Foundation/Color+DashUI.swift
  • docs/foundation.md
  • docs/navigation-and-containers.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

DashColors.shadow now resolves the Shadow colorset through dashAsset on all supported platforms. The conventions script now checks Color+DashUI.swift for hardcoded colors and includes a regression test for that check.

Changes: Shadow colorset and convention checks

Layer / File(s) Summary
Resolve and document the shadow colorset
Sources/DashUIKit/Foundation/Color+DashUI.swift, docs/foundation.md, docs/navigation-and-containers.md
DashColors.shadow now uses the Shadow colorset through dashAsset on all supported platforms. The documentation identifies the colorset as the source.
Check color tokens for hardcoded colors
.github/scripts/conventions.sh, .github/scripts/tests/conventions-test.sh
The conventions script checks Color+DashUI.swift for hardcoded colors and retains its exemption for asset-name checks in the token resolver. A regression test checks that a component-built color in that file is reported.

Priority: Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Refactor

Possibly related PRs

  • dashpay/DashUIKit#30: Introduced the conventions script and hardcoded-color rule that this change extends.
  • dashpay/DashUIKit#36: Expanded asset scanning and dashAsset checks related to the resolver rules used by this change.
Merge Risk: Minimal · up to 8a4c5

The shadow colorset migration and expanded convention checks have no established merge-blocking issue. Merge after normal checks pass.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: moving the shadow token into a colorset.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files. (2 skipped: 2 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

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

@romchornyi-pitcrew

romchornyi-pitcrew commented Oct 27, 2026 •

Copy link
Copy Markdown

✅ Review posted for commit 5a83176 · triage: normal · approve · took 0 min

@romchornyi-pitcrew romchornyi-pitcrew 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.

✅ APPROVE · 5 non-blocking recommendations · no blockers or majors — reviewed at 962cca5140

Level Verdict
1 · Idea ✅ valid shadow was the only Color.dash token built in code, and it kept all of Color+DashUI.swift out of rule 5.
2 · Architecture ✅ right layer A colorset like every other token; the scanner exemption shrinks to what the file still needs (the token resolver).
3 · Completeness ✅ complete One user (MenuViewModifier); switchThumbShadow is a separate colorset token and left for a design decision; both docs that describe the token are updated.
4 · Code ✅ clean iOS parity checked: light sRGB 0.72/0.76/0.80 @ 0.10 as before, dark alpha 0 (renders as .clear); public name and type unchanged; catalog JSON valid, no namespace, no name clash.
5 non-blocking recommendations
  1. "Every token is a colorset" is wider than rule 5 —
    # #colorLiteral), Color+DashUI.swift included: every token is a colorset;
    — rule 5 catches component initializers only; a token written as .black.opacity(0.1) or Color(uiColor: UIColor { … }) without component labels still passes. Requiring every public static var in DashColors to be exactly dashAsset("<literal>") would make the claim true. (not verified)
  2. macOS change is light appearance only —
    public static var shadow: Color { dashAsset("Shadow") }
    — the catalog's dark entry also applies on macOS, so dark previews stay transparent; the PR description could say "in light appearance".
  3. Rule 5 message inside Color+DashUI.swift —
    out(li, "hardcoded color: add a token to Foundation/Color+DashUI.swift backed by a colorset and use Color.dash.<token>")
    — "add a token to Foundation/Color+DashUI.swift" reads oddly for a violation in that very file; "back the token with a colorset and use dashAsset(\"Name\")" fits both places.
  4. Ragged comment wrap —
    # declared. In this package
    — # declared. In this package breaks mid-sentence; re-wrap lines 192–197.
  5. Doc comment restates catalog values —
    /// Subtle on light, clear on dark.
    — no other token documents its values in Swift, and this one goes stale if the colorset changes.
Review details Triage: normal (token refactor + CI script), stacked on #36. Levels 1–3 inline. Level 4: general lane (`/code-review high`) and a UI specialist lane (colour parity incl. trait coverage, token users, public API, catalog validity, docs). Verifier: no finding of major or higher; parity facts checked against the colorset JSON and the removed code.

🤖 Reviewed with Claude Code

romchornyi and others added 3 commits October 27, 2026 11:56
…y are

Follow-up to the review of this PR:
- each call's literal names are read once, so a ternary in the host
  bundle or a repeated missing name is reported once;
- a .custom(…) that passes a bundle is a lookup wherever it sits, and a
  computed name in .main / nil / .none is reported;
- an empty name also gets its bundle checked;
- negative needles ("!text") are checked in pass cases too;
- CLAUDE.md, docs/foundation.md and the script header say what the scan
  does and does not follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-up to the review of this PR: the header no longer claims every
token is a colorset (rule 5 only sees colors built from components), the
violation message says to add a colorset and a token, and a comment is
re-wrapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@romchornyi-pitcrew romchornyi-pitcrew 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.

✅ no blockers · no majors · 2 non-blocking recommendations — reviewed at 5a8317683b

Level Verdict
1 · Idea ✅ valid Unchanged since the last review
2 · Architecture ✅ right layer Unchanged
3 · Completeness ✅ complete Unchanged: one user, both docs updated
4 · Code ✅ clean 5a83176 changes only messages and comments. The rest of the new diff is the merge of #36's 3171eed

Closed since the last review (bot review on 962cca5)

  • The rule 5 header now says what it covers in Color+DashUI.swift: tokens read from colorsets with dashAsset("Name"). It no longer claims "every token is a colorset".
    # 5. no color built from components (red:, white:, hue:, gray:, .sRGB, hex,
    # #colorLiteral), Color+DashUI.swift included, where tokens are read from
    # colorsets with dashAsset("Name");
  • The rule 5 message works inside Color+DashUI.swift too ("add a colorset and a token for it … (dashAsset("Name"))").
    if (ml ~ /#colorLiteral/) out(li, "hardcoded color: add a colorset and a token for it in Foundation/Color+DashUI.swift (dashAsset(\"Name\")), and use Color.dash.<token>")
    and
    out(li, "hardcoded color: add a colorset and a token for it in Foundation/Color+DashUI.swift (dashAsset(\"Name\")), and use Color.dash.<token>")
  • The ragged comment wrap is fixed.
    # checked against the catalog. Icon_DashUI.swift and Color+DashUI.swift are
    # exempt from this check only: they hold the resolvers for DashIcon cases
    # and Color.dash tokens, whose names rules 1 and 2 check where they are
    # declared. In this package only DashIconSource has a .custom case that
    # takes a bundle. A literal with an escape counts as computed: its name is
    # not read below.
2 non-blocking recommendations
  1. Doc comment restates catalog values — https://github.com/dashpay/DashUIKit/blob/5a8317683b751332f10d6008e4dd0a899766c786/Sources/DashUIKit/Foundation/Color+DashUI.swift — the shadow doc comment still repeats the colorset's sRGB values. No other token does this, and the comment goes stale if the colorset changes. (open from the last review)
  2. The merged #36 script change carries its own open points — the false no imageset named "…" for a literal in a ternary's condition, and the per-line duplicates. They are listed on #36 (review 5665698584) and are not repeated here, because they belong to that PR.
Review details

Re-review of the bot review on 962cca5. The new diff is 5a83176 (messages and comments) plus a merge of #36 3171eed, which the bot reviewed on #36 an hour earlier, general lane included. Following the re-review rule, only the touched level was re-checked: level 4, inline, against the diff. No lane was re-run for message-only changes. Two items stay unaddressed and are not repeated, as they were non-blocking: the macOS light-appearance wording in the description, and the doc comment (kept as item 1).

When this review was written, Conventions and both builds were green. Public API, Lint CI config, Before / After screenshots and Validate PR title were still pending.

🤖 Reviewed with Claude Code

Base automatically changed from refactor/asset-names-dashicon to master October 30, 2026 11:31
…orset

# Conflicts:
#	.github/scripts/conventions.sh
#	.github/scripts/tests/conventions-test.sh
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.

3 participants