Skip to content

Commit c6d0e25

Browse files
committed
fix(widgets): renumber the unroutable-child rule to MDL-WIDGET30, and guard the numbers
MDL-WIDGET29 was taken twice. This branch used it for the unroutable-child rule; main independently used it for the retired-spelling rule. Both were correct when written — nothing compared them until a rebase put both in the tree, and the number is only ambiguous once they meet. Renumbered this branch's rule to MDL-WIDGET30 and added the comparison as a test, because no amount of care at authoring time prevents a merge collision: the guard has to run where the collision exists, which is CI on the merge. The invariant is not "one file per id" — MDL-WIDGET21 is legitimately raised from two paths and is still one rule — so known pairs are listed and anything new fails, which is the moment to decide whether it is one rule or two. A second test keeps the numbers dense, so "the next free one" has an answer. Proven by reintroducing the collision: the guard names both files and says what to do. Its first version scanned for `RuleID: "…"` and missed MDL-WIDGET22, which is declared as a named constant — so it reported a gap that was not there. It now matches quoted literals, which is also what separates a declaration from a doc comment naming a neighbouring rule. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JXnEgoc2NQP1Y2TWMCMXC4
1 parent 6c12702 commit c6d0e25

7 files changed

Lines changed: 138 additions & 11 deletions

File tree

‎.claude/skills/mendix/overview-pages/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ datagrid dg (...) { column colName (attribute: Name) { textfilter f1 } }
225225
-- ✅ gallery: the widget-wide filter bar, which the gallery calls `filter`
226226
gallery g (...) { filter f { textfilter f1 } }
227227

228-
-- ❌ the gallery form on a data grid — MDL-WIDGET29
228+
-- ❌ the gallery form on a data grid — MDL-WIDGET30
229229
datagrid dg (...) { column colName (attribute: Name) filter f { textfilter f1 } }
230230
```
231231

‎cmd/mxcli/syntax/features_page.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ CREATE PAGE Sales.Detail (Title: 'Detail', Layout: Atlas_Core.Atlas_Default) {
133133
"GALLERY g (...) { FILTER f { TEXTFILTER tf (Attribute: A) } }\n" +
134134
"-- A FILTER block written on a DATAGRID is not a column filter and not a\n" +
135135
"-- container the grid declares — it used to be dropped on write with no\n" +
136-
"-- diagnostic, and is now refused (MDL-WIDGET29).\n\n" +
136+
"-- diagnostic, and is now refused (MDL-WIDGET30).\n\n" +
137137
"-- Inputs\nTEXTBOX name (Label: 'L', Attribute: Attr)\nTEXTAREA | DATEPICKER | COMBOBOX | CHECKBOX | RADIOBUTTONS\n\n" +
138138
"-- Actions\nACTIONBUTTON name (Caption: 'C', Action: SAVE_CHANGES, ButtonStyle: Primary)\nLINKBUTTON name (Caption: 'C', Action: ...)\n\n" +
139139
"-- Display\nDYNAMICTEXT name (Content: 'Hello, {1}!', ContentParams: [{1} = Name])\nTITLE name (Content: 'Heading')\nIMAGE name (Image: 'Module.Collection.ImageName')\nIMAGE name (ImageType: imageUrl, ImageUrl: 'https://…')\n" +
@@ -154,7 +154,7 @@ CREATE PAGE Sales.Detail (Title: 'Detail', Layout: Atlas_Core.Atlas_Default) {
154154
"-- DROPDOWN -> COMBOBOX\n" +
155155
"-- And three the executor refuses on BOTH engines, each with its own message:\n" +
156156
"-- STATICTEXT (writes Forms$Text, a type Mendix no longer has — the\n" +
157-
"-- project could not be OPENED afterwards; MDL-WIDGET29.\n" +
157+
"-- project could not be OPENED afterwards; MDL-WIDGET30.\n" +
158158
"-- Use DYNAMICTEXT with a literal Content.)\n" +
159159
"-- REFERENCESELECTOR (unsupported widget type)\n" +
160160
"-- LEGACYDATAGRID (use DATAGRID for the pluggable equivalent on Mendix 11+)",

‎docs/01-project/MDL_QUICK_REFERENCE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,8 +1340,8 @@ MDL uses explicit property declarations for pages:
13401340
| Page CSS class / style | `Class: 'css-class', Style: 'css: rule'` | `(Title: 'Home', Class: 'container-fluid bg-light', Style: 'min-height: 100vh')` — the page's Appearance |
13411341
| Page variables | `variables: { $name: type = 'expr' }` | `variables: { $show: boolean = 'true' }` |
13421342
| Repeated widget entries | `<container> <name> ( … )` **in the widget body** | A repeatable property (FileUploader `allowedFileFormats`, HTML Element `attributes`, a chart's `series`) is a block, never a property value. `attributes: [(attributeName: 'x')]` is **MDL-WIDGET27** — it used to check clean, exec, and vanish from storage. `describe widget <name> -p app.mpr` lists the container keywords |
1343-
| Data grid 2 column filter | `column c (attribute: A) { textfilter f }` | **Inside the column's braces.** `column c (…) filter f { … }` is the GALLERY form — the grammar reads it as a column with no body plus a sibling `filter` widget, which the grid has nowhere to put; it used to be dropped on write and is now **MDL-WIDGET29**. A grid-wide filter bar is `controlbar`; a gallery spells that same slot `filter`. Match the filter to the column's type (String → `textfilter`, number → `numberfilter`, DateTime → `datefilter`, Enumeration → `dropdownfilter`, Boolean → none) |
1344-
| Widget with nowhere to go | any widget in a pluggable widget's body | A child matching no container, slot or `template` catch-all is **MDL-WIDGET29** at check time and refused by `exec`. `describe widget <name> -p app.mpr` lists what the parent declares. Needs the parent's definition, so it is silent without `-p` |
1343+
| Data grid 2 column filter | `column c (attribute: A) { textfilter f }` | **Inside the column's braces.** `column c (…) filter f { … }` is the GALLERY form — the grammar reads it as a column with no body plus a sibling `filter` widget, which the grid has nowhere to put; it used to be dropped on write and is now **MDL-WIDGET30**. A grid-wide filter bar is `controlbar`; a gallery spells that same slot `filter`. Match the filter to the column's type (String → `textfilter`, number → `numberfilter`, DateTime → `datefilter`, Enumeration → `dropdownfilter`, Boolean → none) |
1344+
| Widget with nowhere to go | any widget in a pluggable widget's body | A child matching no container, slot or `template` catch-all is **MDL-WIDGET30** at check time and refused by `exec`. `describe widget <name> -p app.mpr` lists what the parent declares. Needs the parent's definition, so it is silent without `-p` |
13451345
| Inspect a widget | `describe widget <keyword\|'widget id'>;` | `describe widget combobox;` — properties, enum values, defaults and the editor rules that HIDE properties under some configurations. **Body containers** names what the widget's body takes, and for an object list the widgets-typed slots *inside one item* plus the widget types that route into each — that is where `column … { textfilter }` is spelled out. Works with no project open; with one, reads the installed `.mpk` (version-accurate, and the only place a Marketplace widget appears). Same output as `mxcli widget describe` |
13461346
| Widget name | Required after type | `textbox txtName (...)` |
13471347
| Attribute binding | `attribute: AttrName` | `textbox txt (label: 'Name', attribute: Name)` |

‎mdl-examples/bug-tests/datagrid-filter-block-dropped-silently.mdl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
-- leftovers were discarded. Not datagrid-specific: one `continue` per pass,
2525
-- shared by every pluggable widget.
2626
--
27-
-- Fix: MDL-WIDGET29 at check time and a refusal in buildPluggable at exec time,
27+
-- Fix: MDL-WIDGET30 at check time and a refusal in buildPluggable at exec time,
2828
-- both from unroutedPluggableChildren() so they cannot disagree. The message
2929
-- names the spelling THIS widget uses for the same slot, since an author who
3030
-- copied a gallery example needs `controlbar`, not a list to search.
3131
--
32-
-- This repro is a plain .mdl, not .fail.mdl, on purpose: MDL-WIDGET29 needs the
32+
-- This repro is a plain .mdl, not .fail.mdl, on purpose: MDL-WIDGET30 needs the
3333
-- parent widget's DEFINITION, which comes from the project's installed .mpk, and
3434
-- `make check-mdl` runs `check` with no project (see the Makefile's note on
3535
-- #891/#892). The refusal is covered by widget_unrouted_children_test.go; this
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package executor
4+
5+
import (
6+
"os"
7+
"path/filepath"
8+
"regexp"
9+
"sort"
10+
"strings"
11+
"testing"
12+
)
13+
14+
// MDL-WIDGET rule numbers are handed out by hand, from no registry, by grepping
15+
// for the highest one in use. That has now failed twice:
16+
//
17+
// - once at authoring time, picking 27 for a rule that already existed;
18+
// - once at MERGE time, where two branches independently took 29 — one for a
19+
// retired-spelling rule, one for an unroutable child — and each was correct
20+
// in isolation. Nothing compared them until a rebase put both in the tree.
21+
//
22+
// The second is the one that matters, because no amount of care at authoring
23+
// time prevents it. This test does the comparison, so the collision fails on the
24+
// merge that creates it rather than shipping as two rules answering to one id.
25+
//
26+
// The invariant is NOT "one file per id": a rule legitimately raised from two
27+
// places stays one rule. So known pairs are listed, and anything new fails —
28+
// which is exactly the moment to check whether it is one rule or two.
29+
var widgetRuleIDsRaisedFromSeveralFiles = map[string][]string{
30+
// One rule about a property that is hidden under the current configuration,
31+
// raised from the content-params path and the editability path.
32+
"MDL-WIDGET21": {"validate_widget_contentparams.go", "validate_widget_editability.go"},
33+
}
34+
35+
// Matched as a QUOTED literal rather than after `RuleID:`, because an id is
36+
// also declared as a named constant (imageSourceRule = "MDL-WIDGET22") — the
37+
// first version of this guard missed that one and reported a gap that was not
38+
// there. Quoting is what separates a declaration from a doc comment mentioning
39+
// a neighbouring rule.
40+
var widgetRuleIDRe = regexp.MustCompile(`"(MDL-WIDGET\d+)"`)
41+
42+
func TestWidgetRuleIDsAreNotReused(t *testing.T) {
43+
files, err := filepath.Glob("*.go")
44+
if err != nil {
45+
t.Fatal(err)
46+
}
47+
byID := map[string]map[string]bool{}
48+
for _, f := range files {
49+
if strings.HasSuffix(f, "_test.go") {
50+
continue
51+
}
52+
src, err := os.ReadFile(f)
53+
if err != nil {
54+
t.Fatal(err)
55+
}
56+
for _, m := range widgetRuleIDRe.FindAllStringSubmatch(string(src), -1) {
57+
if byID[m[1]] == nil {
58+
byID[m[1]] = map[string]bool{}
59+
}
60+
byID[m[1]][f] = true
61+
}
62+
}
63+
if len(byID) == 0 {
64+
t.Fatal("no MDL-WIDGET rule ids found — this guard would pass vacuously")
65+
}
66+
67+
for id, files := range byID {
68+
if len(files) < 2 {
69+
continue
70+
}
71+
var got []string
72+
for f := range files {
73+
got = append(got, f)
74+
}
75+
sort.Strings(got)
76+
want := append([]string(nil), widgetRuleIDsRaisedFromSeveralFiles[id]...)
77+
sort.Strings(want)
78+
if strings.Join(got, ",") != strings.Join(want, ",") {
79+
t.Errorf("%s is raised from %v.\n"+
80+
"If those are TWO different rules, one of them needs a new number — take the next "+
81+
"free one after the highest in use, and check again after rebasing, because another "+
82+
"branch may have taken it meanwhile.\n"+
83+
"If it is ONE rule raised from two places, add it to "+
84+
"widgetRuleIDsRaisedFromSeveralFiles.", id, got)
85+
}
86+
}
87+
}
88+
89+
// The numbers are also expected to be dense, so "the next free one" is a
90+
// question with an answer. A gap means a rule was removed without its number
91+
// being reused, which is fine but worth stating deliberately rather than
92+
// leaving the next author to guess.
93+
func TestWidgetRuleIDsHaveNoGaps(t *testing.T) {
94+
files, _ := filepath.Glob("*.go")
95+
seen := map[int]bool{}
96+
max := 0
97+
numRe := regexp.MustCompile(`MDL-WIDGET(\d+)`)
98+
for _, f := range files {
99+
if strings.HasSuffix(f, "_test.go") {
100+
continue
101+
}
102+
src, err := os.ReadFile(f)
103+
if err != nil {
104+
t.Fatal(err)
105+
}
106+
for _, m := range widgetRuleIDRe.FindAllStringSubmatch(string(src), -1) {
107+
n := 0
108+
for _, d := range numRe.FindStringSubmatch(m[1])[1] {
109+
n = n*10 + int(d-'0')
110+
}
111+
seen[n] = true
112+
if n > max {
113+
max = n
114+
}
115+
}
116+
}
117+
var missing []int
118+
for i := 1; i < max; i++ {
119+
if !seen[i] {
120+
missing = append(missing, i)
121+
}
122+
}
123+
if len(missing) > 0 {
124+
t.Errorf("MDL-WIDGET numbers are not dense: %v missing below %d. "+
125+
"Reuse the lowest free number, or note here why it is retired.", missing, max)
126+
}
127+
}

‎mdl/executor/widget_unrouted_children.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func sameSlotUnderAnotherName(def *WidgetDefinition, keyword string) string {
144144
return ""
145145
}
146146

147-
// validateUnroutedChildren is the check-time half (MDL-WIDGET29). It sits beside
147+
// validateUnroutedChildren is the check-time half (MDL-WIDGET30). It sits beside
148148
// MDL-WIDGET26, which covers the neighbouring case: a container KEYWORD (`group`,
149149
// `series` — words that are not widgets at all) under a parent that does not
150150
// declare it. This one covers a real WIDGET in the same position, which
@@ -153,7 +153,7 @@ func validateUnroutedChildren(w *ast.WidgetV3, def *WidgetDefinition, locationPr
153153
var out []linter.Violation
154154
for _, child := range unroutedPluggableChildren(def, w) {
155155
out = append(out, linter.Violation{
156-
RuleID: "MDL-WIDGET29",
156+
RuleID: "MDL-WIDGET30",
157157
Severity: linter.SeverityError,
158158
Message: fmt.Sprintf("%s: %s", locationPrefix, unroutedChildMessage(def, child)),
159159
Suggestion: "move it into one of the parent's containers, or out of the widget's body",

‎mdl/executor/widget_unrouted_children_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ func TestUnroutedViolationIsAnError(t *testing.T) {
207207
if len(v) != 1 {
208208
t.Fatalf("got %d violations, want 1", len(v))
209209
}
210-
if v[0].RuleID != "MDL-WIDGET29" {
211-
t.Errorf("RuleID = %s, want MDL-WIDGET29", v[0].RuleID)
210+
if v[0].RuleID != "MDL-WIDGET30" {
211+
t.Errorf("RuleID = %s, want MDL-WIDGET30", v[0].RuleID)
212212
}
213213
if v[0].Severity != linter.SeverityError {
214214
t.Errorf("Severity = %s, want error — a dropped widget is not a style note", v[0].Severity)

0 commit comments

Comments
 (0)