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
1 change: 1 addition & 0 deletions apps/oxfmt/src/cli/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl FormatRunner {
let oxfmtrc_path = resolve_oxfmtrc_path(&cwd, config_options.config.as_deref());
let editorconfig_path = resolve_editorconfig_path(&cwd);
let mut config_resolver = match ConfigResolver::from_config_paths(
&cwd,
oxfmtrc_path.as_deref(),
editorconfig_path.as_deref(),
) {
Expand Down
3 changes: 2 additions & 1 deletion apps/oxfmt/src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl ConfigResolver {
/// - Config file is specified but not found or invalid
/// - Config file parsing fails
pub fn from_config_paths(
cwd: &Path,
oxfmtrc_path: Option<&Path>,
editorconfig_path: Option<&Path>,
) -> Result<Self, String> {
Expand Down Expand Up @@ -120,7 +121,7 @@ impl ConfigResolver {
let str = utils::read_to_string(path)
.map_err(|_| format!("Failed to read {}: File not found", path.display()))?;

Some(EditorConfig::parse(&str))
Some(EditorConfig::parse(&str).with_cwd(cwd))
}
None => None,
};
Expand Down
1 change: 1 addition & 0 deletions apps/oxfmt/src/stdin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl StdinRunner {
let oxfmtrc_path = resolve_oxfmtrc_path(&cwd, config_options.config.as_deref());
let editorconfig_path = resolve_editorconfig_path(&cwd);
let mut config_resolver = match ConfigResolver::from_config_paths(
&cwd,
oxfmtrc_path.as_deref(),
editorconfig_path.as_deref(),
) {
Expand Down
57 changes: 57 additions & 0 deletions apps/oxfmt/test/__snapshots__/editorconfig.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,60 @@ if (true) {

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

exports[`editorconfig > per-file overrides 1`] = `
"--- FILE -----------
test.js
--- BEFORE ---------
if (true) { console.log("js"); }

--- AFTER ----------
if (true) {
console.log("js");
}

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

--- FILE -----------
test.ts
--- BEFORE ---------
if (true) { console.log("ts"); }

--- AFTER ----------
if (true) {
console.log("ts");
}

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

--- FILE -----------
nested/deep/test.js
--- BEFORE ---------
if (true) { console.log("nested js"); }

--- AFTER ----------
if (true) {
console.log("nested js");
}

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

--- FILE -----------
nested/deep/test.json
--- BEFORE ---------
{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8}

--- AFTER ----------
{
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8
}

--------------------"
`;
8 changes: 3 additions & 5 deletions apps/oxfmt/test/editorconfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ describe("editorconfig", () => {
// [*] indent_style=space, indent_size=2
// [*.ts] indent_size=4
// [nested/**/*.js] indent_size=8
// [nested/**/*.json] indent_size=8, max_line_length=40
// [nested/deep/*.json] indent_style=tab, max_line_length=40
//
// Expected:
// - test.js: tabWidth=2 (from [*], not matched by [nested/**/*.js])
// - test.ts: tabWidth=4 (from [*.ts])
// - nested/deep/test.js: tabWidth=8 (from [nested/**/*.js], deep path glob)
// - nested/deep/test.json: tabWidth=8, printWidth=40 (from [nested/**/*.json], deep path glob for external formatter)
// TODO: Should fix `editor_config_parser` to accept `cwd` for `resolve()`
// oxlint-disable-next-line vitest/no-disabled-tests
it.skip("per-file overrides", async () => {
// - nested/deep/test.json: useTab=true, printWidth=40 (from [nested/deep/*.json], deep path glob for external formatter)
it("per-file overrides", async () => {
const cwd = join(fixturesDir, "per_file_override");
const snapshot = await runWriteModeAndSnapshot(cwd, [
"test.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ indent_size = 4
indent_size = 8

[nested/deep/*.json]
indent_size = 8
indent_style = tab
max_line_length = 40
Loading