From f0d5329f625ab3b54a3af68c2677004631093838 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 29 Dec 2025 21:28:55 +0100 Subject: [PATCH] fix(co-authored-by-is-trailer): trailers do not have leading spaces --- lib/rules/co-authored-by-is-trailer.js | 4 ++-- test/rules/co-authored-by-is-trailer.js | 31 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/rules/co-authored-by-is-trailer.js b/lib/rules/co-authored-by-is-trailer.js index 20a34a4..6e3b2de 100644 --- a/lib/rules/co-authored-by-is-trailer.js +++ b/lib/rules/co-authored-by-is-trailer.js @@ -11,7 +11,7 @@ export default { validate: (context, rule) => { const parsed = context.toJSON() const lines = parsed.body.map((line, i) => [line, i]) - const re = /^\s*Co-authored-by:/gi + const re = /^Co-authored-by:/gi const coauthors = lines.filter(([line]) => re.test(line)) if (coauthors.length !== 0) { const firstCoauthor = coauthors[0] @@ -19,7 +19,7 @@ export default { // There must be at least one empty line, and the last empty line must be // above the first Co-authored-by line. const isTrailer = (emptyLines.length !== 0) && - emptyLines.pop()[1] < firstCoauthor[1] + emptyLines.at(-1)[1] < firstCoauthor[1] if (isTrailer) { context.report({ id, diff --git a/test/rules/co-authored-by-is-trailer.js b/test/rules/co-authored-by-is-trailer.js index c10baa0..3dc3b8d 100644 --- a/test/rules/co-authored-by-is-trailer.js +++ b/test/rules/co-authored-by-is-trailer.js @@ -56,6 +56,37 @@ test('rule: co-authored-by-is-trailer', (t) => { Rule.validate(context) }) + t.test('quoting another commit message', (tt) => { + tt.plan(4) + const v = new Validator() + const context = new Commit({ + sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea', + author: { + name: 'Foo', + email: 'foo@example.com', + date: '2016-04-12T19:42:23Z' + }, + message: 'deps: v8: cherry-pick deadbeef\n' + + '\n' + + 'Original commit message:' + + '\n' + + ' Some description.\n' + + '\n' + + ' Co-authored-by: Someone \n' + + '\n' + + 'Reviewed-By: Bar ' + }, v) + + context.report = (opts) => { + tt.pass('called report') + tt.equal(opts.id, 'co-authored-by-is-trailer', 'id') + tt.equal(opts.message, 'no Co-authored-by metadata', 'message') + tt.equal(opts.level, 'pass', 'level') + } + + Rule.validate(context) + }) + t.test('not trailer', (tt) => { tt.plan(7) const v = new Validator()