pub struct PreferReadonlyRule;Expand description
Type-aware rule that flags private members that are never reassigned and can
therefore be marked readonly.
Faithful port of the tsgolint builtin prefer-readonly rule. The upstream Go
implementation walks each class scope, tracks every modification of a private
member through class/instance property accesses, and at scope exit reports the
private, non-readonly, non-accessor, non-computed members that were never
modified outside the constructor (modifications that occur directly inside
the constructor still allow a readonly mark).
In this architecture the host performs the per-class data-flow walk and the
Rust rule receives the result as a raw fact on each member declaration
(__memberIsReassigned). All of the eligibility decisions (visibility,
readonly/accessor/computed gating, and the onlyInlineLambdas option) stay in
Rust; only the raw “was this member reassigned outside the constructor” query
is delegated.
Upstream also reports on private constructor parameter properties
(constructor(private x = 7)), which are surfaced in TS-ESTree as
TSParameterProperty nodes rather than PropertyDefinition. We therefore
listen on both kinds and normalize them.
Trait Implementations§
Source§impl Clone for PreferReadonlyRule
impl Clone for PreferReadonlyRule
Source§fn clone(&self) -> PreferReadonlyRule
fn clone(&self) -> PreferReadonlyRule
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PreferReadonlyRule
impl Debug for PreferReadonlyRule
Source§impl Default for PreferReadonlyRule
impl Default for PreferReadonlyRule
Source§fn default() -> PreferReadonlyRule
fn default() -> PreferReadonlyRule
Source§impl RustLintRule for PreferReadonlyRule
impl RustLintRule for PreferReadonlyRule
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Source§fn docs_description(&self) -> &'static str
fn docs_description(&self) -> &'static str
Source§fn messages(&self) -> &'static [RuleMessage]
fn messages(&self) -> &'static [RuleMessage]
message_id.Source§fn listeners(&self) -> &'static [&'static str]
fn listeners(&self) -> &'static [&'static str]
Source§fn has_suggestions(&self) -> bool
fn has_suggestions(&self) -> bool
Source§fn check(&self, ctx: &mut RuleContext<'_>, node: &LintNode)
fn check(&self, ctx: &mut RuleContext<'_>, node: &LintNode)
ctx.