oxc-project/oxc · warning · OxcDiagnostic
A constructor name should not start with a lowercase letter.
Error message
A constructor name should not start with a lowercase letter.
What it means
Reported by the `new-cap` rule when `newIsCap` is enabled (default true) and a `new` expression's callee is an identifier (or property, when `properties: true`) starting with a lowercase letter. The message is fixed ('A constructor name should not start with a lowercase letter.') while the label/help adapt: for the Lower case the label says 'This should be uppercase' (crates/oxc_linter/src/rules/eslint/new_cap.rs:31-43). A built-in exceptions list (`newIsCapExceptions`, seeded from caps_allowed_vec) whitelists known lowercase constructors.
Source
Thrown at crates/oxc_linter/src/rules/eslint/new_cap.rs:40
let msg = if *cap == GetCapResult::Lower {
"A constructor name should not start with a lowercase letter."
} else {
"A function with a name starting with an uppercase letter should only be used as a constructor."
};
let label = if *cap == GetCapResult::Lower {
"This should be uppercase"
} else {
"This should be called with `new`"
};
let help = if *cap == GetCapResult::Lower {
"Capitalize the first letter of the constructor name, or add it to the exceptions list if it should not be capitalized."
} else {
"Use the new operator when calling this function, or add it to the exceptions list if it should not be called with new."
};
OxcDiagnostic::warn(msg).with_help(help).with_label(span.label(label))
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct NewCap(Box<NewCapConfig>);
#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct NewCapConfig {
/// `true` to require that all constructor names start with an uppercase letter, e.g. `new Person()`.
new_is_cap: bool,
/// `true` to require that all functions with names starting with an uppercase letter to be called with `new`.
cap_is_new: bool,
/// Exceptions to ignore for constructor names starting with an uppercase letter.
new_is_cap_exceptions: Vec<CompactStr>,
/// A regex pattern to match exceptions for constructor names starting with an uppercase letter.
#[serde(default, deserialize_with = "deserialize_regex_option")]
new_is_cap_exception_pattern: Option<Regex>,
/// Exceptions to ignore for functions with names starting with an uppercase letter.View on GitHub (pinned to e1e7af627c)
Solutions
- Capitalize the constructor: `new Person()` — rename the class/function itself if you own it.
- If the lowercase name is a third-party API you cannot change, add it to `newIsCapExceptions` (e.g. `["stream", "peer"]`) or a `newIsCapExceptionPattern` regex in `.oxlintrc.json`.
- If it is actually a factory function, drop the `new` (verify the implementation supports being called without `new`).
Example fix
// before const emitter = new eventEmitter(); // after const emitter = new EventEmitter();
Defensive patterns
Strategy: validation
Validate before calling
// CI: oxlint --rule new-cap src/
// Register known lowercase third-party constructors up front:
// { "new-cap": [{ "newIsCapExceptions": ["myLib.builder"], "newIsCapExceptionPattern": "^[a-z]+\\$" }] } Type guard
// Convention guard (TypeScript): classes are PascalCase; a type predicate for callables you own:
function isConstructor<T>(fn: new (...args: never[]) => T): true { return true; } Prevention
- Name constructors with an uppercase first letter at creation time; renaming later touches every call site.
- Maintain newIsCapExceptions in config as the single place third-party lowercase constructors are acknowledged.
- Prefer class syntax over function-constructor patterns in new code — classes make the constructor role obvious.
When it happens
Trigger: `const s = new person()`, `new myModule.Thing`-style lowercase property calls with `properties: true`, or lowercase factory constructors not in the exceptions list. Defaults: `newIsCap: true`, `capIsNew: true`, `properties: true` (crates/oxc_linter/src/rules/eslint/new_cap.rs:67-77).
Common situations: Calling `new` on third-party libraries whose constructors are lowercase (older libraries, some DSL builders); using lowercase class names in throwaway prototypes; the rule flagging dynamic property access paths; config migrations that dropped a previously maintained `newIsCapExceptions` list.
Related errors
- A function with a name starting with an uppercase letter sho
- Identifier '{name}' is restricted.
- Identifier '#{name}' is restricted.
- Identifier name is too short (< {config_min}).
- `VirtualFree` failed during cleanup: {err}
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/28eca0e33f107320.
Report an issue: GitHub.