From 74101de6e9aa8342d8d4eef774a183a7fe292822 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 3 Jun 2020 21:35:18 -0700 Subject: [PATCH] fix: flag yes-only violations on lines other than the first line Refs: https://github.com/nodejs/node/pull/33691 --- index.js | 11 ++++++----- test.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2a8c420..0644864 100644 --- a/index.js +++ b/index.js @@ -12,9 +12,10 @@ module.exports = rule('remark-lint:prohibited-strings', prohibitedStrings) function testProhibited (val, content) { let regexpFlags = 'g' + let no = val.no - if (!val.no) { - val.no = escapeStringRegexp(val.yes) + if (!no) { + no = escapeStringRegexp(val.yes) regexpFlags += 'i' } @@ -23,21 +24,21 @@ function testProhibited (val, content) { const ignoreNextTo = val.ignoreNextTo ? escapeStringRegexp(val.ignoreNextTo) : '' // If it starts with a letter, make sure it is a word break. - if (/^\b/.test(val.no)) { + if (/^\b/.test(no)) { regexpString += '\\b' } if (ignoreNextTo) { regexpString += `(? { 'should escape regexp special chars with `yes` option but no `no` option' ) } + + { + const contents = 'Fhqwhgads\n\nType: End-of-life' + t.deepEqual( + processorWithOptions([{ yes: 'End-of-Life' }]) + .processSync(vfile({ path: path, contents: contents })) + .messages.map(String), + ['fhqwhgads.md:3:7-3:18: Use "End-of-Life" instead of "End-of-life"'], + 'should flag yes-only violations on lines other than the first line' + ) + } t.end() })