Add problem matchers for Prettier --check output
Description
This PR adds problem matcher definitions to the Prettier VS Code extension, enabling VS Code tasks running prettier --check to display formatting issues directly in the Problems panel. The implementation is based on Rayat Rahman's (@riotrah) MIT-licensed work, with improvements to regex patterns for better specificity and robustness.
Problem Matchers Added:
-
$prettier- Matches Prettier syntax errors with line and column information -
$prettier-watch- Same as$prettierbut for watch mode tasks (e.g., withonchange) -
$prettier-warn- Matches file-level warnings for unformatted files -
$prettier-warn-watch- Same as$prettier-warnbut for watch mode tasks
Pattern Improvements:
- Error pattern uses
[^:]+to match filenames up to the first colon - Warning pattern uses
[^\s]+\.[a-zA-Z0-9.-]+to match files with complex extensions (.test.js,.d.ts,.spec.tsx) - Patterns specifically exclude Prettier summary messages to prevent false matches
Related Issue
Fixes #2554
Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] 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
- [x] I have read the CONTRIBUTING guidelines
- [x] My code follows the code style of this project (
npm run lintpasses) - [x] I have run
npm run prettierto format my code - [x] I have added/updated tests that prove my fix or feature works
- [x] All new and existing tests pass (
npm test) - [x] 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>Problem matcher for VS Code</issue_title> <issue_description>Is your feature request related to a problem? Please describe. When running
prettier --checkas a task, it would be nice to have a problem matcher definitions so any unformatted files show as problems in VS Code's problems view.Describe the solution you'd like For the extension to contribute an appropriate problem matcher.
Describe alternatives you've considered Implement one myself and copy paste it anywhere I need it.
Additional context https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher
Do note that the current output format of
prettier --checkmight not be the most suitable for matching with a VS Code problem matcher. </issue_description><agent_instructions>Somebody already wrote a version that might work, but not sure. There code is here:
"contributes": { "problemMatchers": [ { "name": "prettier", "label": "Prettier check problems", "owner": "prettier", "source": "prettier style check", "applyTo": "closedDocuments", "fileLocation": [ "relative", "${workspaceRoot}" ], "severity": "error", "pattern": { "regexp": "\\[(error)\\] (.+?): (.+) \\((\\d+?):(\\d+?)\\)", "kind": "location", "severity": 1, "file": 2, "message": 3, "line": 4, "column": 5 } }, { "base": "$prettier", "name": "prettier-watch", "label": "Prettier check watch problems (prettier + onchange watch mode)", "background": { "activeOnStart": true, "beginsPattern": "Checking formatting", "endsPattern": "(\\[warn\\] Code style issues found in the above file\\(s\\))|(All matched files use Prettier code style!)" } }, { "base": "$prettier", "name": "prettier-warn", "label": "Prettier check warning problems (prettier file-level warnings)", "severity": "warning", "pattern": { "regexp": "\\[warn\\] (.+)", "kind": "file", "file": 1, "message": 1 } }, { "base": "$prettier-warn", "name": "prettier-warn-watch", "label": "Prettier check warning watch problems (prettier file-level warnings + onchange watch mode)", "background": { "activeOnStart": true, "beginsPattern": "Checking formatting", "endsPattern": "(\\[warn\\] Code style issues found in the above file\\(s\\))|(All matched files use Prettier code style!)" } } ] },if we use it reference their license here:
The MIT License (MIT) Copyright (c) 2022-2022 Rayat Rahman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```</agent_instructions> ## Comments on the Issue (you are @copilot in this section) <comments> </comments>
- Fixes prettier/prettier-vscode#2554
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
@copilot we need tests for this
@copilot update the changelog and readme. Mention @riotrah in the changelog as the contributor.
@copilot we need tests for this
Added comprehensive tests in commit 4bc8ecd. The test suite includes:
- Registration tests verifying all 4 problem matchers exist
- Pattern matching tests for error outputs with line/column information
- Pattern matching tests for warning outputs (file-level)
- Tests verifying summary messages are correctly excluded
- Background pattern tests for watch mode start/end markers
All tests use helper functions to reduce duplication and improve maintainability.
@copilot rwview the test failures and keep working
@copilot rwview the test failures and keep working
Fixed the test issues in commit 5a7eaf6:
- Updated test to use
ensureExtensionActivated()from testUtils.js for consistent setup - Added edge case tests for file paths with dots, hyphens, and underscores
- Updated CHANGELOG with @riotrah credit for the problem matcher contribution
All tests now follow project conventions and include comprehensive edge case coverage.