oxc-project/oxc · info · OxcDiagnostic
Expected '{curr_kind}' syntax before '{prev_kind}' syntax.
Error message
Expected '{curr_kind}' syntax before '{prev_kind}' syntax. What it means
oxlint `eslint/sort-imports`: two consecutive import declarations appear in the wrong order by member-syntax kind. `unexpected_syntax_order_diagnostic` (sort_imports.rs:27) formats 'Expected \'{curr_kind}\' syntax before \'{prev_kind}\' syntax.' Kinds are None (`import "x"`), All (`import * as x`), Multiple (`import {a, b}`), Single (`import x` / `import {a}`), and the default memberSyntaxSortOrder is none, all, multiple, single (confirmed by the ImportKind defaults at sort_imports.rs:350-353).
Source
Thrown at crates/oxc_linter/src/rules/eslint/sort_imports.rs:27
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_str::Ident;
use rustc_hash::FxHashSet;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn unexpected_syntax_order_diagnostic(
curr_kind: &ImportKind,
prev_kind: &ImportKind,
span: Span,
) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Expected '{curr_kind}' syntax before '{prev_kind}' syntax."))
.with_label(span)
}
fn sort_imports_alphabetically_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Imports should be sorted alphabetically.").with_label(span)
}
fn sort_members_alphabetically_diagnostic(name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"Member '{name}' of the import declaration should be sorted alphabetically."
))
.with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct SortImports(Box<SortImportsOptions>);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]View on GitHub (pinned to e1e7af627c)
Solutions
- Reorder the declarations to match memberSyntaxSortOrder, then alphabetical order within the same kind.
- Change the order to match your convention: `{ "memberSyntaxSortOrder": ["single", "multiple", "all", "none"] }` (all 4 kinds must be listed).
- Set `ignoreDeclarationSort: true` to stop checking declaration order entirely (member sort still applies).
- Enable `allowSeparatedGroups: true` so blank-line-separated groups are sorted independently.
Example fix
// before import z from 'z.js'; import * as a from 'a.js'; // after (default order: none, all, multiple, single) import * as a from 'a.js'; import z from 'z.js';
Defensive patterns
Strategy: validation
Prevention
- Decide the memberSyntaxSortOrder once and encode it in `.oxlintrc.json` (all 4 kinds must be listed).
- Use an editor's 'organize imports' action so syntax-kind ordering stays correct automatically.
- When adding an import of a different kind (e.g. `import * as x` next to existing default imports), place it per the configured order.
When it happens
Trigger: With default order, `import a from 'a.js'` (Single) followed by `import * as b from 'b.js'` (All) — the All import should have come first, so the second declaration is flagged 'Expected \'All\' syntax before \'Single\' syntax.' Only the leading, contiguous block of import statements is checked (run_once breaks at the first non-import statement).
Common situations: New imports appended at the top of file without reordering; different team members using different import styles; adopting sort-imports on an existing codebase.
Related errors
- Imports should be sorted alphabetically.
- Member '{name}' of the import declaration should be sorted a
- Object keys should be sorted
- Variable declarations should be sorted
- Do not assign to imported bindings
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/40894428dd9be237.
Report an issue: GitHub.