Skip to content

Commit

Permalink
chore: update to ESM-only remark-lint@9.0.0
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ESM-only
  • Loading branch information
Trott committed Aug 15, 2021
1 parent ad89635 commit 5330580
Show file tree
Hide file tree
Showing 6 changed files with 1,308 additions and 463 deletions.
File renamed without changes.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ remark-lint plugin to prohibit specified strings in markdown files
Example configuration:

```javascript
[
require("remark-lint-prohibited-strings"),
{
"plugins": [
"remark-lint-prohibited-strings",
[
{ no: "End-Of-Life", yes: "End-of-Life" },
{ no: "End-of-life", yes: "End-of-Life" },
Expand All @@ -21,6 +22,7 @@ Example configuration:
{ no: "v8", yes: "V8" }
]
]
}
```

`no` is a string specifying the string you wish to prohibit. Regular expression
Expand Down
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'

const escapeStringRegexp = require('escape-string-regexp')
const position = require('unist-util-position')
const rule = require('unified-lint-rule')
const visit = require('unist-util-visit')
const vfileLocation = require('vfile-location')
import escapeStringRegexp from 'escape-string-regexp'
import { pointStart } from 'unist-util-position'
import { lintRule } from 'unified-lint-rule'
import { visit } from 'unist-util-visit'
import { location } from 'vfile-location'

const start = position.start
const remarkLintProhibitedStrings = lintRule('remark-lint:prohibited-strings', prohibitedStrings)

module.exports = rule('remark-lint:prohibited-strings', prohibitedStrings)
export default remarkLintProhibitedStrings

function testProhibited (val, content) {
let regexpFlags = 'g'
Expand Down Expand Up @@ -62,22 +62,22 @@ function testProhibited (val, content) {
}

function prohibitedStrings (ast, file, strings) {
const location = vfileLocation(file)
const myLocation = location(file)

visit(ast, 'text', checkText)

function checkText (node) {
const content = node.value
const initial = start(node).offset
const initial = pointStart(node).offset

strings.forEach((val) => {
const results = testProhibited(val, content)
if (results.length) {
results.forEach(({ result, index, yes }) => {
const message = val.yes ? `Use "${yes}" instead of "${result}"` : `Do not use "${result}"`
file.message(message, {
start: location.toPoint(initial + index),
end: location.toPoint(initial + index + [...result].length)
start: myLocation.toPoint(initial + index),
end: myLocation.toPoint(initial + index + [...result].length)
})
})
}
Expand Down
Loading

0 comments on commit 5330580

Please sign in to comment.