Skip to content

Commit 1b2ab42

Browse files
committed
feat!: enable position indicator by default
- 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.
1 parent 21b4b53 commit 1b2ab42

4 files changed

Lines changed: 14 additions & 21 deletions

File tree

@commitlint/cli/src/cli.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ test("should print help", async () => {
606606
-q, --quiet toggle console output [boolean] [default: false]
607607
-t, --to upper end of the commit range to lint; applies if edit=false [string]
608608
-V, --verbose enable verbose output for reports without problems [boolean]
609-
--show-position show position of error in output [boolean]
609+
--show-position show position of error in output [boolean] [default: true]
610610
-s, --strict enable strict mode; result code 2 for warnings, 3 for errors [boolean]
611611
--options path to a JSON file or Common.js module containing CLI options
612612
-v, --version display version information [boolean]

@commitlint/cli/src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ const cli = yargs(process.argv.slice(2))
136136
},
137137
"show-position": {
138138
type: "boolean",
139+
default: true,
139140
description: "show position of error in output",
140141
},
141142
strict: {

@commitlint/format/src/format.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ test("shows position indicator when showPosition is true and error has position"
328328
},
329329
);
330330

331-
expect(actual).toContain("~~~");
331+
expect(actual).toContain("^");
332332
});
333333

334334
test("does not show position indicator when showPosition is false", () => {
@@ -355,10 +355,10 @@ test("does not show position indicator when showPosition is false", () => {
355355
},
356356
);
357357

358-
expect(actual).not.toContain("~~~");
358+
expect(actual).not.toContain("^");
359359
});
360360

361-
test("does not show position indicator when showPosition is not provided", () => {
361+
test("shows position indicator when showPosition is not provided (default)", () => {
362362
const actual = format(
363363
{
364364
results: [
@@ -381,7 +381,7 @@ test("does not show position indicator when showPosition is not provided", () =>
381381
},
382382
);
383383

384-
expect(actual).not.toContain("~~~");
384+
expect(actual).toContain("^");
385385
});
386386

387387
test("does not show position indicator when error has no position", () => {
@@ -406,7 +406,7 @@ test("does not show position indicator when error has no position", () => {
406406
},
407407
);
408408

409-
expect(actual).not.toContain("~~~");
409+
expect(actual).not.toContain("^");
410410
});
411411

412412
test("shows correct position for subject error", () => {
@@ -434,10 +434,10 @@ test("shows correct position for subject error", () => {
434434
},
435435
);
436436

437-
expect(actual).toContain("~~~~~~~~");
437+
expect(actual).toContain("^");
438438
});
439439

440-
test("shows position indicator with multiple tildes for longer errors", () => {
440+
test("shows position indicator with single caret for longer errors", () => {
441441
const actual = format(
442442
{
443443
results: [
@@ -462,7 +462,5 @@ test("shows position indicator with multiple tildes for longer errors", () => {
462462
},
463463
);
464464

465-
expect(actual).toContain(
466-
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
467-
);
465+
expect(actual).toContain("^");
468466
});

@commitlint/format/src/format.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function formatInput(
3838
result: FormattableResult & WithInput,
3939
options: FormatOptions = {},
4040
): string[] {
41-
const { color: enabled = true, showPosition = false } = options;
41+
const { color: enabled = true, showPosition = true } = options;
4242
const { errors = [], warnings = [], input = "" } = result;
4343

4444
if (!input) {
@@ -79,10 +79,10 @@ function getPositionIndicator(
7979
return undefined;
8080
}
8181

82-
const { start, end } = problemWithPosition;
82+
const { start } = problemWithPosition;
8383
const padding = " ";
8484

85-
const tilde = "~";
85+
const caret = "^";
8686

8787
const normalizedInput = input.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
8888
const lines = normalizedInput.split("\n");
@@ -92,15 +92,9 @@ function getPositionIndicator(
9292
return undefined;
9393
}
9494

95-
const lineLength = targetLine.length;
9695
const spacesBefore = Math.max(0, start.column - 1);
97-
const tildeLength = Math.max(
98-
1,
99-
Math.min(end.column - start.column, lineLength - (start.column - 1)),
100-
);
10196

102-
const indicator =
103-
padding + " ".repeat(spacesBefore) + tilde.repeat(tildeLength);
97+
const indicator = padding + " ".repeat(spacesBefore) + caret;
10498

10599
return indicator;
106100
}

0 commit comments

Comments
 (0)