avoid-accessing-other-classes-private-members
- Group
- Suspicious
- Path
lint/suspicious/avoid-accessing-other-classes-private-members- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 13 of 512
Enforces class-level encapsulation even inside one Dart library.
Invalid
class Secret {
int _value = 0;
static int _shared = 0;
void _reset() {}
static Secret _default() => Secret();
}
class Other {
void inspect(Secret secret) {
final value = secret._value;
secret._value = value;
secret._reset();
final reset = secret._reset;
Secret._shared++;
secret.._value = 1;
secret.._reset();
}
}
int outside(Secret secret) => secret._value;
class NullableAccess {
void inspect(Secret? secret) {
secret?._value;
secret?._reset();
}
void shorthand() {
Secret secret = ._default();
}
}
class Child extends Secret {
int inspectBase(Secret secret) => secret._value;
} void inspect(Secret secret) { final value = secret._value; final value = secret._value; secret._value = value; secret._value = value; secret._reset(); secret._reset(); final reset = secret._reset; final reset = secret._reset; Secret._shared++; Secret._shared++; secret.._value = 1; secret.._value = 1; secret.._reset();}int outside(Secret secret) => secret._value; void inspect(Secret? secret) { secret?._value; secret?._value; secret?._reset(); void shorthand() { Secret secret = ._default();class Child extends Secret { int inspectBase(Secret secret) => secret._value;Valid
class Secret {
int _value = 0;
static int _shared = 0;
int publicValue = 0;
void _reset() {}
static Secret _default() => Secret();
void nullable(Secret? other) {
other?._value;
other?._reset();
}
void shorthand() {
Secret other = ._default();
}
void inspect(Secret other) {
_value = other._value;
this._reset();
other.._value = 1;
Secret._shared++;
void nested() { other._reset(); }
nested();
}
}
class Other {
int read(Secret secret) => secret.publicValue;
void unknown(dynamic value) { value._unresolved(); }
}
class Child extends Secret {
@override
void _reset() { super._reset(); }
int readOwn() => this._value;
void resetOwn() { this.._value = 1; this.._reset(); }
bool same(Child other) => this._value == other._value;
void nullable(Child? other) { other?._value; }
void cascade(Child other) { other.._value = 1; }
}
extension NamedSecretAccess on Secret {
int readOther(Secret other) => other._value;
}
extension on Secret {
int readOtherUnnamed(Secret other) => other._value;
}Configure avoid-accessing-other-classes-private-members
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-accessing-other-classes-private-members": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-accessing-other-classes-private-members: <reason>More suspicious rules
- avoid-assignments-as-conditions
Flags assignments evaluated inside control-flow conditions.
- avoid-banned-annotations
Ban configured dotted annotation names, without the leading
@. - avoid-banned-exports
Ban decoded export URIs, including all conditional alternatives.
- avoid-banned-names
Ban declaration names, exempting references, initializing/super formals, and
@override-annotated members and their parameters. - avoid-banned-types
Ban resolved explicit type annotations, including nested generic arguments.
- avoid-barrel-files
Discourage files containing only re-exports, without declarations or parts.
- avoid-bitwise-operators-with-booleans
Flags
&and|applied to two non-nullable boolean operands. - avoid-commented-out-code
Flags ordinary comments that contain recognizable Dart statements.