Skip to content

Commit 88d04d7

Browse files
committed
fix: remove duplicate test names
1 parent 6a56853 commit 88d04d7

4 files changed

Lines changed: 18 additions & 171 deletions

File tree

@commitlint/format/src/format.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function formatInput(
5656
}
5757

5858
const positionIndicator = showPosition
59-
? getPositionIndicator(errors, input)
59+
? getPositionIndicator([...errors, ...warnings], input)
6060
: undefined;
6161

6262
const lines: string[] = [`${decoration} input: ${decoratedInput}`];
@@ -91,16 +91,15 @@ function getPositionIndicator(
9191
const headerEndIndex = input.indexOf("\n\n");
9292
if (headerEndIndex === -1) return undefined;
9393

94-
const bodyLineStart = headerEndIndex + 2;
95-
const charsOnLine = input.slice(bodyLineStart).indexOf("\n");
96-
const lineLength =
97-
charsOnLine === -1 ? input.length - bodyLineStart : charsOnLine;
94+
const bodyText = input.slice(headerEndIndex + 2);
95+
const firstBodyLine = bodyText.split("\n")[0];
96+
const lineLength = firstBodyLine.length;
9897

99-
if (start.column <= lineLength) {
98+
if (start.column <= lineLength + 1) {
10099
const spacesBefore = Math.max(0, start.column - 1);
101100
const tildeLength = Math.max(
102101
1,
103-
Math.min(end.column, lineLength) - start.column,
102+
Math.min(end.column - start.column, lineLength - (start.column - 1)),
104103
);
105104
indicator =
106105
padding + " ".repeat(spacesBefore) + tilde.repeat(tildeLength);
@@ -109,12 +108,16 @@ function getPositionIndicator(
109108
const footerStartIndex = input.lastIndexOf("\n\n");
110109
if (footerStartIndex === -1) return undefined;
111110

112-
const footerLineStart = footerStartIndex + 2;
113-
const lineLength = input.length - footerLineStart;
111+
const footerText = input.slice(footerStartIndex + 2);
112+
const firstFooterLine = footerText.split("\n")[0];
113+
const lineLength = firstFooterLine.length;
114114

115-
if (start.column <= lineLength) {
115+
if (start.column <= lineLength + 1) {
116116
const spacesBefore = Math.max(0, start.column - 1);
117-
const tildeLength = Math.max(1, end.column - start.column);
117+
const tildeLength = Math.max(
118+
1,
119+
Math.min(end.column - start.column, lineLength - (start.column - 1)),
120+
);
118121
indicator =
119122
padding + " ".repeat(spacesBefore) + tilde.repeat(tildeLength);
120123
}

@commitlint/lint/src/lint.test.ts

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -438,158 +438,3 @@ test("returns correct position for valid commit (no position needed)", async ()
438438
expect(result.valid).toBe(true);
439439
expect(result.errors).toHaveLength(0);
440440
});
441-
442-
test("returns position for subject-full-stop error", async () => {
443-
const result = await lint("feat: some message.", {
444-
"subject-full-stop": [RuleConfigSeverity.Error, "never", "."],
445-
});
446-
expect(result.valid).toBe(false);
447-
expect(result.errors[0].name).toBe("subject-full-stop");
448-
expect(result.errors[0].start).toBeDefined();
449-
expect(result.errors[0].start?.line).toBe(1);
450-
expect(result.errors[0].end).toBeDefined();
451-
});
452-
453-
test("returns position for header-max-length error", async () => {
454-
const longHeader =
455-
"feat: this is a very long header that definitely exceeds the maximum allowed character limit for commit messages";
456-
const result = await lint(longHeader, {
457-
"header-max-length": [RuleConfigSeverity.Error, "always", 50],
458-
});
459-
expect(result.valid).toBe(false);
460-
expect(result.errors[0].name).toBe("header-max-length");
461-
expect(result.errors[0].start).toEqual({ line: 1, column: 1, offset: 0 });
462-
expect(result.errors[0].end).toEqual({
463-
line: 1,
464-
column: longHeader.length + 1,
465-
offset: longHeader.length,
466-
});
467-
});
468-
469-
test("returns position for body-max-line-length error", async () => {
470-
const longBodyLine =
471-
"this is a body line that is way too long and exceeds the maximum allowed character limit";
472-
const result = await lint(`feat: some message\n\n${longBodyLine}`, {
473-
"body-max-line-length": [RuleConfigSeverity.Error, "always", 50],
474-
});
475-
expect(result.valid).toBe(false);
476-
expect(result.errors[0].name).toBe("body-max-line-length");
477-
expect(result.errors[0].start).toBeDefined();
478-
expect(result.errors[0].start?.line).toBe(2);
479-
});
480-
481-
test("returns position for header-max-length error", async () => {
482-
const longHeader =
483-
"feat: this is a very long header that definitely exceeds the maximum allowed character limit for commit messages";
484-
const result = await lint(longHeader, {
485-
"header-max-length": [RuleConfigSeverity.Error, "always", 50],
486-
});
487-
expect(result.valid).toBe(false);
488-
expect(result.errors[0].name).toBe("header-max-length");
489-
expect(result.errors[0].start).toEqual({ line: 1, column: 1, offset: 0 });
490-
expect(result.errors[0].end).toEqual({
491-
line: 1,
492-
column: longHeader.length + 1,
493-
offset: longHeader.length,
494-
});
495-
});
496-
497-
test("returns position for body-max-line-length error", async () => {
498-
const longBodyLine =
499-
"this is a body line that is way too long and exceeds the maximum allowed character limit";
500-
const result = await lint(`feat: some message\n\n${longBodyLine}`, {
501-
"body-max-line-length": [RuleConfigSeverity.Error, "always", 50],
502-
});
503-
expect(result.valid).toBe(false);
504-
expect(result.errors[0].name).toBe("body-max-line-length");
505-
expect(result.errors[0].start).toBeDefined();
506-
expect(result.errors[0].start?.line).toBe(2);
507-
});
508-
509-
test("returns no position for rules without position support", async () => {
510-
const result = await lint("somehting #1", {
511-
"references-empty": [RuleConfigSeverity.Error, "always"],
512-
});
513-
expect(result.valid).toBe(false);
514-
expect(result.errors[0].name).toBe("references-empty");
515-
expect(result.errors[0].start).toBeUndefined();
516-
expect(result.errors[0].end).toBeUndefined();
517-
});
518-
519-
test("returns position when type is provided", async () => {
520-
const result = await lint("feat: some message", {
521-
"type-enum": [RuleConfigSeverity.Error, "always", ["bar"]],
522-
});
523-
expect(result.valid).toBe(false);
524-
expect(result.errors[0].name).toBe("type-enum");
525-
expect(result.errors[0].start).toBeDefined();
526-
});
527-
528-
test("returns position when scope is provided", async () => {
529-
const result = await lint("feat(myscope): some message", {
530-
"scope-enum": [RuleConfigSeverity.Error, "always", ["other"]],
531-
});
532-
expect(result.valid).toBe(false);
533-
expect(result.errors[0].name).toBe("scope-enum");
534-
expect(result.errors[0].start).toBeDefined();
535-
});
536-
537-
test("handles duplicate text in message - uses first occurrence", async () => {
538-
const result = await lint("fix: test test", {
539-
"type-enum": [RuleConfigSeverity.Error, "always", ["feat", "fix"]],
540-
});
541-
expect(result.valid).toBe(true);
542-
expect(result.errors).toHaveLength(0);
543-
});
544-
545-
test("returns correct position for valid commit (no position needed)", async () => {
546-
const result = await lint("feat: add new feature", {
547-
"type-enum": [RuleConfigSeverity.Error, "always", ["feat", "fix"]],
548-
});
549-
expect(result.valid).toBe(true);
550-
expect(result.errors).toHaveLength(0);
551-
});
552-
553-
test("returns no position for rules without position support", async () => {
554-
const result = await lint("somehting #1", {
555-
"references-empty": [RuleConfigSeverity.Error, "always"],
556-
});
557-
expect(result.valid).toBe(false);
558-
expect(result.errors[0].name).toBe("references-empty");
559-
expect(result.errors[0].start).toBeUndefined();
560-
expect(result.errors[0].end).toBeUndefined();
561-
});
562-
563-
test("returns position when type is provided", async () => {
564-
const result = await lint("feat: some message", {
565-
"type-enum": [RuleConfigSeverity.Error, "always", ["bar"]],
566-
});
567-
expect(result.valid).toBe(false);
568-
expect(result.errors[0].name).toBe("type-enum");
569-
expect(result.errors[0].start).toBeDefined();
570-
});
571-
572-
test("returns position when scope is provided", async () => {
573-
const result = await lint("feat(myscope): some message", {
574-
"scope-enum": [RuleConfigSeverity.Error, "always", ["other"]],
575-
});
576-
expect(result.valid).toBe(false);
577-
expect(result.errors[0].name).toBe("scope-enum");
578-
expect(result.errors[0].start).toBeDefined();
579-
});
580-
581-
test("handles duplicate text in message - uses first occurrence", async () => {
582-
const result = await lint("fix: test test", {
583-
"type-enum": [RuleConfigSeverity.Error, "always", ["feat", "fix"]],
584-
});
585-
expect(result.valid).toBe(true);
586-
expect(result.errors).toHaveLength(0);
587-
});
588-
589-
test("returns correct position for valid commit (no position needed)", async () => {
590-
const result = await lint("feat: add new feature", {
591-
"type-enum": [RuleConfigSeverity.Error, "always", ["feat", "fix"]],
592-
});
593-
expect(result.valid).toBe(true);
594-
expect(result.errors).toHaveLength(0);
595-
});

@commitlint/lint/src/lint.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function getRulePosition(
4545
case "type-min-length":
4646
case "type-max-length": {
4747
if (!parsed.type) return undefined;
48-
const offset = raw.indexOf(parsed.type);
49-
if (offset === -1) return undefined;
48+
if (!raw.startsWith(parsed.type)) return undefined;
49+
const offset = 0;
5050
return {
5151
start: { line: 1, column: offset + 1, offset },
5252
end: {
@@ -315,8 +315,7 @@ export default async function lint(
315315
});
316316

317317
const results = (await Promise.all(pendingResults)).filter(
318-
(result): result is LintRuleOutcome =>
319-
result !== null && result.message !== undefined,
318+
(result): result is LintRuleOutcome => result !== null,
320319
);
321320

322321
const errors = results.filter(

docs/api/format.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type formatOptions = {
6464
/**
6565
* Show position indicator (~~~) for errors in the input line
6666
**/
67-
showPosition: boolean = false;
67+
showPosition?: boolean;
6868
}
6969

7070
format(report?: Report = {}, options?: formatOptions = {}) => string[];

0 commit comments

Comments
 (0)