lloyAlloy on GitHub
stale_export
Docs

stale_export

Updated

A write to an exported local inside a function.

A module returns its exports as a table built when it loads, and an import copies each value into a local of the importer. export local count = 0 sends out the number 0, not the variable. A write at the top level runs before the module returns, so the table takes it. A write inside a function runs later and never reaches an importer, which keeps the value it read when it loaded. Export a function that returns the value, or keep the value in a table and write its fields: export local state = { count = 0 } and state.count += 1. An importer holds that table, so it reads every write. Keep the table in a local that no line assigns again. A const freezes its value by convention, so const_mutation reports each field or index write into it, and prefer_const leaves alone a local whose fields change. A local member of a namespace stays live through accessors and draws no report.

Set its level in the [lint] table of alloy.toml, or for one file with --@alloy-lint.