Skip to content

feat(check): warn about an inject() key no component above provides (#207) - #243

Merged
JuroOravec merged 34 commits into
mainfrom
fix/static-checks-207-inject
Oct 22, 2026
Merged

JuroOravec merged 34 commits into
mainfrom
fix/static-checks-207-inject

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Part of #207, stacked on #242; merge that first. It implements proposal 15 (m50) as recommended: a check for an inject() key that no component above provides.

What changes

  • The rule: rule_unknown_inject_key, code citry.template.unknown-inject-key, a warning by default.
  • Where it runs: citry check with the app loaded, and the editor once it has loaded the app.
  • What it reports: a literal self.inject("key") with no default, when no component above it provides that key. For example: "No component above Card provides 'bord', so self.inject('bord') raises KeyError when the page renders. Did you mean 'board'?"
  • How it finds providers: from each template that uses the component's tag, it walks up the page. A key counts as provided by any of these:
    • a <c-provide> around the tag;
    • a provide() in a component on the way;
    • the component whose <c-slot> shows the slot content, including slots passed on to other components;
    • literal render(provides={...}) keys in the project's Python files.
  • Fallback: when the path can't be traced, the rule checks the key against everything the app provides. That covers a component rendered only from Python, or only through a dynamic <c-component is>.
  • Never reported:
    • an inject() with a default;
    • a key written as an expression;
    • a path that holds a provider whose key is an expression.
  • A known false report: a key passed through a provides dictionary built somewhere else can't be seen. This is why the rule is a warning, and it can be turned off per component in Lint or app-wide in LintSettings.

The decisions table in docs/design/issue_207_proposals.md records where the build differs from section 15.

Evidence

  • Benchmark: the m50 case is now reported, with "Did you mean 'board'?".
  • False reports: none on the starters, the demos, citry_ui, the docs site examples, or the benchmark's Citry app.
  • Tests: 65 new ones, covering every error mode in section 15, slots, mixins, cycles, and imported key constants. They also pass on Python 3.10.
  • Lint and types: ruff and mypy pass, including mypy with --platform linux.
  • Reviews: three rounds of independent code review, plus a separate prose pass.

Wheel size

The wheel is 1,377,070 bytes, so the cap moves to 1,360 KiB (commit 0042eff15). Drop that commit if you'd rather trim the wheel.

Local gate

The local gate's pytest phase had 13 failures, all in tests that came with #239. They need #239's Rust fixes, which the published citry-core 1.8.0 wheel used here doesn't have. CI builds citry-core from source, so they pass there.

🤖 Generated with Claude Code

JuroOravec and others added 20 commits October 21, 2026 20:00
CLAUDE.md and the agent index named only template_parser, safe_eval and
html_transform (plus i18n in the index); lib.rs also registers vue and
template_formatter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… arguments (#207)

Section 5.1 already says written arguments replace the form's fields; the
component-tag section still described a merge that the browser runtime
does not do (both paths go through declarativeEventArgs in _vue/client.js).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e emit payload (#207)

A listener written as a bare method name, such as @hide="hideCard", is
now passed to a generated function typed from the child's emits, so tsc
compares the method's parameters with the payload (m60). The props and
events guide documents typed emits, which also report a wrong payload at
the child's $emit call (m30).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… render errors (#207)

12a: the missing and duplicate #c-key messages now give the template and
line for inline templates, template files, slot fills and template-valued
attributes, include the repeated value, and explain nested loops; the
element-key conflict shares one message with the parser's wording.

12b: when the Vue compiler reports MODEL_HELPER_MISMATCH, the render
searches the authored templates the Vue template came from with the
invalid-model-target rule and names each element, its template and line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Secret[T] wraps a server-only value such as an API token. Its text form
is ***, so a template never shows it; js_data(), css_data() and State
refuse it with an error naming the component and key path; and the
citry.js-data.unsupported-type rule reports it statically (annotations,
module constants, also nested in literals, and values ty types as Secret).
The component options and security guides explain how to keep tokens off
the page (m42).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and variable rules (#207)

citry.css.misspelled-class (rule_misspelled_css_class, a warning) reports
a static class one slip from a class selector in the component's own CSS
that no CSS Citry reads declares (m16). citry.css.undeclared-class and
citry.css.undeclared-variable are off by default ("ignore", which the
diagnostics schema now allows with a configurable severity) and report
every class no CSS Citry reads declares and every var(--x) without a
fallback that nothing sets. All three run in citry check with the app
loaded. _css_scan.py is the one reader of selectors and custom property
declarations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…velopment mode (#207)

12c: with Citry(mode="development"), a hydrating page inlines
_vue/dev_checks.js, and the runtime compares each shell's served HTML with
Vue's first render and logs a console warning naming the component, the
element, the first difference, and the data-allow-mismatch value that
silences it (m14). Production pages carry no flag and no script.

12d: in development mode, serialization collects each component's own ids
and issues one RuntimeWarning per page listing every id two components (or
two renders of one) wrote, with the components and template files (m57).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… m50 (#207)

The decisions table records what was built for items 8, 11, 12a-12d, 13,
the two off-by-default CSS rules, and 14. Section 15 proposes a check for
an inject() key no ancestor provides (m50) for the maintainer to decide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
CSS rules: the misspelled-class rule no longer reports a missing final
d/r/n of a word family or a slip in a short first hyphen part (p-4/px-4),
reads other components' stylesheets only when a class is one slip from
the component's own CSS, and the variable messages say the property gets
its initial or inherited value.

Secret: constant-time equality for text and bytes; css_data() refuses a
Secret even without CSS; a Secret in a cache key gets its own error and is
never hashed into the key; citry check also follows attributes, *, both
branches of a conditional and Const(); the js-data warning has a Secret
message in citry check and the editor; the State error names the class.

Development checks: same-tag v-if/v-else branches are paired by their
whole subtree within a budget, so a correct page no longer warns; the
script is read once; warnings from the repeated-id, CSP and JavaScript
policy checks point at the caller's code (_caller_warnings.py).

Render errors: an element-key clash names its template, line and column;
the v-model search reads template-valued attributes. Prose fixes across
the docs, docstrings, messages, changelogs and design docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Development checks: an agreeing pair outranks any number of differing
pairs, a branch rejected only by the quick text check gets a full
comparison while budget remains, and the budget now charges the text
search (raised to 200,000 steps). Caller warnings work through a
symlinked import path and document the Events response case.

CSS rule: the final d/r/n exclusion covers only listed UI words
(collapse, disable, show, toggle, ...), the short-first-part exclusion
covers only a doubled or dropped letter, and a word already ending in s
is not excused, so heade, iu-button and progres are reported again.

Secret: the static walk reads attributes without running user code,
judges only built-in values, survives deep nesting and skips a value a
property shadows; equality treats str and bytes subclasses as text;
css_data() refuses a nested Secret with or without CSS; the js-data
message says a field can hold a Secret. Prose fixes in the docs,
changelogs and design docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The CSS checks, citry.Secret, and the development-mode browser check
(_vue/dev_checks.js) grow the wheel to 1,360,663 bytes, 9 KB over the cap
the earlier #207 batch set. The cap moves to 1,344 KiB, about 15 KB of
headroom.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On Python 3.10, types.SimpleNamespace lists its own C __getattribute__ in its
class namespace, so the js_data() Secret check took it for a hook that might
run code and left SETTINGS.auth.token unchecked. It runs no user code, so it
joins object, type and ModuleType.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pytest puts a test's id in the PYTEST_CURRENT_TEST environment variable, and
the deeply nested @media case made it longer than the 32,767 characters
Windows allows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	benchmarks/errors/frameworks/citry/framework.toml
#	docs/design/vue.md
…207)

citry.template.unknown-inject-key (rule_unknown_inject_key, a warning)
reports a self.inject("key") with a literal key and no default whose key
reaches the component from no provider (m50). citry/_provide_keys.py reads
every registered template once and walks up from each template that writes
the component's tag: <c-provide> keys around the tag, provide() keys of
the components on the way, keys around the <c-slot> that shows slot
content, and literal render(provides={...}) keys in the project's Python
files. A component no template writes falls back to every key the app
provides. Paths through a provider Citry cannot read report nothing.

citry check runs it with the app loaded; the editor's app worker sends the
keys per component class (inject_keys) and the editor reads the calls from
the open buffer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A <c-slot> written in another component's body, and its fallback
content, now get that component's slot keys. provide() and inject() calls
in base classes and mixins outside Citry and the standard library count,
including LibraryComponent definitions. A component that Python builds
inside a component's methods, or passes to another component, is no
longer checked below that point, and a component used only inside its own
cycle of templates falls back to every key the app provides. A
render(provides=...) key written as a module constant counts. Slot answers
are kept once final, so slots passed through many components stay fast,
and a project folder past 20,000 Python files turns the rule off.

The messages now say what to do next, the editor tolerates fields a newer
worker adds, and the docs list exactly what counts and what is skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A component Python places inside other content is no longer compared
with every provided key when no template uses it. Slot answers are worked
out once per (component, slot) pair until they stop changing, so slots
passed through cycles stay fast. Standard-library classes are found by
file location, so a project package named like a standard module is read.
A class without a readable class statement counts as providing nothing
unless its compiled methods name provide. render(provides=...) keys
imported from a loaded module or a project module count. Project files
are read one at a time; test files do not hide components, and a
component passed to another one through a variable counts as placed.
Calls in installed packages are not reported, and a mixin's message names
a component that uses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only folders inside the project mark a test file, so a project under a
folder named tests still finds components Python places. render(provides=
...) keys imported with a relative import, or read from a module imported
from a package (from shop import keys), count. The compiled-method check
for a class without a readable class statement follows decorators and
property accessors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The inject-key check grows the wheel to 1,377,070 bytes, 814 bytes over
the cap. The cap moves to 1,360 KiB, about 15 KB of headroom.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec and others added 7 commits October 22, 2026 11:45
Give hot reload and development mode their own guides: /guides/hot-reload/
covers file reloading only, and /guides/development-mode/ covers
Citry(mode="development") and what it turns on. /guides/dev-server/ now
redirects to the hot reload page, and every link points at the new pages.

On the pages this branch touched, move typing, linting, and error detail
out of the main flow into one section near the end of each page:
"Keep tokens off the page" now sits before "Check JS code" on Component
options, and Props and events gains "Catch mistakes early". The full list
of rules for method listeners moves to the VS Code page, and the CSS
class rule details move to the template linting page's less common cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec deleted the branch fix/static-checks-207-more October 22, 2026 10:19
@JuroOravec JuroOravec closed this Oct 22, 2026
@JuroOravec JuroOravec reopened this Oct 22, 2026
Base automatically changed from fix/static-checks-207-more to main October 22, 2026 10:24
@JuroOravec
JuroOravec merged commit 5cefab5 into main Oct 22, 2026
26 of 50 checks passed
@JuroOravec
JuroOravec deleted the fix/static-checks-207-inject branch October 22, 2026 10:25
JuroOravec added a commit that referenced this pull request Oct 22, 2026
Main brought two checks whose findings carry ranges: the CSS class rules
(#242) and the unknown inject key rule (#243). Both already counted from
0 in UTF-16 units through `_byte_offset_coordinates`, but neither said
which text it counts in, so the report rejected them. The CSS class
findings are now built with `_ranged_finding` from their template source,
and the inject key findings are marked as counting in the component's
Python file. Their tests now also check `source_kind`; no expected
position changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant