Skip to content

Commit 7656e2b

Browse files
authored
docs(linter): Add configuration option docs for eslint/sort-imports rule. (#15013)
Part of #14743. Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### allowSeparatedGroups type: `boolean` default: `false` When `true`, the rule allows import groups separated by blank lines to be treated independently. ### ignoreCase type: `boolean` default: `false` When `true`, the rule ignores case-sensitivity when sorting import names. ### ignoreDeclarationSort type: `boolean` default: `false` When `true`, the rule ignores the sorting of import declarations (the order of `import` statements). ### ignoreMemberSort type: `boolean` default: `false` When `true`, the rule ignores the sorting of import members within a single import declaration. ### memberSyntaxSortOrder type: `array` Specifies the sort order of different import syntaxes. #### memberSyntaxSortOrder[n] type: `"none" | "all" | "multiple" | "single"` ``` This is imperfect because of the handling of `memberSyntaxSortOrder[n]` by the website generation tool, but I think this is probably fine as-is.
1 parent 6faa11d commit 7656e2b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

crates/oxc_linter/src/rules/eslint/sort_imports.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use oxc_ast::ast::{ImportDeclaration, ImportDeclarationSpecifier, Statement};
1010
use oxc_diagnostics::OxcDiagnostic;
1111
use oxc_macros::declare_oxc_lint;
1212
use oxc_span::Span;
13+
use schemars::JsonSchema;
1314

1415
use crate::{context::LintContext, rule::Rule};
1516

@@ -36,12 +37,18 @@ fn sort_members_alphabetically_diagnostic(name: &str, span: Span) -> OxcDiagnost
3637
#[derive(Debug, Default, Clone)]
3738
pub struct SortImports(Box<SortImportsOptions>);
3839

39-
#[derive(Debug, Default, Clone)]
40+
#[derive(Debug, Default, Clone, JsonSchema)]
41+
#[serde(rename_all = "camelCase", default)]
4042
pub struct SortImportsOptions {
43+
/// When `true`, the rule ignores case-sensitivity when sorting import names.
4144
ignore_case: bool,
45+
/// When `true`, the rule ignores the sorting of import declarations (the order of `import` statements).
4246
ignore_declaration_sort: bool,
47+
/// When `true`, the rule ignores the sorting of import members within a single import declaration.
4348
ignore_member_sort: bool,
49+
/// When `true`, the rule allows import groups separated by blank lines to be treated independently.
4450
allow_separated_groups: bool,
51+
/// Specifies the sort order of different import syntaxes.
4552
member_syntax_sort_order: MemberSyntaxSortOrder,
4653
}
4754

@@ -76,7 +83,8 @@ declare_oxc_lint!(
7683
SortImports,
7784
eslint,
7885
style,
79-
conditional_fix
86+
conditional_fix,
87+
config = SortImportsOptions,
8088
);
8189

8290
impl Rule for SortImports {
@@ -351,7 +359,7 @@ impl SortImports {
351359
}
352360
}
353361

354-
#[derive(Debug, Clone)]
362+
#[derive(Debug, Clone, JsonSchema)]
355363
struct MemberSyntaxSortOrder(Vec<ImportKind>);
356364

357365
impl Default for MemberSyntaxSortOrder {
@@ -403,7 +411,8 @@ impl MemberSyntaxSortOrder {
403411
}
404412
}
405413

406-
#[derive(Debug, Default, Clone, Hash, Eq, PartialEq)]
414+
#[derive(Debug, Default, Clone, Hash, Eq, PartialEq, JsonSchema)]
415+
#[serde(rename_all = "lowercase")]
407416
enum ImportKind {
408417
// import from 'foo.js'
409418
#[default]

0 commit comments

Comments
 (0)