Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add test for .prettierrc with string reference to ESM config package#3868

Merged
ntotten merged 3 commits intomainfrom
copilot/resolve-json-config-issue
Dec 1, 2025
Merged

Add test for .prettierrc with string reference to ESM config package#3868
ntotten merged 3 commits intomainfrom
copilot/resolve-json-config-issue

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

Description

Adds test coverage for .prettierrc files containing a string reference to an ESM config package. This pattern is valid in Prettier but was reported to fail in the extension with "Invalid prettier configuration file detected."

Test fixture structure:

  • .prettierrc containing "test-prettier-config-esm" (JSON string reference)
  • Local ESM package test-prettier-config-esm/ exporting Prettier config with "type": "module"
  • Prettier v3.7.3 to support ESM imports
  • Standard test/result files for format validation

Example of the pattern being tested:

// .prettierrc
"@1stg/prettier-config"

Where the referenced package exports ESM:

// node_modules/@1stg/prettier-config/index.js
const config = { /* options */ };
export default config;

Verified: Prettier CLI resolves this config correctly. Test will validate extension behavior.

Related Issue

Addresses issue where extension fails to resolve string JSON configs that reference pure ESM prettier config packages.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/Build changes

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project (npm run lint passes)
  • I have run npm run prettier to format my code
  • I have added/updated tests that prove my fix or feature works
  • All new and existing tests pass (npm test)
  • I have updated the CHANGELOG.md with a summary of my changes

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

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

  • https://api.github.com//advisories
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (http block)
  • update.code.visualstudio.com
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/.bin/vscode-test (dns block)

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

Original prompt

This section details on the original issue you should resolve

<issue_title>Unable to resolve string JSON config which resolves a pure ESM prettier config</issue_title>
<issue_description><!--
SEE THIS GUIDE ON OPENING A GOOD ISSUE: https://github.com/prettier/prettier-vscode/wiki/Writing-a-Good-Issue

You must complete all steps in this checklist or the issue will be automatically closed.

  • Write a summary of your issue
  • Include a link to a github repo that can be used to reproduce the issue or exact reproduction steps.
  • Provide the expected result
  • Provide the actual result
  • Include extension, os, and vs code information
  • Include Prettier extension log

PLEASE NOTE: Many of the issues with the extension are heavily based on your specific configuration and source code. In order to improve your chances of having your bug fixed, the number one thing you can do is create a github repository that can be used to reproduce the issue along with the detailed reproduction steps. If you don't provide this info, it is usually the case that we cannot reproduce the issue and the issue will be closed.

DO NOT PUT LOGS OR CODE SNIPPETS IN SCREENSHOTS. THIS MAKES IT IMPOSSIBLE TO COPY/PASTE
-->

Summary

// .prettierrc
"@1stg/prettier-config"

Github Repository to Reproduce Issue

https://github.com/un-ts/preversion

Steps To Reproduce:

  1. yarn install
  2. Change something in package.json and exec format command

Expected result

No error

Actual result

Error

Additional information

Image

VS Code Version:

版本: 1.100.1
提交: 91fa95bccb027ece6a968589bb1d662fa9c8e170
日期: 2025-05-09T15:43:50.040Z
Electron: 34.5.1
ElectronBuildId: 11369351
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.4.0

Prettier Extension Version:

11.0.0

OS and version:

macOS 15.4.1 (24E263)

Prettier Log Output

["INFO" - 08:30:41] Formatting file:///Users/JounQin/Workspaces/GitHub/configs/package.json
["ERROR" - 08:30:41] Invalid prettier configuration file detected.
{}

</issue_description>

<agent_instructions>Add a test for this</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 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] Fix JSON config resolution for ESM Prettier Add test for .prettierrc with string reference to ESM config package Dec 1, 2025
Copilot AI requested a review from ntotten December 1, 2025 23:36
@ntotten ntotten marked this pull request as ready for review December 1, 2025 23:37
Copilot AI review requested due to automatic review settings December 1, 2025 23:37
@ntotten ntotten merged commit 2984cef into main Dec 1, 2025
15 checks passed
@ntotten ntotten deleted the copilot/resolve-json-config-issue branch December 1, 2025 23:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds test coverage for a specific Prettier configuration pattern where a .prettierrc file contains a string reference to an ESM config package. This addresses an issue where the extension fails with "Invalid prettier configuration file detected" when resolving such configurations.

Key changes:

  • New test suite string-esm-config.test.ts to validate string ESM config resolution
  • Test fixture test-fixtures/string-esm-config/ with local ESM package dependency
  • Workspace configuration updated to include the new test fixture

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/test/suite/string-esm-config.test.ts New test suite validating .prettierrc with string reference to ESM config package
test-fixtures/test.code-workspace Added string-esm-config fixture to test workspace
test-fixtures/string-esm-config/.prettierrc Test config file containing string reference to ESM package
test-fixtures/string-esm-config/package.json Test fixture package with Prettier 3.4.2 and local ESM config package dependency
test-fixtures/string-esm-config/test.js Unformatted test input file
test-fixtures/string-esm-config/test.result.js Expected formatted output
test-fixtures/string-esm-config/test-prettier-config-esm/package.json ESM config package definition with proper module exports
test-fixtures/string-esm-config/test-prettier-config-esm/index.js ESM config package exporting Prettier configuration

@@ -0,0 +1 @@
const foo={bar:1,baz:2};
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable foo.

Suggested change
const foo={bar:1,baz:2};

Copilot uses AI. Check for mistakes.
@@ -0,0 +1 @@
const foo = { bar: 1, baz: 2 };
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable foo.

Suggested change
const foo = { bar: 1, baz: 2 };

Copilot uses AI. Check for mistakes.
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.

Unable to resolve string JSON config which resolves a pure ESM prettier config

3 participants