feat: improve errors message to distinguish between file system and fragment errors

This commit is contained in:
2023-06-27 13:15:03 +02:00
parent 6c4e8cec9c
commit a33c682974
4 changed files with 18 additions and 11 deletions

View File

@ -43,10 +43,14 @@ const customRule = {
const isRelative =
url.protocol === 'file:' && !hrefSrc.startsWith('/')
if (isRelative) {
const detail = `Link "${hrefSrc}" is not valid`
const detail = `Link "${hrefSrc}"`
if (!fs.existsSync(url)) {
addError(onError, lineNumber, detail)
addError(
onError,
lineNumber,
`${detail} should exist in the file system`
)
return
}
@ -68,7 +72,11 @@ const customRule = {
})
if (!headingsHTMLFragments.includes(url.hash)) {
addError(onError, lineNumber, detail)
addError(
onError,
lineNumber,
`${detail} should have a valid fragment`
)
}
}
}

View File

@ -41,8 +41,7 @@ const addError = (onError, lineNumber, detail, context, range, fixInfo) => {
* Converts a Markdown heading into an HTML fragment according to the rules
* used by GitHub.
*
* Taken from <https://github.com/DavidAnson/markdownlint/blob/d01180ec5a014083ee9d574b693a8d7fbc1e566d/lib/md051.js#L19>
*
* @see https://github.com/DavidAnson/markdownlint/blob/d01180ec5a014083ee9d574b693a8d7fbc1e566d/lib/md051.js#L1
* @param {string} inlineText Inline token for heading.
* @returns {string} Fragment string for heading.
*/