Skip to content

feat(formatter): Add a warning when Oxfmt is used without a configuration file.#19904

Closed
cpojer wants to merge 1 commit intooxc-project:mainfrom
cpojer:default-format-warning
Closed

feat(formatter): Add a warning when Oxfmt is used without a configuration file.#19904
cpojer wants to merge 1 commit intooxc-project:mainfrom
cpojer:default-format-warning

Conversation

@cpojer
Copy link
Copy Markdown
Contributor

@cpojer cpojer commented Mar 2, 2026

Same as #19313 but for Oxfmt. It will show a warning when Oxfmt is invoked without a configuration file.

Copilot AI review requested due to automatic review settings March 2, 2026 06:22
@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request labels Mar 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a user-facing note when oxfmt runs without any explicit or auto-discovered configuration, mirroring the UX added to oxlint in the referenced PR.

Changes:

  • Print a default-configuration note to stderr when no --config, no .oxfmtrc.*, and no .editorconfig are found.
  • Introduce uses_default_config(...) helper and re-export it via core.
  • Add unit tests for the new helper.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/oxfmt/src/stdin/mod.rs Emits the default-config note in stdin mode when no config sources exist.
apps/oxfmt/src/core/mod.rs Re-exports the new uses_default_config helper.
apps/oxfmt/src/core/config.rs Adds uses_default_config helper and unit tests.
apps/oxfmt/src/cli/mod.rs Adds shared DEFAULT_CONFIG_NOTE_MESSAGE constant.
apps/oxfmt/src/cli/format.rs Emits the default-config note in normal CLI formatting flow.
Comments suppressed due to low confidence (1)

apps/oxfmt/src/core/config.rs:540

  • Test modules in this crate are consistently named tests (or tests_*), but this new module is named test. Renaming it to tests would match the established convention and make it easier to search for test modules.
#[cfg(test)]
mod test {
    use std::path::Path;

Comment on lines +97 to +103
if uses_default_config(
config_options.config.as_deref(),
oxfmtrc_path.as_deref(),
editorconfig_path.as_deref(),
) {
utils::print_and_flush(stderr, DEFAULT_CONFIG_NOTE_MESSAGE);
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new default-config note changes stderr output for runs without any .oxfmtrc/.editorconfig, which will likely break existing Vitest CLI snapshot tests (many fixtures don't include config files). Please update/add CLI snapshot coverage to assert the note is printed (and update existing snapshots that now have non-empty stderr).

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +83
if uses_default_config(
config_options.config.as_deref(),
oxfmtrc_path.as_deref(),
editorconfig_path.as_deref(),
) {
utils::print_and_flush(stderr, DEFAULT_CONFIG_NOTE_MESSAGE);
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new default-config note will change stderr output for --stdin-filepath runs when no .oxfmtrc/.editorconfig exists, which may break existing stdin-related snapshot tests. Please update/add coverage so tests assert the note is printed in the no-config case (and that it is not printed when config files are present).

Copilot uses AI. Check for mistakes.
Comment on lines 8 to +11

pub(crate) const DEFAULT_CONFIG_NOTE_MESSAGE: &str =
"Using Oxfmt's default configuration. Run `oxfmt --init` to set up Oxfmt in this project.\n";

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_CONFIG_NOTE_MESSAGE advises running oxfmt --init, but --init is only available when the napi feature is enabled (see cli/command.rs). When building without default features (--no-default-features), this message will instruct users to run a flag that doesn't exist. Consider making the message conditional on cfg(feature = "napi"), or adjust the text for non-napi builds (e.g., point to creating .oxfmtrc.json manually).

Suggested change
pub(crate) const DEFAULT_CONFIG_NOTE_MESSAGE: &str =
"Using Oxfmt's default configuration. Run `oxfmt --init` to set up Oxfmt in this project.\n";
#[cfg(feature = "napi")]
pub(crate) const DEFAULT_CONFIG_NOTE_MESSAGE: &str =
"Using Oxfmt's default configuration. Run `oxfmt --init` to set up Oxfmt in this project.\n";
#[cfg(not(feature = "napi"))]
pub(crate) const DEFAULT_CONFIG_NOTE_MESSAGE: &str =
"Using Oxfmt's default configuration. Create a `.oxfmtrc.json` file to configure Oxfmt for this project.\n";

Copilot uses AI. Check for mistakes.
@leaysgur
Copy link
Copy Markdown
Member

leaysgur commented Mar 2, 2026

Thanks for getting things started!

However, since we intend to handle this matter as #19913, please allow me to close it for now. 🙏🏻

@leaysgur leaysgur closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants