Skip to content

Commit 410b3cb

Browse files
authored
docs(linter): Add configuration option docs for import/extensions rule. (#15171)
Part of #14743. Doing this as a separate MR because it finishes the last import rule :) Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### checkTypeImports type: `boolean` default: `false` Whether to check type imports when enforcing extension rules. ### ignorePackages type: `boolean` default: `true` Whether to ignore package imports (e.g., 'react', 'lodash') when enforcing extension rules. ### js type: `"always" | "never" | "ignorePackages"` default: `"never"` Configuration for `.js` file extensions. ### json type: `"always" | "never" | "ignorePackages"` default: `"never"` Configuration for `.json` file extensions. ### jsx type: `"always" | "never" | "ignorePackages"` default: `"never"` Configuration for `.jsx` file extensions. ### ts type: `"always" | "never" | "ignorePackages"` default: `"never"` Configuration for `.ts` file extensions. ### tsx type: `"always" | "never" | "ignorePackages"` default: `"never"` Configuration for `.tsx` file extensions. ```
1 parent b0cc5de commit 410b3cb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crates/oxc_linter/src/rules/import/extensions.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use oxc_macros::declare_oxc_lint;
77
use oxc_resolver::NODEJS_BUILTINS;
88
use oxc_span::{CompactStr, Span};
99
use oxc_syntax::module_record::RequestedModule;
10+
use schemars::JsonSchema;
11+
use serde::Serialize;
1012
use serde_json::Value;
1113

1214
use crate::{context::LintContext, rule::Rule};
@@ -33,7 +35,8 @@ fn extension_missing_diagnostic(span: Span, is_import: bool) -> OxcDiagnostic {
3335
.with_label(span)
3436
}
3537

36-
#[derive(Debug, Default, Clone, PartialEq)]
38+
#[derive(Debug, Default, Clone, PartialEq, Serialize, JsonSchema)]
39+
#[serde(rename_all = "camelCase")]
3740
enum FileExtensionConfig {
3841
Always,
3942
#[default]
@@ -52,15 +55,24 @@ impl FileExtensionConfig {
5255
}
5356
}
5457

55-
#[derive(Debug, Clone)]
58+
#[derive(Debug, Clone, JsonSchema, Serialize)]
59+
#[serde(rename_all = "camelCase", default)]
5660
pub struct ExtensionsConfig {
61+
/// Whether to ignore package imports (e.g., 'react', 'lodash') when enforcing extension rules.
5762
ignore_packages: bool,
63+
/// Configuration for requiring or disallowing file extensions in import/require statements.
5864
require_extension: Option<FileExtensionConfig>,
65+
/// Whether to check type imports when enforcing extension rules.
5966
check_type_imports: bool,
67+
/// Configuration for `.js` file extensions.
6068
js: FileExtensionConfig,
69+
/// Configuration for `.jsx` file extensions.
6170
jsx: FileExtensionConfig,
71+
/// Configuration for `.ts` file extensions.
6272
ts: FileExtensionConfig,
73+
/// Configuration for `.tsx` file extensions.
6374
tsx: FileExtensionConfig,
75+
/// Configuration for `.json` file extensions.
6476
json: FileExtensionConfig,
6577
}
6678

@@ -161,6 +173,7 @@ declare_oxc_lint!(
161173
Extensions,
162174
import,
163175
restriction,
176+
config = ExtensionsConfig,
164177
);
165178

166179
impl Rule for Extensions {

0 commit comments

Comments
 (0)