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

Skip to content

Log EditorConfig usage and resolved configuration to prevent silent config conflicts#3867

Merged
ntotten merged 3 commits intomainfrom
copilot/fix-line-break-issue
Dec 1, 2025
Merged

Log EditorConfig usage and resolved configuration to prevent silent config conflicts#3867
ntotten merged 3 commits intomainfrom
copilot/fix-line-break-issue

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

Description

.editorconfig files silently affect formatting without appearing in logs. When no .prettierrc exists but .editorconfig is present with formatting settings (e.g., indent_size, max_line_length), the extension logs "No local configuration detected" while actually applying those settings. This causes unexpected formatting behavior that's difficult to debug.

Root cause: Prettier's resolveConfigFile() returns only Prettier-specific configs, not .editorconfig. But resolveConfig() merges .editorconfig settings when editorconfig: true. The extension only checked for Prettier config files to determine log messages.

Changes:

Added comprehensive logging in ModuleResolverNode.resolveConfig():

  • Log when EditorConfig support is enabled
  • Log resolved Prettier config file path (if found)
  • Log custom config path from VS Code settings (if specified)
  • Log the complete resolved configuration object
  • Explicitly log when settings come from .editorconfig alone

Simplified logging in PrettierEditService.getPrettierOptions() since details are now logged upstream.

Example log output with .editorconfig only:

["INFO"] EditorConfig support is enabled, checking for .editorconfig files
["INFO"] Resolved config: { "printWidth": 40, "tabWidth": 3 }
["INFO"] No Prettier config file found, but settings were loaded from .editorconfig
["INFO"] Using local configuration (VS Code configuration will not be used)

Related Issue

Fixes #3848

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
Original prompt

This section details on the original issue you should resolve

<issue_title>Line break occurs when I use prettier and save it. </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

I'm using prettier extension in vscode. When you save the code from a certain point, the code is pushed up one line on the screen. For example, if I write a two-line code and save the code, the code goes up one line at a time on the screen, and the first line disappears from the screen. In other words, on the screen, the second line comes up to the top. But the code that's pushed up here has only briefly disappeared from the screen, not really removed. If you scroll, there's still a backlog there.

The following steps have been taken to resolve this issue:

  1. I only removed the pretier extension. -> There was no problem that the code was pushed up on the screen as above, but the code was not aligned because the pretier extension was removed.

  2. After initializing all settings related to vscode (I also deleted all extention files) to determine if it was a conflict with other extensions, we tested whether the same problem occurred after reinstalling vscode and installing only the prettier extension. -> The same problem occurred when the code was pushed up on the screen as above.

  3. The item "Editor: Scroll Beyond Last Line" has been unchecked. -> The problem of pushing up the code has disappeared, but it was inconvenient because it couldn't scroll after the end line of the code.

Github Repository to Reproduce Issue

x

Steps To Reproduce:

  1. This is step 1.
  2. This is step 2. All steps should start with '1.'

Expected result

I expected the code to be saved in Prettier's code alignment method without pushing the code up one line on the screen.

Actual result

The code is saved by pretier's code alignment method, but the code is pushed up one line on the screen.
That is, if I have two lines of code, the second line comes up on top of the screen at the same time as I save it. But the first line only disappeared for a moment on the screen, so if I scroll up, it still exists.

Additional information

화면-기록-2023-02-23-오후-6 29 50
KakaoTalk_Photo_2023-02-22-22-07-54

VS Code Version:
Version: 1.75.1 (Universal)
Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf
Date: 2023-02-08T21:34:59.000Z
Electron: 19.1.9
Chromium: 102.0.5005.194
Node.js: 16.14.2
V8: 10.2.154.23-electron.0
OS: Darwin arm64 22.1.0
Sandboxed: No

Prettier Extension Version: 9.10.4

OS and version: MacOS ventura 13.0.1

Prettier Log Output

["INFO" - 오전 4:29:19] Formatting completed in 34ms.
["INFO" - 오전 4:29:47] Formatting file:///Users/inguk/Desktop/%E1%84%83%E1%85%B3%E1%84%85%E1%85%B5%E1%86%B7%E1%84%8F%E1%85%A9%E1%84%83%E1%85%B5%E1%86%BCJS/experiment2.js
["INFO" - 오전 4:29:47] Using ignore file (if present) at /Users/inguk/Desktop/드림코딩JS/.prettierignore
["INFO" - 오전 4:29:47] File Info:
{
  "ignored": false,
  "inferredParser": "babel"
}
["INFO" - 오전 4:29:47] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 오전 4:29:47] Prettier Options:
{
  "arrowParens": "always",
  "bracketSpacing": true,
  "endOfLine": "lf",
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "singleAttributePerLine": false,
  "bracketSameLine": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": true,
  "printWidth": 80,
...

</details>

- Fixes prettier/prettier-vscode#2880

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Copilot AI and others added 2 commits December 1, 2025 23:19
- Log when EditorConfig support is enabled
- Log the config file path if found
- Log when settings come from .editorconfig (when no Prettier config exists)
- Log the complete resolved configuration
- Simplify logging messages in PrettierEditService

This helps users understand what configuration is being applied, especially
when .editorconfig has settings that affect formatting.

Co-authored-by: ntotten <[email protected]>
Also log when a custom prettier.configPath is specified in VS Code settings
to provide complete visibility into what configuration is being used.

Co-authored-by: ntotten <[email protected]>
Copilot AI changed the title [WIP] Fix line break issue with Prettier on save Log EditorConfig usage and resolved configuration to prevent silent config conflicts Dec 1, 2025
Copilot AI requested a review from ntotten December 1, 2025 23:27
@ntotten ntotten marked this pull request as ready for review December 1, 2025 23:32
Copilot AI review requested due to automatic review settings December 1, 2025 23:32
@ntotten ntotten merged commit c5f79f4 into main Dec 1, 2025
15 checks passed
@ntotten ntotten deleted the copilot/fix-line-break-issue branch December 1, 2025 23:32
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 enhances logging in the Prettier VS Code extension to make EditorConfig usage visible and prevent silent configuration conflicts. The main issue was that .editorconfig files would affect formatting without appearing in logs, making debugging difficult.

Key Changes:

  • Added detailed logging in ModuleResolverNode.resolveConfig() to log EditorConfig support status, resolved config files, custom config paths, and the complete resolved configuration
  • Simplified logging messages in PrettierEditService.getPrettierOptions() since detailed information is now logged upstream
  • Added specific detection and logging when settings come from .editorconfig alone

Reviewed changes

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

File Description
src/ModuleResolverNode.ts Added comprehensive logging for config resolution including EditorConfig usage, config file paths, custom config paths, and resolved configuration objects
src/PrettierEditService.ts Simplified logging messages to avoid redundancy since detailed config source information is now logged in ModuleResolver

Comment on lines +449 to +454
if (!configPath && resolvedConfig && vscodeConfig.useEditorConfig) {
// Config was resolved but no Prettier config file was found
// This means settings came from .editorconfig
this.loggingService.logInfo(
"No Prettier config file found, but settings were loaded from .editorconfig",
);
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.

The logic for detecting EditorConfig-only scenarios may be incorrect when a custom config path is specified via VS Code settings.

When customConfigPath is set (line 419-421), but configPath from resolveConfigFile() is undefined, this condition will incorrectly log "settings were loaded from .editorconfig" even though they actually came from the custom config file.

Example scenario:

  • User sets prettier.configPath to a custom location
  • No .prettierrc found by auto-discovery (configPath = undefined)
  • .editorconfig exists and useEditorConfig is true
  • resolvedConfig will contain settings from the custom config file
  • But this code will log "settings were loaded from .editorconfig" which is misleading

Suggested fix:

if (!configPath && !customConfigPath && resolvedConfig && vscodeConfig.useEditorConfig) {
  // Config was resolved but no Prettier config file was found
  // This means settings came from .editorconfig
  this.loggingService.logInfo(
    "No Prettier config file found, but settings were loaded from .editorconfig",
  );
}

Copilot uses AI. Check for mistakes.
const customConfigPath = vscodeConfig.configPath
? getWorkspaceRelativePath(fileName, vscodeConfig.configPath)
: undefined;

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.

This line contains trailing whitespace, which should be removed. The project uses Prettier which typically removes trailing whitespace by default.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +405 to +406
// Log what config file was found (if any)
if (configPath) {
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.

When a custom config path is specified in VS Code settings, logging "Using config file at {configPath}" can be misleading because the custom config path will take precedence (line 431: config: customConfigPath ?? configPath).

Example scenario:

  • Auto-discovered config: /project/.prettierrc
  • Custom config in settings: /custom/prettier.config.js
  • Logs: "Using config file at /project/.prettierrc" (misleading)
  • Then logs: "Using custom config path from settings: /custom/prettier.config.js" (correct)
  • Actually uses: /custom/prettier.config.js

Suggested fix:
Only log the auto-discovered config if it will actually be used:

// Log what config file was found (if any), only if no custom path will override it
if (configPath && !vscodeConfig.configPath) {
  this.loggingService.logInfo(`Using config file at ${configPath}`);
}
Suggested change
// Log what config file was found (if any)
if (configPath) {
// Log what config file was found (if any), only if no custom path will override it
if (configPath && !vscodeConfig.configPath) {

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.

Update Prettier to v3.7.2

3 participants