oxc-project/oxc · warning · OxcDiagnostic
Missing accessibility modifier on {member_type} {name}.
Error message
Missing accessibility modifier on {member_type} {name}. What it means
typescript/explicit-member-accessibility with accessibility "explicit" (the default) reports class properties and methods declared without a public/protected/private modifier. The diagnostic interpolates the member kind and name. Members without a modifier are implicitly public, which the rule considers an unintentional-looking default.
Source
Thrown at crates/oxc_linter/src/rules/typescript/explicit_member_accessibility.rs:83
accessibility: AccessibilityLevel,
/// Changes to required accessibility modifiers for specific kinds of class members.
overrides: AccessibilityOverrides,
/// Specific method names that may be ignored.
ignored_method_names: Vec<String>,
}
impl Default for ExplicitMemberAccessibilityConfig {
fn default() -> Self {
Self {
accessibility: AccessibilityLevel::Explicit,
overrides: AccessibilityOverrides::default(),
ignored_method_names: Vec::new(),
}
}
}
fn missing_accessibility_diagnostic(span: Span, member_type: &str, name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Missing accessibility modifier on {member_type} {name}."))
.with_help("Add an explicit 'public', 'private', or 'protected' modifier. Members without a modifier are implicitly public, which may not be intentional.")
.with_label(span)
}
fn unwanted_public_accessibility_diagnostic(
span: Span,
member_type: &str,
name: &str,
) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Public accessibility modifier on {member_type} {name}."))
.with_help("Remove the 'public' modifier. Members are public by default, so the modifier is redundant.")
.with_label(span)
}
declare_oxc_lint!(
/// ### What it does
///
/// Require explicit accessibility modifiers on class properties and methods.View on GitHub (pinned to e1e7af627c)
Solutions
- Add the intended modifier: `private count = 0;`, `public greet(): void {}`, `protected onInit(): void`
- List names that should be skipped in "ignoredMethodNames"
- If the team decides modifiers are noise, set "accessibility": "none" to turn the rule off for missing modifiers
- Use "overrides" to require modifiers only for specific member kinds (e.g. properties but not constructors)
Example fix
// before
class Account {
balance = 0;
withdraw(amount: number) {}
}
// after
class Account {
private balance = 0;
public withdraw(amount: number): void {}
} Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
{
"rules": {
"typescript/explicit-member-accessibility": [
"warn",
{ "accessibility": "explicit", "ignoredMethodNames": ["constructor"] }
]
}
} Prevention
- Use IDE code actions (add modifier) or a codemod when enabling the rule on a large codebase
- Decide the convention before mixing: explicit vs no-public vs none, and set accessibility once
- Add accessibility modifiers as part of the class-creation snippet template
When it happens
Trigger: Any class field or method lacking a modifier, e.g. `class A { count = 0; greet() {} }`, while AccessibilityLevel::Explicit is configured, unless the member is covered by overrides or listed in ignoredMethodNames.
Common situations: Angular-style or strict API codebases that mandate explicit accessibility; enabling the typescript restriction category; auto-generated class code or quick-fixes that omit modifiers; new team members from plain JS backgrounds.
Related errors
- Public accessibility modifier on {member_type} {name}.
- Literals should be exposed using readonly fields.
- Literals should be exposed using getters.
- encountered allocation error
- ARIA used where native HTML could suffice.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/805c60b2590abab0.
Report an issue: GitHub.