oxc-project/oxc · warning · OxcDiagnostic
Enforce using the separator argument with Array#join()
Error message
Enforce using the separator argument with Array#join()
What it means
This is the oxlint rule `unicorn/require-array-join-separator`. `Array#join()` with no arguments defaults to a comma, which is implicit and often not what the author meant; the rule requires an explicit separator argument so intent is visible ('Missing the separator argument.'). The rule checks calls via `is_method_call` and `is_prototype_property` on the receiver.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/require_array_join_separator.rs:15
use oxc_ast::{
AstKind,
ast::{Argument, MemberExpression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{
AstNode, ast_util::is_method_call, context::LintContext, rule::Rule,
utils::is_prototype_property,
};
fn require_array_join_separator_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Enforce using the separator argument with Array#join()")
.with_help("Missing the separator argument.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct RequireArrayJoinSeparator;
declare_oxc_lint!(
/// ### What it does
///
/// Enforce using the separator argument with `Array#join()`.
///
/// ### Why is this bad?
///
/// It's better to make it clear what the separator is when calling `Array#join()`,
/// instead of relying on the default comma (`','`) separator.
///
/// ### ExamplesView on GitHub (pinned to e1e7af627c)
Solutions
- Pass the separator you actually mean: `list.join('')` for concatenation, `list.join(',')` to make the default explicit.
- Run `oxlint --fix` where the fixer inserts the separator.
- Disable the rule with `"unicorn/require-array-join-separator": "off"` if your team accepts the implicit comma default.
Example fix
// before
const csv = ids.join();
const className = mods.join();
// after
const csv = ids.join(',');
const className = mods.join(' '); Defensive patterns
Strategy: validation
Validate before calling
// State the separator explicitly every time
const csv = ids.join(',');
const glued = parts.join('');
// CI: npx oxlint --deny-warn unicorn/require-array-join-separator src/ Prevention
- Never call `.join()` bare — the comma default is rarely the intent.
- Review join sites during string-building refactors; silent commas are a classic log/output bug.
- Enable the rule repo-wide; it is cheap and prevents a whole class of formatting mistakes.
When it happens
Trigger: `list.join()` — a `.join` member call on an array-like receiver with zero arguments. Passing any explicit separator (`join(',')`, `join('')`, `join('-')`) silences it; `.join` accessed through `Array.prototype.join.call(...)` shapes is also covered by the prototype-property check.
Common situations: Joining to build strings (log lines, class lists, paths) where the author assumed no-separator but got `','`; or join-for-stringification in template building where the comma default slips into output. Reviewers use this rule to force `join('')` vs `join(',')` to be stated.
Related errors
- Found a useless array length check
- NaN values will never be found by `Array.prototype.{method_n
- Unexpected array literal comparison.
- Suggest using `toContain()`.
- The catch parameter {caught_ident:?} should be named {expect
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/4f40c6a13c9040c4.
Report an issue: GitHub.