feat(cli)!: add --show-position flag to display error location#4629
feat(cli)!: add --show-position flag to display error location#4629escapedcat wants to merge 8 commits intomasterfrom
Conversation
Adds a new --show-position CLI option that displays a position indicator (~~~) under the commit input to show exactly where the error occurs, similar to TypeScript's red squiggly lines. This helps users quickly identify the problematic part of their commit message. Features: - Add optional start/end position fields to LintRuleOutcome and FormattableProblem - Add getRulePosition() helper to calculate error positions for various rules - Add showPosition option to FormatOptions - Add --show-position CLI flag (opt-in, default false) - Add tests for position indicator in format package - Update config-conventional tests to use toMatchObject for backward compatibility
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||
Add comprehensive tests for the getRulePosition function that calculates error positions for various rule types: - type-enum, type-case, type-max-length - scope-enum, scope-case - subject-max-length, subject-full-stop - header-max-length - body-max-line-length Also test edge cases like rules without position support and valid commits that don't need position data.
226cf37 to
88d04d7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ndling - Add fallback positions for type-empty, scope-empty, subject-empty, body-empty, footer-empty - Fix getPositionIndicator to find first problem with position (not just first problem) - Empty field rules now show position indicator pointing to where the field should be
- Fix typo: somehting -> something in test file
- Export Position interface from @commitlint/types - Use shared Position type in FormattableProblem - Remove duplicate Position interface from lint.ts - Improves maintainability by having a single source of truth
- Refactor getPositionIndicator to handle any line number dynamically - Normalize \r\n and \r to \n for cross-platform compatibility - Simplify code by using split approach instead of hard-coded line handling - Works for header, body, footer, and any future line numbers
|
@knocte wdyt? |
I love this! But IMO:
|
I'm worried this would be a breaking change and mess up whatever people do with current output format
As it was described in the issue and also as I mostly know it from other linters I guess |
I figured, but think about it: by being a flag this feature would be not discoverable at all, most people will not use it because they don't know about it. As a consequence of this, at some point you will think of making it the default, and then the breaking change will happen. Why not make the breaking change already? Just do a higher version in the bump. And let people file bugs, we'll fix them?
In the issue they use an example of something that has known length (the string "thisDoesNotExist") and so the compiler prints as many
Funny you say that because I spotted some compiler errors from typescript, pasted by people into issues, and all I saw is just a single |
7729dae to
1b2ab42
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| start: { line: 2, column: 1, offset: bodyStartOffset }, | ||
| end: { | ||
| line: 2, | ||
| column: parsed.body.length + 1, | ||
| offset: bodyStartOffset + parsed.body.length, | ||
| }, | ||
| }; | ||
| } | ||
| case "footer-empty": | ||
| case "footer-min-length": | ||
| case "footer-max-length": | ||
| case "footer-leading-blank": | ||
| case "footer-max-line-length": { | ||
| if (!parsed.footer) { | ||
| if (ruleName === "footer-empty") { | ||
| const footerOffset = raw.lastIndexOf("\n\n"); | ||
| if (footerOffset === -1) return undefined; | ||
| return { | ||
| start: { line: 3, column: 1, offset: footerOffset + 2 }, | ||
| end: { line: 3, column: 1, offset: footerOffset + 2 }, | ||
| }; | ||
| } | ||
| return undefined; | ||
| } | ||
| const footerOffset = raw.lastIndexOf("\n\n"); | ||
| if (footerOffset === -1) return undefined; | ||
| const footerStartOffset = footerOffset + 2; | ||
| return { | ||
| start: { line: 3, column: 1, offset: footerStartOffset }, | ||
| end: { | ||
| line: 3, | ||
| column: parsed.footer.length + 1, | ||
| offset: footerStartOffset + parsed.footer.length, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
The body and footer line numbers are hardcoded as line: 2 and line: 3 respectively. This is incorrect for commit messages with multi-line bodies. For example, a commit with a body spanning 5 lines would have a footer starting at line 7, not line 3. The actual line number should be computed dynamically by counting the newlines before the footer start offset in the raw string.
|
Wow, copilot feedback is really good |
bc208cc to
13def8c
Compare
- Change position indicator from ~ (multiple) to ^ (single caret) - Enable showPosition by default (breaking change) - Aligns with TypeScript/Rust error formatting - Keep --show-position flag to allow disabling BREAKING CHANGE: position indicator is now shown by default. Output format changed from multiple ~ characters to single ^ caret. Users can disable with --show-position=false.
13def8c to
720e751
Compare
User description
Fixes: #633
Adds a new --show-position CLI option that displays a position indicator (
^) under the commit input to show exactly where the error occurs, similar to TypeScript's red squiggly lines.This helps users quickly identify the problematic part of their commit message.
Features:
Local test
PR Type
Enhancement
Description
Add
--show-positionCLI flag to display error position indicatorsImplement position tracking for lint rule outcomes with start coordinates
Add
getRulePosition()helper to calculate error positions for various rulesDisplay position indicator (~~~) under commit input when flag is enabled
Update test assertions to use
toMatchObjectfor backward compatibilityDiagram Walkthrough
File Walkthrough
6 files
Add show-position CLI flag definitionAdd show-position to CliFlags interfaceImplement getRulePosition helper and position trackingAdd position indicator rendering logicAdd position fields to LintRuleOutcome interfaceAdd position fields and showPosition option to types3 files
Update help text to include show-position flagAdd comprehensive position indicator testsUpdate assertions to use toMatchObject1 files
Document showPosition option in format API