Skip to content

Commit

Permalink
fix: flag yes-only violations on lines other than the first line
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Jun 4, 2020
1 parent a9bdb13 commit 74101de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -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'
}

Expand All @@ -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 += `(?<!${ignoreNextTo})`
}

regexpString += `(${val.no})`
regexpString += `(${no})`

if (ignoreNextTo) {
regexpString += `(?!${ignoreNextTo})`
}

// If it ends with a letter, make sure it is a word break.
if (/\b$/.test(val.no)) {
if (/\b$/.test(no)) {
regexpString += '\\b'
}
regexpString += '(?!\\.\\w)'
Expand Down
11 changes: 11 additions & 0 deletions test.js
Expand Up @@ -314,5 +314,16 @@ test('remark-lint-prohibited-strings', (t) => {
'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()
})

0 comments on commit 74101de

Please sign in to comment.