Skip to content

Commit

Permalink
Change to improve messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 25, 2023
1 parent 0a586f1 commit 323908a
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 191 deletions.
19 changes: 9 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,15 @@ function warn(landmarks, reference) {
let ruleId

if (hash) {
reason = 'Link to unknown heading'
reason = 'Cannot find heading for `#' + hash + '`'
ruleId = constants.headingRuleId

if (base && path.join(base, filePath) !== absolute) {
reason += ' in `' + filePath + '`'
ruleId = constants.headingInFileRuleId
}

reason += ': `' + hash + '`'
} else {
reason = 'Link to unknown file: `' + filePath + '`'
reason = 'Cannot find file `' + filePath + '`'
ruleId = constants.fileRuleId
}

Expand Down Expand Up @@ -569,17 +567,18 @@ function warn(landmarks, reference) {
})

if (suggestion) {
reason += '. Did you mean `' + suggestion + '`'
reason += '; did you mean `' + suggestion + '`'
}

let index = -1

while (++index < reference.nodes.length) {
const message = reference.file.message(
reason,
reference.nodes[index],
origin
)
const node = reference.nodes[index]
const message = reference.file.message(reason, {
place: node.position,
source: origin,
ruleId
})
message.url = 'https://github.com/remarkjs/remark-validate-links#readme'
}
}
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark": "^15.0.0",
"remark-cli": "^11.0.0",
"remark-cli": "^12.0.0",
"remark-preset-wooorm": "^9.0.0",
"strip-ansi": "^7.0.0",
"to-vfile": "^8.0.0",
Expand All @@ -74,7 +74,8 @@
},
"scripts": {
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . --frail --output --quiet && prettier . --log-level warn --write && xo --fix",
"#": "remark . --frail --output --quiet",
"format": "prettier . --log-level warn --write && xo --fix",
"prepack": "npm run build && npm run format",
"test": "npm run build && npm run format && npm run test-coverage",
"test-api": "node --conditions development test/index.js",
Expand Down Expand Up @@ -112,7 +113,8 @@
],
"prettier": true,
"rules": {
"unicorn/prefer-logical-operator-over-ternary": "off"
"unicorn/prefer-logical-operator-over-ternary": "off",
"unicorn/prefer-string-replace-all": "off"
}
}
}
Loading

0 comments on commit 323908a

Please sign in to comment.