Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()
})