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
4 changes: 2 additions & 2 deletions apps/oxfmt/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PATHS_ERROR_MESSAGE: &str = "PATH must not contain \"..\"";
#[derive(Debug, Clone, Bpaf)]
#[bpaf(options, version(VERSION))]
pub struct FormatCommand {
#[bpaf(external, fallback(OutputOptions::DefaultWrite), hide_usage)]
#[bpaf(external, fallback(OutputOptions::Write), hide_usage)]
pub output_options: OutputOptions,
#[bpaf(external)]
pub basic_options: BasicOptions,
Expand All @@ -43,7 +43,7 @@ pub struct FormatCommand {
pub enum OutputOptions {
/// Default - when no output option is specified, behaves like `--write` mode in Prettier
#[bpaf(hide)]
DefaultWrite,
Write,
/// Check mode - check if files are formatted, also show statistics
#[bpaf(long)]
Check,
Expand Down
2 changes: 1 addition & 1 deletion apps/oxfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl FormatRunner {
CliRunResult::FormatMismatch
}
// Default (write) does not output anything
(OutputOptions::DefaultWrite, changed_count) => {
(OutputOptions::Write, changed_count) => {
// Each changed file is also NOT printed
debug_assert_eq!(
changed_count, 0,
Expand Down
2 changes: 1 addition & 1 deletion apps/oxfmt/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl FormatService {
let is_changed = source_text != code;

// Write back if needed
if matches!(self.output_options, OutputOptions::DefaultWrite) && is_changed {
if matches!(self.output_options, OutputOptions::Write) && is_changed {
fs::write(path, code)
.map_err(|_| format!("Failed to write to '{}'", path.to_string_lossy()))
.unwrap();
Expand Down
28 changes: 28 additions & 0 deletions apps/oxfmt/test/__snapshots__/write_mode.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ const obj = {
--------------------"
`;

exports[`write_mode > should format unformatted files with explicit --write 1`] = `
"--- FILE -----------
unformatted.js
--- BEFORE ---------
class Foo {}

--- AFTER ----------
class Foo {}

--------------------

--- FILE -----------
complex.js
--- BEFORE ---------
const obj = {
foo: "bar",
baz: 123
};

--- AFTER ----------
const obj = {
foo: "bar",
baz: 123,
};

--------------------"
`;

exports[`write_mode > should not modify already formatted files 1`] = `
"--- FILE -----------
already_formatted.js
Expand Down
8 changes: 8 additions & 0 deletions apps/oxfmt/test/write_mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ describe("write_mode", () => {
expect(snapshot).toMatchSnapshot();
});

it("should format unformatted files with explicit --write", async () => {
const fixtureDir = join(fixturesDir, "write_mode");
const files = ["unformatted.js", "complex.js"];

const snapshot = await runWriteModeAndSnapshot(fixtureDir, files, ["--write"]);
expect(snapshot).toMatchSnapshot();
});

it("should not modify already formatted files", async () => {
const fixtureDir = join(fixturesDir, "write_mode");
const files = ["already_formatted.js"];
Expand Down
Loading