oxc-project/oxc · warning · OxcDiagnostic
Public accessibility modifier on {member_type} {name}.
Error message
Public accessibility modifier on {member_type} {name}. What it means
The no-public variant of typescript/explicit-member-accessibility: when accessibility is "no-public", an explicit `public` modifier is reported as redundant because members are public by default. The diagnostic interpolates member type and name, mirroring @typescript-eslint/explicit-member-accessibility.
Source
Thrown at crates/oxc_linter/src/rules/typescript/explicit_member_accessibility.rs:93
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.
///
/// ### Why is this bad?
///
/// TypeScript allows placing explicit `public`, `protected`, and `private`
/// accessibility modifiers in front of class members. The modifiers exist
/// solely in the type system and serve to describe who is allowed to access
/// those members.
///
/// Leaving off accessibility modifiers makes for less code to read and
/// write. Members are `public` by default. However, adding explicitView on GitHub (pinned to e1e7af627c)
Solutions
- Remove the `public` keyword: `public greet(): void {}` becomes `greet(): void {}`
- Run `oxlint --fix` to strip modifiers mechanically
- If mixed usage is intentional, adjust "overrides" per member kind or switch accessibility back to "explicit"
Example fix
// before
class Greeter {
public name: string;
public greet(): void {}
}
// after
class Greeter {
name: string;
greet(): void {}
} Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json — the modifier is redundant under this convention
{
"rules": {
"typescript/explicit-member-accessibility": ["warn", { "accessibility": "no-public" }]
}
} Prevention
- Run `oxlint --fix` after switching conventions to strip or add modifiers mechanically
- Keep the convention in the style guide so generated code matches it
- Do not mix accessibility: explicit and no-public across shared configs; pick one for the org
When it happens
Trigger: `public greet(): void {}` or `public name: string;` in a class while the rule is configured with "accessibility": "no-public" and no override re-allows it for that member kind.
Common situations: Codebases that use `public` only for documentation elsewhere and standardize on omitting it; switching a repo's convention from explicit to no-public; bulk-editing classes written under the opposite convention.
Related errors
- Missing 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/6560efc6bfc585c1.
Report an issue: GitHub.