From 34505dfe7916c93bc674188e665b2f045e7b3b06 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 13:05:24 +0000 Subject: [PATCH] fix(app): settings list column width is a GridLength; lint resource value types The Settings screen sized its section column from a Double resource; ColumnDefinition.Width needs a GridLength, so the template failed to load on Windows. xaml-lint now compares keyed Double, GridLength, Thickness and CornerRadius resources with the property they are used for, so this fails on Linux too. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- docs/DECISIONS.md | 1 + src/Titano.App/Sections/SettingsView.xaml | 2 +- src/Titano.Tools/Commands/XamlLintCommand.cs | 41 +++++++++++++++++++- src/Titano.Ui/Themes/Typography.xaml | 2 +- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 139d93f8..e26e4dd6 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -122,3 +122,4 @@ One line per decision: date · decision · alternative · reason. | 2026-10-02 | Render jobs never run on the server engine: render nodes claim them by codec and resolution, report failures, and a job fails after losing its node 5 times. | Managed rendering on the server | No server render handler yet. | | 2026-10-02 | Server settings page writes only edited keys to `server.json`; environment-fixed settings are locked; restart-only keys are flagged. Windows service: LocalSystem, automatic start, name `TitanoServer`. Admin panel: strict CSP (SVG charts, no inline styles), light theme only. | Rewrite the whole file / theme toggle | Secrets never written; DESIGN.md wins over the mockup toggle. | | 2026-10-02 | Migrations are numbered without gaps (0001 initial, 0002 archive index, 0003 server uploads). | Keep 0005 | Parallel workstreams picked numbers to avoid collisions; renumbered at merge. | +| 2026-10-02 | `xaml-lint` checks keyed value resources against the property type (GridLength for column/row sizes, Thickness, CornerRadius, Double). | Rely on Windows smoke tests | A Double used as a column width compiles and only fails when the template loads on Windows; the lint now fails on Linux too. | diff --git a/src/Titano.App/Sections/SettingsView.xaml b/src/Titano.App/Sections/SettingsView.xaml index eabe6757..62f231bd 100644 --- a/src/Titano.App/Sections/SettingsView.xaml +++ b/src/Titano.App/Sections/SettingsView.xaml @@ -28,7 +28,7 @@ - + diff --git a/src/Titano.Tools/Commands/XamlLintCommand.cs b/src/Titano.Tools/Commands/XamlLintCommand.cs index bf4c1f2e..87621e35 100644 --- a/src/Titano.Tools/Commands/XamlLintCommand.cs +++ b/src/Titano.Tools/Commands/XamlLintCommand.cs @@ -28,9 +28,11 @@ internal sealed class XamlLintCommand : ICommand && !f.Contains($"{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}", StringComparison.Ordinal)) .ToList(); - foreach (var file in files) + var documents = files.Select(f => (File: f, Doc: XDocument.Load(f, LoadOptions.SetLineInfo))).ToList(); + var valueTypes = ValueResourceTypes(documents.Select(d => d.Doc)); + + foreach (var (file, doc) in documents) { - var doc = XDocument.Load(file, LoadOptions.SetLineInfo); foreach (var el in doc.Descendants()) { var line = ((System.Xml.IXmlLineInfo)el).LineNumber; @@ -52,6 +54,13 @@ internal sealed class XamlLintCommand : ICommand problems.Add($"{where}: literal {attrName}=\"{v}\" on <{name}> (use {{l:Loc …}})"); } + foreach (var attr in el.Attributes()) + { + if (ExpectedValueType(name, attr.Name.LocalName) is not { } expected || ResourceKey(attr.Value) is not { } key) continue; + if (valueTypes.TryGetValue(key, out var actual) && actual != expected) + problems.Add($"{where}: {name}.{attr.Name.LocalName} needs a {expected} but resource {key} is a {actual}"); + } + // Literal element content such as Hello or Hi. if (name is "TextBlock" or "Run" or "Label" or "Button" && !el.HasElements && el.Value.Any(char.IsLetter)) problems.Add($"{where}: literal text in <{name}>"); @@ -63,6 +72,34 @@ internal sealed class XamlLintCommand : ICommand return Task.FromResult(problems.Count == 0 ? 0 : 1); } + /// Keyed resources of the value types WPF cannot convert into each other at run time (parsing succeeds, loading fails). + private static Dictionary ValueResourceTypes(IEnumerable documents) + { + var types = new Dictionary(StringComparer.Ordinal); + foreach (var el in documents.SelectMany(d => d.Descendants())) + { + if (el.Name.LocalName is not ("Double" or "GridLength" or "Thickness" or "CornerRadius")) continue; + if (el.Attributes().FirstOrDefault(a => a.Name.LocalName == "Key") is { } key) types[key.Value] = el.Name.LocalName; + } + return types; + } + + private static string? ExpectedValueType(string element, string attribute) => attribute switch + { + "Width" when element == "ColumnDefinition" => "GridLength", + "Height" when element == "RowDefinition" => "GridLength", + "Margin" or "Padding" or "BorderThickness" => "Thickness", + "CornerRadius" => "CornerRadius", + "Width" or "Height" or "MinWidth" or "MaxWidth" or "MinHeight" or "MaxHeight" or "FontSize" => "Double", + _ => null, + }; + + private static string? ResourceKey(string value) + { + var match = System.Text.RegularExpressions.Regex.Match(value, @"^\{(?:Static|Dynamic)Resource\s+(?:ResourceKey=)?([^\s}]+)\s*\}$"); + return match.Success ? match.Groups[1].Value : null; + } + private static bool HasToolTip(XElement el) => el.Attribute("ToolTip") is not null || el.Elements().Any(c => c.Name.LocalName.EndsWith(".ToolTip", StringComparison.Ordinal)) diff --git a/src/Titano.Ui/Themes/Typography.xaml b/src/Titano.Ui/Themes/Typography.xaml index 2a9a3f3f..dfc2d65b 100644 --- a/src/Titano.Ui/Themes/Typography.xaml +++ b/src/Titano.Ui/Themes/Typography.xaml @@ -34,7 +34,7 @@ 128 48 320 - 200 + 200 116 180