Documentation
¶
Overview ¶
Package mvvmlint provides a go/analysis analyzer that makes MVVM usage mandatory for applications built on the go-widgets pixel/cell toolkit.
The toolkit exposes mutable value fields on its widgets (a text entry's Text, a list's Items, a table's Rows, and so on). Mutating those fields ad hoc scatters view state across imperative call sites and defeats the point of a ViewModel layer. The sanctioned way to touch widget state is through the go-widgets/mvvm binders, which take a POINTER into the field (BindField(obs, &w.Text, &w.OnChange, invalidate)); the address-of form is a binding, not a mutation, and is never flagged.
The analyzer reports two rules, but only in packages that import the toolkit:
Direct widget-state mutation. An assignment whose left-hand side is a selector X.Field, where the static type of X is (a pointer to) a toolkit widget type and Field is in the configurable state-field allowlist. This is the core "mutate ad hoc" violation. Composite literals and the address-of form &w.Field are not assignments to a selector and are never flagged. Assignments in files named *_binding.go, and any file carrying a //mvvmlint:allow directive, are exempt so intentional glue can opt out.
Missing view-model. A package that imports the toolkit but does not import go-widgets/mvvm gets a single diagnostic asking that state be wired through a view-model. This rule can be turned off (via -requirevm=false) for pure widget libraries that legitimately ship no ViewModel.
Index ¶
Constants ¶
const MVVMPath = "github.com/go-widgets/mvvm"
MVVMPath is the import path of the go-widgets MVVM library.
const ToolkitPath = "github.com/go-widgets/toolkit"
ToolkitPath is the import path of the go-widgets pixel toolkit.
Variables ¶
var Analyzer = newAnalyzer()
Analyzer is the mvvmlint go/analysis analyzer. Use it with singlechecker, or as a go vet tool: go vet -vettool=$(which mvvmlint) ./...
var DefaultStateFields = []string{
"Active",
"Checked",
"Columns",
"Content",
"Current",
"Cursor",
"Data",
"Expanded",
"Fraction",
"High",
"Items",
"Low",
"Max",
"Min",
"Nodes",
"On",
"Options",
"Page",
"Progress",
"Range",
"Root",
"Rows",
"ScrollRow",
"Selected",
"Text",
"Value",
"Values",
}
DefaultStateFields is the built-in allowlist of toolkit widget value fields that carry display or data state. Assigning to one of these on a toolkit widget is the "mutate ad hoc" violation the analyzer exists to catch.
The set is intentionally curated to value/state fields (not callback slots such as OnChange, and not one-time construction options): it is derived from the mutable state fields of the toolkit widgets — an entry's Text, a list's Items and Selected, a table's Rows/Columns, a tree's Root, a slider's Value/Low/High, a check's Checked, a switch's On, and so on.
Functions ¶
This section is empty.
Types ¶
This section is empty.