Skip to content

feat: support array of strings for prettier.ignorePath setting - #4020

Open
Mohit-Gaur75 wants to merge 1 commit into
prettier:mainfrom
Mohit-Gaur75:feat/support-array-for-ignorepath
Open

Mohit-Gaur75 wants to merge 1 commit into
prettier:mainfrom
Mohit-Gaur75:feat/support-array-for-ignorepath

Conversation

@Mohit-Gaur75

Copy link
Copy Markdown

Summary

Fixes #3341
Addresses #3894

Prettier CLI and core API natively accept multiple ignore paths via ignorePath (supporting string | string[] since Prettier 3.0.0+ / PR prettier/prettier#14332). However, the VS Code extension previously only accepted a single string for prettier.ignorePath, preventing users from specifying multiple ignore files (such as [".prettierignore", ".gitignore"]).

This PR adds full support for configuring prettier.ignorePath as either a string or an array of strings.

Changes

  • Configuration Schema (package.json): Updated prettier.ignorePath using anyOf to accept either string or array of string.
  • Types (src/types.ts): Updated IExtensionConfig.ignorePath and ModuleResolverInterface.getResolvedIgnorePath to accept string | string[] and return Promise<string | string[] | undefined>.
  • Resolution (src/ModuleResolverNode.ts, src/ModuleResolverWeb.ts):
    • ModuleResolverNode: Resolves multiple paths in parallel, filters to existing files, and returns string[] | undefined.
    • ModuleResolverWeb: Resolves workspace-relative paths for arrays.
  • Formatting Service (src/PrettierEditService.ts): Updated PrettierEditService to forward the resolved string | string[] ignore path(s) to prettierInstance.getFileInfo(...) and format logging output for multiple paths.
  • Testing (src/test/suite/ModuleResolverNode.test.ts): Added unit tests verifying single string resolution, array resolution with filtering of non-existent files, and undefined fallback when none exist.
  • Documentation & Localization (README.md, package.nls*.json): Updated setting description and README to document array support.

Test plan

  • npm run compile succeeds
  • npm run compile:test succeeds
  • npm run lint passes with 0 errors
  • Code formatting verified with Prettier (npx prettier --check)
  • Unit tests added to src/test/suite/ModuleResolverNode.test.ts covering array of ignore paths

- Allow prettier.ignorePath to accept either a string or an array of strings in package.json configuration schema

- Update ModuleResolverNode and ModuleResolverWeb to resolve array of ignore paths in parallel and filter existing paths

- Update PrettierEditService to pass resolved string or string[] ignore paths to Prettier getFileInfo

- Add unit tests for resolving array of ignore paths in ModuleResolverNode.test.ts

- Update documentation and localization files

Fixes prettier#3341
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.

ignorePath only accepts a string not an array

1 participant