The experimental cli applies different configuration files to the same file depending on whether you specify an explicit file path or use a glob pattern
Observed behavior:
- Explicit path (
subdir/example.js): Uses root .prettierrc config ❌
- Glob pattern (
"subdir/*.js"): Uses subdirectory .prettierrc config ✅
According to Prettier's documentation, config resolution should search upward from the file being formatted and use the closest config found. Both commands should use subdir/.prettierrc for files in subdir/.
Reproduction Steps
1. Set up a test dir
mkdir prettier-experimental-bug
cd prettier-experimental-bug
npm init -y
npm install --save-dev prettier@latest
2. Create root Prettier config
Create .prettierrc in the project root:
3. Create subdirectory with its own config
Create subdir/.prettierrc:
4. Create a test file
Create subdir/example.js:
function example() {
return;
}
5. Format the file to establish baseline
npx prettier --no-cache --experimental-cli --write "subdir/*.js"
This should format the code block with 4-space indentation (using subdir/.prettierrc).
6. Reproduce the bug
Test with explicit path:
npx prettier --no-cache --experimental-cli --check subdir/example.js
Checking fails ✗ (file has 4 spaces, but root config expects 2 spaces)
Test with glob pattern:
npx prettier --no-cache --experimental-cli --check "subdir/*.js"
Checking passes ✓ (file has 4 spaces, subdir config expects 4 spaces)
The experimental cli applies different configuration files to the same file depending on whether you specify an explicit file path or use a glob pattern
Observed behavior:
subdir/example.js): Uses root.prettierrcconfig ❌"subdir/*.js"): Uses subdirectory.prettierrcconfig ✅According to Prettier's documentation, config resolution should search upward from the file being formatted and use the closest config found. Both commands should use
subdir/.prettierrcfor files insubdir/.Reproduction Steps
1. Set up a test dir
mkdir prettier-experimental-bug cd prettier-experimental-bug npm init -y npm install --save-dev prettier@latest2. Create root Prettier config
Create
.prettierrcin the project root:{ "tabWidth": 2 }3. Create subdirectory with its own config
Create
subdir/.prettierrc:{ "tabWidth": 4 }4. Create a test file
Create
subdir/example.js:5. Format the file to establish baseline
npx prettier --no-cache --experimental-cli --write "subdir/*.js"This should format the code block with 4-space indentation (using
subdir/.prettierrc).6. Reproduce the bug
Test with explicit path:
Checking fails ✗ (file has 4 spaces, but root config expects 2 spaces)
Test with glob pattern:
npx prettier --no-cache --experimental-cli --check "subdir/*.js"Checking passes ✓ (file has 4 spaces, subdir config expects 4 spaces)