Skip to content

Conversation

Copy link

Copilot AI commented May 30, 2025

Problem

The prettier config resolution was failing when no prettierFilePath option was explicitly provided in the plugin configuration. This affected users who expected the plugin to automatically discover prettier config files (.prettierrc.json, .prettierrc.yml, etc.) in their project root.

Root Cause

The issue was in the fallback behavior in src/index.ts. When option.prettierFilePath was not provided, the code fell back to using config.root (a directory path):

const prettierOptions = 
  (await resolveConfig(option.prettierFilePath || config.root)) || {}

However, prettier.resolveConfig() expects a file path to search from, not a directory path. When passed a directory directly, it returns null, causing prettier configuration to be ignored.

Solution

Modified the fallback to provide a file path within the project root instead of the directory itself:

const prettierOptions =
  (await resolveConfig(
    option.prettierFilePath || join(config.root, 'package.json')
  )) || {}

This allows prettier to properly search for configuration files starting from the project root when no explicit prettierFilePath is provided.

Testing

  • ✅ Direct .json config files work when specified via prettierFilePath
  • ✅ Direct .yml config files work when specified via prettierFilePath
  • ✅ Direct .cjs config files continue to work (no regression)
  • ✅ Fallback behavior now correctly discovers config files in project root
  • ✅ Plugin initializes successfully with all config formats
  • ✅ No breaking changes to existing functionality

Changes

  • Added import for join from node:path
  • Updated fallback logic to use join(config.root, 'package.json') instead of config.root
  • Total: 2 lines added, 1 line modified (minimal surgical change)

Fixes #113.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] The prettierFilePath does not respect prettier config if it is .json or .yml Fix prettier config resolution when no prettierFilePath is provided May 30, 2025
Copilot AI requested a review from activeguild May 30, 2025 01:11
Copilot finished work on behalf of activeguild May 30, 2025 01:11
@activeguild activeguild closed this Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The prettierFilePath does not respect prettier config if it is .json or .yml

2 participants