Log EditorConfig usage and resolved configuration to prevent silent config conflicts#3867
Log EditorConfig usage and resolved configuration to prevent silent config conflicts#3867
Conversation
- 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]>
There was a problem hiding this comment.
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
.editorconfigalone
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 |
| 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", | ||
| ); |
There was a problem hiding this comment.
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.configPathto a custom location - No
.prettierrcfound by auto-discovery (configPath= undefined) .editorconfigexists anduseEditorConfigis trueresolvedConfigwill 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",
);
}| const customConfigPath = vscodeConfig.configPath | ||
| ? getWorkspaceRelativePath(fileName, vscodeConfig.configPath) | ||
| : undefined; | ||
|
|
There was a problem hiding this comment.
This line contains trailing whitespace, which should be removed. The project uses Prettier which typically removes trailing whitespace by default.
| // Log what config file was found (if any) | ||
| if (configPath) { |
There was a problem hiding this comment.
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}`);
}| // 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) { |
Description
.editorconfigfiles silently affect formatting without appearing in logs. When no.prettierrcexists but.editorconfigis 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. ButresolveConfig()merges.editorconfigsettings wheneditorconfig: true. The extension only checked for Prettier config files to determine log messages.Changes:
Added comprehensive logging in
ModuleResolverNode.resolveConfig():.editorconfigaloneSimplified logging in
PrettierEditService.getPrettierOptions()since details are now logged upstream.Example log output with
.editorconfigonly:Related Issue
Fixes #3848
Type of Change
Checklist
npm run lintpasses)npm run prettierto format my codenpm test)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.
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:
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.
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.
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:
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
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