VIEW018: fragile-component-reference
Script or binding navigates the component tree
| Code | VIEW018 |
| Name | fragile-component-reference |
| Category | View structure (VIEW) |
| Default severity | warning |
| Enabled by default | no |
| Fix available | no |
| ign-lint equivalent | BadComponentReferenceRule |
What it does
Section titled “What it does”Reports scripts and bindings that reach other components by walking the component tree:
- in scripts: calls of
getSibling,getParent,getChildandgetChildren, andself.parent/self.children; - in expression bindings, expression transforms, expression-structure
bindings and property bindings: relative component paths
../Sibling...and./Child....
Scripts are parsed with the Jython parser and expressions with the
expression parser, so text in comments and string literals never counts,
and ../ is not also reported as ./. One finding per script or binding
lists every pattern it uses.
Why is this bad?
Section titled “Why is this bad?”Such references break silently when components are renamed, moved or wrapped in a new container. View custom properties, view parameters and message handlers keep components decoupled. This is a style rule and is not in the default set.
Example
Section titled “Example”self.getSibling('Total').props.text = str(value)Use instead: bind Total.props.text to {view.custom.total} and write
self.view.custom.total = value.
Options
Section titled “Options”forbidden-patterns(default[".getSibling(", ".getParent(", ".getChild(", ".getChildren(", "self.parent.", "self.children.", "self.parent)", "self.children)", "self.parent,", "self.children,", "self.parent\n", "self.children\n", "self.parent\r", "self.children\r", "../", "./"]): the patterns to report, in ign-lint's notation:.getSibling(,.getParent(,.getChild(,.getChildren(,self.parent.(and the otherself.parentforms),self.children.(and its other forms),../(paths going up) and./(paths relative to the component itself). Other strings are matched as plain text in the script or expression. An empty list means the default list (all of these).case-sensitive(defaulttrue): when false, method and attribute names and text patterns match case-insensitively.
ign-lint
Section titled “ign-lint”Equivalent of BadComponentReferenceRule (forbidden_patterns,
case_sensitive) with the same messages in iglint ign-lint. ign-lint
matches substrings: it also reports text in comments, strings and invalid
expressions, and every ../ also counts as ./ (bug 18); iglint does not.
Option reference
Section titled “Option reference”Set in [rules.VIEW018] of iglint.toml (or [tool.iglint.rules.VIEW018] in pyproject.toml).
| Option | Type | Default | Description |
|---|---|---|---|
forbidden-patterns |
array of strings | [".getSibling(", ".getParent(", ".getChild(", ".getChildren(", "self.parent.", "self.children.", "self.parent)", "self.children)", "self.parent,", "self.children,", "self.parent\n", "self.children\n", "self.parent\r", "self.children\r", "../", "./"] |
Patterns to report. |
case-sensitive |
boolean | true |
Match names case-sensitively. |
ign-lint kwargs in a rule_config.json: forbidden_patterns -> forbidden-patterns, case_sensitive -> case-sensitive.
Generated from the rule metadata by iglint generate-docs; iglint rule VIEW018 prints the same page in the terminal. Source: docs/rules/VIEW018.md.