diff --git a/apps/oxfmt/tests/fixtures/multiple_files/app.tsx b/apps/oxfmt/tests/fixtures/multiple_files/app.tsx
new file mode 100644
index 0000000000000..61725ac07802f
--- /dev/null
+++ b/apps/oxfmt/tests/fixtures/multiple_files/app.tsx
@@ -0,0 +1,10 @@
+interface Props {
+ title : string
+ count : number
+}
+const App : React.FC < Props > = ( { title , count } ) => {
+return
+
{ title }
+ Count : { count }
+
+}
diff --git a/apps/oxfmt/tests/fixtures/multiple_files/arrow.js b/apps/oxfmt/tests/fixtures/multiple_files/arrow.js
index 6040f32be53e5..35082ec4ba704 100644
--- a/apps/oxfmt/tests/fixtures/multiple_files/arrow.js
+++ b/apps/oxfmt/tests/fixtures/multiple_files/arrow.js
@@ -1,3 +1,3 @@
-const fn1 = ( ) => { }
-const fn2 = x => x * 2
-const fn3 = ( a , b ) => a + b
\ No newline at end of file
+const Element = ( ) =>
\ No newline at end of file
diff --git a/apps/oxfmt/tests/fixtures/multiple_files/component.jsx b/apps/oxfmt/tests/fixtures/multiple_files/component.jsx
new file mode 100644
index 0000000000000..a73a91e0f8c39
--- /dev/null
+++ b/apps/oxfmt/tests/fixtures/multiple_files/component.jsx
@@ -0,0 +1,6 @@
+const Component = ( ) => {
+ return
+}
diff --git a/apps/oxfmt/tests/fixtures/multiple_files/simple.ts b/apps/oxfmt/tests/fixtures/multiple_files/simple.ts
new file mode 100644
index 0000000000000..3905b3043f71b
--- /dev/null
+++ b/apps/oxfmt/tests/fixtures/multiple_files/simple.ts
@@ -0,0 +1,5 @@
+interface Person {
+ name : string
+age:number
+}
+const user : Person = { name : "Alice" , age : 30 }
diff --git a/apps/oxfmt/tests/fixtures/multiple_files/types.d.ts b/apps/oxfmt/tests/fixtures/multiple_files/types.d.ts
new file mode 100644
index 0000000000000..f8d8d97d860be
--- /dev/null
+++ b/apps/oxfmt/tests/fixtures/multiple_files/types.d.ts
@@ -0,0 +1,9 @@
+declare module "my-module" {
+export function hello ( name : string ) : void
+ export interface Config {
+ enabled : boolean
+ }
+}
+export const visitorKeys: Record<
+string, string[]
+>;
diff --git a/apps/oxfmt/tests/mod.rs b/apps/oxfmt/tests/mod.rs
index 1f50f70cbe466..e55f717372839 100644
--- a/apps/oxfmt/tests/mod.rs
+++ b/apps/oxfmt/tests/mod.rs
@@ -28,6 +28,7 @@ fn multiple_files() {
// Explicit cwd
&["--check", "."],
&["--check", "./"],
+ &["--check", "!*.{ts,tsx}"],
],
);
}
diff --git a/apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap b/apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap
index f1f21d61580e2..252c51c39873b 100644
--- a/apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap
+++ b/apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap
@@ -20,11 +20,15 @@ arguments: --check
working directory: tests/fixtures/multiple_files
----------
Checking formatting...
+app.tsx (ms)
arrow.js (ms)
+component.jsx (ms)
simple.js (ms)
+simple.ts (ms)
+types.d.ts (ms)
-Format issues found in above 2 files. Run without `--check` to fix.
-Finished in ms on 2 files using 1 threads.
+Format issues found in above 6 files. Run without `--check` to fix.
+Finished in ms on 6 files using 1 threads.
----------
CLI result: FormatMismatch
----------
@@ -34,11 +38,15 @@ arguments: --check .
working directory: tests/fixtures/multiple_files
----------
Checking formatting...
+app.tsx (ms)
arrow.js (ms)
+component.jsx (ms)
simple.js (ms)
+simple.ts (ms)
+types.d.ts (ms)
-Format issues found in above 2 files. Run without `--check` to fix.
-Finished in ms on 2 files using 1 threads.
+Format issues found in above 6 files. Run without `--check` to fix.
+Finished in ms on 6 files using 1 threads.
----------
CLI result: FormatMismatch
----------
@@ -48,11 +56,30 @@ arguments: --check ./
working directory: tests/fixtures/multiple_files
----------
Checking formatting...
+app.tsx (ms)
arrow.js (ms)
+component.jsx (ms)
simple.js (ms)
+simple.ts (ms)
+types.d.ts (ms)
-Format issues found in above 2 files. Run without `--check` to fix.
-Finished in ms on 2 files using 1 threads.
+Format issues found in above 6 files. Run without `--check` to fix.
+Finished in ms on 6 files using 1 threads.
+----------
+CLI result: FormatMismatch
+----------
+
+##########
+arguments: --check !*.{ts,tsx}
+working directory: tests/fixtures/multiple_files
+----------
+Checking formatting...
+arrow.js (ms)
+component.jsx (ms)
+simple.js (ms)
+
+Format issues found in above 3 files. Run without `--check` to fix.
+Finished in ms on 3 files using 1 threads.
----------
CLI result: FormatMismatch
----------
diff --git a/crates/oxc_formatter/src/service/source_type.rs b/crates/oxc_formatter/src/service/source_type.rs
index 9874801d1c717..02c13e446d6fb 100644
--- a/crates/oxc_formatter/src/service/source_type.rs
+++ b/crates/oxc_formatter/src/service/source_type.rs
@@ -31,12 +31,13 @@ const ADDITIONAL_JS_EXTENSIONS: &[&str] = &[
];
pub fn get_supported_source_type(path: &std::path::Path) -> Option {
- let extension = path.extension()?.to_string_lossy();
-
// Standard extensions, also supported by `oxc_span::VALID_EXTENSIONS`
- if let Ok(source_type) = SourceType::from_extension(&extension) {
+ // NOTE: Use `path` directly for `.d.ts` detection
+ if let Ok(source_type) = SourceType::from_path(path) {
return Some(source_type);
}
+
+ let extension = path.extension()?.to_string_lossy();
// Additional extensions from linguist-languages, which Prettier also supports
if ADDITIONAL_JS_EXTENSIONS.contains(&extension.as_ref()) {
return Some(SourceType::default());