Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/oxfmt/tests/fixtures/multiple_files/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface Props {
title : string
count : number
}
const App : React.FC < Props > = ( { title , count } ) => {
return <div >
<h1 > { title } </h1>
<span > Count : { count } </span>
</div>
}
6 changes: 3 additions & 3 deletions apps/oxfmt/tests/fixtures/multiple_files/arrow.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const fn1 = ( ) => { }
const fn2 = x => x * 2
const fn3 = ( a , b ) => a + b
const Element = ( ) => <button onClick = { ( ) => alert ( "clicked" ) } >
Click me
</button>
6 changes: 6 additions & 0 deletions apps/oxfmt/tests/fixtures/multiple_files/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const Component = ( ) => {
return <div className = "container" >
<h1 > Hello </h1>
<p > World </p>
</div>
}
5 changes: 5 additions & 0 deletions apps/oxfmt/tests/fixtures/multiple_files/simple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Person {
name : string
age:number
}
const user : Person = { name : "Alice" , age : 30 }
9 changes: 9 additions & 0 deletions apps/oxfmt/tests/fixtures/multiple_files/types.d.ts
Original file line number Diff line number Diff line change
@@ -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[]
>;
1 change: 1 addition & 0 deletions apps/oxfmt/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn multiple_files() {
// Explicit cwd
&["--check", "."],
&["--check", "./"],
&["--check", "!*.{ts,tsx}"],
],
);
}
Expand Down
39 changes: 33 additions & 6 deletions apps/oxfmt/tests/snapshots/multiple_files@oxfmt.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ arguments: --check
working directory: tests/fixtures/multiple_files
----------
Checking formatting...
app.tsx (<variable>ms)
arrow.js (<variable>ms)
component.jsx (<variable>ms)
simple.js (<variable>ms)
simple.ts (<variable>ms)
types.d.ts (<variable>ms)

Format issues found in above 2 files. Run without `--check` to fix.
Finished in <variable>ms on 2 files using 1 threads.
Format issues found in above 6 files. Run without `--check` to fix.
Finished in <variable>ms on 6 files using 1 threads.
----------
CLI result: FormatMismatch
----------
Expand All @@ -34,11 +38,15 @@ arguments: --check .
working directory: tests/fixtures/multiple_files
----------
Checking formatting...
app.tsx (<variable>ms)
arrow.js (<variable>ms)
component.jsx (<variable>ms)
simple.js (<variable>ms)
simple.ts (<variable>ms)
types.d.ts (<variable>ms)

Format issues found in above 2 files. Run without `--check` to fix.
Finished in <variable>ms on 2 files using 1 threads.
Format issues found in above 6 files. Run without `--check` to fix.
Finished in <variable>ms on 6 files using 1 threads.
----------
CLI result: FormatMismatch
----------
Expand All @@ -48,11 +56,30 @@ arguments: --check ./
working directory: tests/fixtures/multiple_files
----------
Checking formatting...
app.tsx (<variable>ms)
arrow.js (<variable>ms)
component.jsx (<variable>ms)
simple.js (<variable>ms)
simple.ts (<variable>ms)
types.d.ts (<variable>ms)

Format issues found in above 2 files. Run without `--check` to fix.
Finished in <variable>ms on 2 files using 1 threads.
Format issues found in above 6 files. Run without `--check` to fix.
Finished in <variable>ms on 6 files using 1 threads.
----------
CLI result: FormatMismatch
----------

##########
arguments: --check !*.{ts,tsx}
working directory: tests/fixtures/multiple_files
----------
Checking formatting...
arrow.js (<variable>ms)
component.jsx (<variable>ms)
simple.js (<variable>ms)

Format issues found in above 3 files. Run without `--check` to fix.
Finished in <variable>ms on 3 files using 1 threads.
----------
CLI result: FormatMismatch
----------
7 changes: 4 additions & 3 deletions crates/oxc_formatter/src/service/source_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ const ADDITIONAL_JS_EXTENSIONS: &[&str] = &[
];

pub fn get_supported_source_type(path: &std::path::Path) -> Option<SourceType> {
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());
Expand Down
Loading