Skip to content

Config resolution differs between explicit paths and glob patterns #84

@vnhlvn

Description

@vnhlvn

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:

{
  "tabWidth": 2
}

3. Create subdirectory with its own config

mkdir subdir

Create subdir/.prettierrc:

{
  "tabWidth": 4
}

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions