From 63df94b6d2089e378c3187a123e410847ae272a0 Mon Sep 17 00:00:00 2001 From: leaysgur <6259812+leaysgur@users.noreply.github.com> Date: Mon, 19 Jan 2026 07:39:43 +0000 Subject: [PATCH] test(oxfmt): Test `oxfmtrc.overrides` (#18208) Follow up on #18068 --- .../oxfmtrc_overrides.test.ts.snap | 93 +++++++++++++++ .../fixtures/basic/.oxfmtrc.json | 12 ++ .../fixtures/basic/.testrc.js | 4 + .../oxfmtrc_overrides/fixtures/basic/app.js | 4 + .../fixtures/basic/app_test.js | 4 + .../fixtures/basic/app_test.min.js | 4 + .../fixtures/basic/app_test.ts | 4 + .../fixtures/basic/vendor/lib.js | 4 + .../fixtures/multiple_overrides/.oxfmtrc.json | 24 ++++ .../fixtures/multiple_overrides/root.js | 4 + .../fixtures/multiple_overrides/src/app.js | 4 + .../multiple_overrides/src/app_test.js | 4 + .../multiple_overrides/src/deep/nested/app.js | 4 + .../fixtures/path_with_slash/.oxfmtrc.json | 11 ++ .../fixtures/path_with_slash/lib/app.js | 4 + .../fixtures/path_with_slash/src/app.js | 4 + .../fixtures/prettier_overrides/.oxfmtrc.json | 18 +++ .../fixtures/prettier_overrides/indented.vue | 9 ++ .../prettier_overrides/not-indented.vue | 9 ++ .../prettier_overrides/sorted/package.json | 5 + .../prettier_overrides/unsorted/package.json | 5 + .../priority_over_editorconfig/.editorconfig | 5 + .../priority_over_editorconfig/.oxfmtrc.json | 11 ++ .../src/nested/app.js | 4 + .../tailwindcss_options/.oxfmtrc.json | 21 ++++ .../fixtures/tailwindcss_options/use-clsx.tsx | 2 + .../fixtures/tailwindcss_options/use-cn.tsx | 2 + .../oxfmtrc_overrides.test.ts | 111 ++++++++++++++++++ 28 files changed, 390 insertions(+) create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/__snapshots__/oxfmtrc_overrides.test.ts.snap create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.oxfmtrc.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.testrc.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.min.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.ts create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/vendor/lib.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/.oxfmtrc.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/root.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app_test.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/deep/nested/app.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/.oxfmtrc.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/lib/app.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/src/app.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/.oxfmtrc.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/indented.vue create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/not-indented.vue create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/sorted/package.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/unsorted/package.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.editorconfig create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.oxfmtrc.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/src/nested/app.js create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/.oxfmtrc.json create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-clsx.tsx create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-cn.tsx create mode 100644 apps/oxfmt/test/cli/oxfmtrc_overrides/oxfmtrc_overrides.test.ts diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/__snapshots__/oxfmtrc_overrides.test.ts.snap b/apps/oxfmt/test/cli/oxfmtrc_overrides/__snapshots__/oxfmtrc_overrides.test.ts.snap new file mode 100644 index 0000000000000..e64d9746b2968 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/__snapshots__/oxfmtrc_overrides.test.ts.snap @@ -0,0 +1,93 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`oxfmtrc overrides > Prettier options override - only enabled for specific files 1`] = ` +"-------------------- +arguments: --check . +working directory: oxfmtrc_overrides/fixtures/prettier_overrides +exit code: 1 +--- STDOUT --------- +Checking formatting... + +indented.vue (ms) + +Format issues found in above 1 files. Run without \`--check\` to fix. +Finished in ms on 5 files using 1 threads. +--- STDERR --------- + +--------------------" +`; + +exports[`oxfmtrc overrides > Tailwind CSS override - different options per file (cache test) 1`] = ` +"-------------------- +arguments: --check . +working directory: oxfmtrc_overrides/fixtures/tailwindcss_options +exit code: 0 +--- STDOUT --------- +Checking formatting... + +All matched files use the correct format. +Finished in ms on 3 files using 1 threads. +--- STDERR --------- + +--------------------" +`; + +exports[`oxfmtrc overrides > basic file pattern override with excludeFiles 1`] = ` +"-------------------- +arguments: --check . +working directory: oxfmtrc_overrides/fixtures/basic +exit code: 0 +--- STDOUT --------- +Checking formatting... + +All matched files use the correct format. +Finished in ms on 7 files using 1 threads. +--- STDERR --------- + +--------------------" +`; + +exports[`oxfmtrc overrides > multiple overrides - later overrides take precedence 1`] = ` +"-------------------- +arguments: --check . +working directory: oxfmtrc_overrides/fixtures/multiple_overrides +exit code: 0 +--- STDOUT --------- +Checking formatting... + +All matched files use the correct format. +Finished in ms on 5 files using 1 threads. +--- STDERR --------- + +--------------------" +`; + +exports[`oxfmtrc overrides > oxfmtrc overrides take precedence over editorconfig 1`] = ` +"-------------------- +arguments: --check . +working directory: oxfmtrc_overrides/fixtures/priority_over_editorconfig +exit code: 0 +--- STDOUT --------- +Checking formatting... + +All matched files use the correct format. +Finished in ms on 1 files using 1 threads. +--- STDERR --------- + +--------------------" +`; + +exports[`oxfmtrc overrides > pattern with slash - matches only specified path 1`] = ` +"-------------------- +arguments: --check . +working directory: oxfmtrc_overrides/fixtures/path_with_slash +exit code: 0 +--- STDOUT --------- +Checking formatting... + +All matched files use the correct format. +Finished in ms on 3 files using 1 threads. +--- STDERR --------- + +--------------------" +`; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.oxfmtrc.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.oxfmtrc.json new file mode 100644 index 0000000000000..8fabe490ddd9d --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.oxfmtrc.json @@ -0,0 +1,12 @@ +{ + "tabWidth": 2, + "overrides": [ + { + "files": ["*_test.js", "*_test.ts", ".*rc.js"], + "excludeFiles": ["*.min.js", "vendor/**"], + "options": { + "tabWidth": 4 + } + } + ] +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.testrc.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.testrc.js new file mode 100644 index 0000000000000..3ccb20a608b2e --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/.testrc.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app.js new file mode 100644 index 0000000000000..27513d7d40777 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.js new file mode 100644 index 0000000000000..3ccb20a608b2e --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.min.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.min.js new file mode 100644 index 0000000000000..27513d7d40777 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.min.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.ts b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.ts new file mode 100644 index 0000000000000..fc0cff1dd384a --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/app_test.ts @@ -0,0 +1,4 @@ +const x: object = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/vendor/lib.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/vendor/lib.js new file mode 100644 index 0000000000000..27513d7d40777 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/basic/vendor/lib.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/.oxfmtrc.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/.oxfmtrc.json new file mode 100644 index 0000000000000..20e6d8d22aa5f --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/.oxfmtrc.json @@ -0,0 +1,24 @@ +{ + "tabWidth": 2, + "semi": true, + "overrides": [ + { + "files": ["src/**/*.js"], + "options": { + "tabWidth": 4 + } + }, + { + "files": ["src/**/*_test.js"], + "options": { + "semi": false + } + }, + { + "files": ["src/deep/**/*.js"], + "options": { + "tabWidth": 6 + } + } + ] +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/root.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/root.js new file mode 100644 index 0000000000000..27513d7d40777 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/root.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app.js new file mode 100644 index 0000000000000..3ccb20a608b2e --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app_test.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app_test.js new file mode 100644 index 0000000000000..90b2bd43d54df --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/app_test.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/deep/nested/app.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/deep/nested/app.js new file mode 100644 index 0000000000000..9d41a1642955d --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/multiple_overrides/src/deep/nested/app.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/.oxfmtrc.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/.oxfmtrc.json new file mode 100644 index 0000000000000..e7e6b763e7c33 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/.oxfmtrc.json @@ -0,0 +1,11 @@ +{ + "tabWidth": 2, + "overrides": [ + { + "files": ["src/*.js"], + "options": { + "tabWidth": 4 + } + } + ] +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/lib/app.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/lib/app.js new file mode 100644 index 0000000000000..27513d7d40777 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/lib/app.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/src/app.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/src/app.js new file mode 100644 index 0000000000000..3ccb20a608b2e --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/path_with_slash/src/app.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/.oxfmtrc.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/.oxfmtrc.json new file mode 100644 index 0000000000000..1a4ccb68e5f57 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/.oxfmtrc.json @@ -0,0 +1,18 @@ +{ + "experimentalSortPackageJson": false, + "vueIndentScriptAndStyle": false, + "overrides": [ + { + "files": ["sorted/package.json"], + "options": { + "experimentalSortPackageJson": true + } + }, + { + "files": ["indented.vue"], + "options": { + "vueIndentScriptAndStyle": true + } + } + ] +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/indented.vue b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/indented.vue new file mode 100644 index 0000000000000..010a164d4704d --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/indented.vue @@ -0,0 +1,9 @@ + + + diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/not-indented.vue b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/not-indented.vue new file mode 100644 index 0000000000000..8cf16777f1090 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/not-indented.vue @@ -0,0 +1,9 @@ + + + diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/sorted/package.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/sorted/package.json new file mode 100644 index 0000000000000..7c2283cd0e3e4 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/sorted/package.json @@ -0,0 +1,5 @@ +{ + "name": "sorted", + "version": "1.0.0", + "description": "This should be sorted" +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/unsorted/package.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/unsorted/package.json new file mode 100644 index 0000000000000..39125daf5c189 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/prettier_overrides/unsorted/package.json @@ -0,0 +1,5 @@ +{ + "description": "This should NOT be sorted", + "version": "1.0.0", + "name": "unsorted" +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.editorconfig b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.editorconfig new file mode 100644 index 0000000000000..d0d97b6b17f79 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*] +indent_style = space +indent_size = 8 diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.oxfmtrc.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.oxfmtrc.json new file mode 100644 index 0000000000000..17aa5fa30ac3d --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/.oxfmtrc.json @@ -0,0 +1,11 @@ +{ + "ignorePatterns": [".oxfmtrc.json"], + "overrides": [ + { + "files": ["*.js"], + "options": { + "tabWidth": 4 + } + } + ] +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/src/nested/app.js b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/src/nested/app.js new file mode 100644 index 0000000000000..3ccb20a608b2e --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/priority_over_editorconfig/src/nested/app.js @@ -0,0 +1,4 @@ +const x = { + foo: 1, + bar: 2, +}; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/.oxfmtrc.json b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/.oxfmtrc.json new file mode 100644 index 0000000000000..f52b59a6b9717 --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/.oxfmtrc.json @@ -0,0 +1,21 @@ +{ + "experimentalTailwindcss": {}, + "overrides": [ + { + "files": ["use-clsx.tsx"], + "options": { + "experimentalTailwindcss": { + "functions": ["clsx"] + } + } + }, + { + "files": ["use-cn.tsx"], + "options": { + "experimentalTailwindcss": { + "functions": ["cn"] + } + } + } + ] +} diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-clsx.tsx b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-clsx.tsx new file mode 100644 index 0000000000000..9d5ce25af5abf --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-clsx.tsx @@ -0,0 +1,2 @@ +const A =
clsx sorted
; +const B =
cn NOT sorted
; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-cn.tsx b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-cn.tsx new file mode 100644 index 0000000000000..a3ec0fc65313f --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/fixtures/tailwindcss_options/use-cn.tsx @@ -0,0 +1,2 @@ +const A =
clsx NOT sorted
; +const B =
cn sorted
; diff --git a/apps/oxfmt/test/cli/oxfmtrc_overrides/oxfmtrc_overrides.test.ts b/apps/oxfmt/test/cli/oxfmtrc_overrides/oxfmtrc_overrides.test.ts new file mode 100644 index 0000000000000..7fa7ed8ad55bc --- /dev/null +++ b/apps/oxfmt/test/cli/oxfmtrc_overrides/oxfmtrc_overrides.test.ts @@ -0,0 +1,111 @@ +import { describe, expect, it } from "vitest"; +import { join } from "node:path"; +import { runAndSnapshot } from "../utils"; + +const fixturesDir = join(import.meta.dirname, "fixtures"); + +describe("oxfmtrc overrides", () => { + // .oxfmtrc.json: + // tabWidth: 2 + // overrides: [{ files: ["*_test.js", "*_test.ts", ".*rc.js"], excludeFiles: ["*.min.js", "vendor/**"], options: { tabWidth: 4 } }] + // + // Expected: + // - app.js: tabWidth=2 (base) + // - app_test.js, app_test.ts: tabWidth=4 (multiple patterns in files array) + // - app_test.min.js: tabWidth=2 (excluded by excludeFiles) + // - vendor/lib.js: tabWidth=2 (excluded by excludeFiles with directory pattern) + // - .testrc.js: tabWidth=4 (dotfile pattern match) + it("basic file pattern override with excludeFiles", async () => { + const cwd = join(fixturesDir, "basic"); + const snapshot = await runAndSnapshot(cwd, [["--check", "."]]); + expect(snapshot).toMatchSnapshot(); + }); + + // .editorconfig: + // [*] indent_size=8 + // .oxfmtrc.json: + // overrides: [{ files: ["*.js"], options: { tabWidth: 4 } }] + // + // Expected: + // - src/nested/app.js: formatted with tabWidth=4 (oxfmtrc override takes precedence over editorconfig) + // + // NOTE: "*.js" pattern matches nested files because it's internally converted to "**/*.js" + it("oxfmtrc overrides take precedence over editorconfig", async () => { + const cwd = join(fixturesDir, "priority_over_editorconfig"); + const snapshot = await runAndSnapshot(cwd, [["--check", "."]]); + expect(snapshot).toMatchSnapshot(); + }); + + // .oxfmtrc.json: + // tabWidth: 2 + // overrides: [{ files: ["src/*.js"], options: { tabWidth: 4 } }] + // + // Expected: + // - src/app.js: formatted with tabWidth=4 (pattern with "/" is NOT prefixed with "**/"") + // - lib/app.js: formatted with tabWidth=2 (pattern "src/*.js" does NOT match "lib/app.js") + // + // Note: Patterns containing "/" are used as-is, NOT prefixed with "**/" + it("pattern with slash - matches only specified path", async () => { + const cwd = join(fixturesDir, "path_with_slash"); + const snapshot = await runAndSnapshot(cwd, [["--check", "."]]); + expect(snapshot).toMatchSnapshot(); + }); + + // .oxfmtrc.json: + // tabWidth: 2, semi: true + // overrides: [ + // { files: ["src/**/*.js"], options: { tabWidth: 4 } }, + // { files: ["src/**/*_test.js"], options: { semi: false } }, + // { files: ["src/deep/**/*.js"], options: { tabWidth: 6 } } + // ] + // + // Expected: + // - root.js: formatted with tabWidth=2, semi=true (base config) + // - src/app.js: formatted with tabWidth=4, semi=true (first override) + // - src/app_test.js: formatted with tabWidth=4, semi=false (first and second overrides applied) + // - src/deep/nested/app.js: formatted with tabWidth=6, semi=true (first and third overrides, later wins) + it("multiple overrides - later overrides take precedence", async () => { + const cwd = join(fixturesDir, "multiple_overrides"); + const snapshot = await runAndSnapshot(cwd, [["--check", "."]]); + expect(snapshot).toMatchSnapshot(); + }); + + // .oxfmtrc.json: + // experimentalSortPackageJson: false + // vueIndentScriptAndStyle: false + // overrides: [ + // { files: ["sorted/package.json"], options: { experimentalSortPackageJson: true } }, + // { files: ["indented.vue"], options: { vueIndentScriptAndStyle: true } } + // ] + // + // Expected: + // - sorted/package.json: keys sorted (name, version, description) + // - unsorted/package.json: keys NOT sorted (original order preserved) + // - indented.vue: script/style content indented + // - not-indented.vue: script/style content NOT indented + // + // This test verifies overrides work for external formatter path (Prettier) + it("Prettier options override - only enabled for specific files", async () => { + const cwd = join(fixturesDir, "prettier_overrides"); + const snapshot = await runAndSnapshot(cwd, [["--check", "."]]); + expect(snapshot).toMatchSnapshot(); + }); + + // .oxfmtrc.json: + // experimentalTailwindcss: {} + // overrides: [ + // { files: ["use-clsx.tsx"], options: { experimentalTailwindcss: { functions: ["clsx"] } } }, + // { files: ["use-cn.tsx"], options: { experimentalTailwindcss: { functions: ["cn"] } } } + // ] + // + // Expected: + // - use-clsx.tsx: only clsx() classes sorted + // - use-cn.tsx: only cn() classes sorted + // + // This test verifies different Tailwind options per file work correctly (cache is not shared) + it("Tailwind CSS override - different options per file (cache test)", async () => { + const cwd = join(fixturesDir, "tailwindcss_options"); + const snapshot = await runAndSnapshot(cwd, [["--check", "."]]); + expect(snapshot).toMatchSnapshot(); + }); +});