From f8902c011ed1ab1fcedd1cd10cdffb7ea7827dc7 Mon Sep 17 00:00:00 2001
From: Anna Henningsen <anna@addaleax.net>
Date: Sat, 13 Oct 2018 11:47:54 -0700
Subject: [PATCH 1/3] rules: skip line-length rule for URLs and quoted lines

---
 lib/rules/line-length.js  |  6 ++++
 test/rules/line-length.js | 64 +++++++++++++++++++++++++++++++++++++++
 test/validator.js         |  4 +--
 3 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/lib/rules/line-length.js b/lib/rules/line-length.js
index 4e32f5b..cfbb735 100644
--- a/lib/rules/line-length.js
+++ b/lib/rules/line-length.js
@@ -31,6 +31,12 @@ module.exports = {
     var failed = false
     for (let i = 0; i < parsed.body.length; i++) {
       const line = parsed.body[i]
+      // Skip quoted lines, e.g. for riginal commit messages of V8 backports.
+      if (line.startsWith('  '))
+        continue
+      // Skip lines with URLs.
+      if (line.match(/https?:\/\//))
+        continue
       if (line.length > len) {
         failed = true
         context.report({
diff --git a/test/rules/line-length.js b/test/rules/line-length.js
index 115a78a..9c5fac0 100644
--- a/test/rules/line-length.js
+++ b/test/rules/line-length.js
@@ -67,5 +67,69 @@ ${'aaa'.repeat(30)}`
     tt.end()
   })
 
+  t.test('quoted lines', (tt) => {
+    const v = new Validator()
+    const context = new Commit({
+      sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
+    , author: {
+        name: 'Evan Lucas'
+      , email: 'evanlucas@me.com'
+      , date: '2016-04-12T19:42:23Z'
+      }
+    , message: `src: make foo mor foo-ey
+
+Here’s the original code:
+
+    ${'aaa'.repeat(30)}
+
+That was the original code.
+`
+    }, v)
+
+    context.report = (opts) => {
+      tt.pass('called report')
+      tt.equal(opts.id, 'line-length', 'id')
+      tt.equal(opts.string, '', 'string')
+      tt.equal(opts.level, 'pass', 'level')
+    }
+
+    Rule.validate(context, {
+      options: {
+        length: 72
+      }
+    })
+    tt.end()
+  })
+
+  t.test('URLs', (tt) => {
+    const v = new Validator()
+    const context = new Commit({
+      sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
+    , author: {
+        name: 'Evan Lucas'
+      , email: 'evanlucas@me.com'
+      , date: '2016-04-12T19:42:23Z'
+      }
+    , message: `src: make foo mor foo-ey
+
+https://${'very-'.repeat(80)}-long-url.org/
+`
+    }, v)
+
+    context.report = (opts) => {
+      tt.pass('called report')
+      tt.equal(opts.id, 'line-length', 'id')
+      tt.equal(opts.string, '', 'string')
+      tt.equal(opts.level, 'pass', 'level')
+    }
+
+    Rule.validate(context, {
+      options: {
+        length: 72
+      }
+    })
+    tt.end()
+  })
+
   t.end()
 })
diff --git a/test/validator.js b/test/validator.js
index df2e80e..b126bd9 100644
--- a/test/validator.js
+++ b/test/validator.js
@@ -205,11 +205,11 @@ test('Validator - real commits', (t) => {
       const filtered = msgs.filter((item) => {
         return item.level === 'fail'
       })
-      tt.equal(filtered.length, 3, 'messages.length')
+      tt.equal(filtered.length, 2, 'messages.length')
       const ids = filtered.map((item) => {
         return item.id
       })
-      const exp = ['line-length', 'line-length', 'title-length']
+      const exp = ['line-length', 'title-length']
       tt.deepEqual(ids.sort(), exp.sort(), 'message ids')
       tt.end()
     })

From 9a11858e6b07298f3e745e5980561e9a272b7aab Mon Sep 17 00:00:00 2001
From: Anna Henningsen <anna@addaleax.net>
Date: Sat, 13 Oct 2018 12:42:10 -0700
Subject: [PATCH 2/3] fixup! rules: skip line-length rule for URLs and quoted
 lines

---
 lib/rules/line-length.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/rules/line-length.js b/lib/rules/line-length.js
index cfbb735..349be4d 100644
--- a/lib/rules/line-length.js
+++ b/lib/rules/line-length.js
@@ -31,7 +31,7 @@ module.exports = {
     var failed = false
     for (let i = 0; i < parsed.body.length; i++) {
       const line = parsed.body[i]
-      // Skip quoted lines, e.g. for riginal commit messages of V8 backports.
+      // Skip quoted lines, e.g. for original commit messages of V8 backports.
       if (line.startsWith('  '))
         continue
       // Skip lines with URLs.

From 6d112586244641d4c3de60c862cc6cc4327f0c39 Mon Sep 17 00:00:00 2001
From: Anna Henningsen <anna@addaleax.net>
Date: Wed, 17 Oct 2018 08:11:46 +0200
Subject: [PATCH 3/3] squash! fixup! rules: skip line-length rule for URLs and
 quoted lines

---
 lib/rules/line-length.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/rules/line-length.js b/lib/rules/line-length.js
index 349be4d..2e19857 100644
--- a/lib/rules/line-length.js
+++ b/lib/rules/line-length.js
@@ -32,10 +32,10 @@ module.exports = {
     for (let i = 0; i < parsed.body.length; i++) {
       const line = parsed.body[i]
       // Skip quoted lines, e.g. for original commit messages of V8 backports.
-      if (line.startsWith('  '))
+      if (line.startsWith('    '))
         continue
       // Skip lines with URLs.
-      if (line.match(/https?:\/\//))
+      if (/https?:\/\//.test(line))
         continue
       if (line.length > len) {
         failed = true