mirror of
https://github.com/theoludwig/markdownlint-rule-relative-links.git
synced 2024-11-03 18:11:31 +01:00
Théo LUDWIG
6c4e8cec9c
Similar to https://github.com/DavidAnson/markdownlint/blob/main/doc/md051.md Fixes #2 BREAKING CHANGE: Validate links fragments in relative links
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
|
|
const { markdownlint } = require('markdownlint').promises
|
|
|
|
const relativeLinks = require('../src/index.js')
|
|
|
|
test('ensure the rule validate correctly', async () => {
|
|
const lintResults = await markdownlint({
|
|
files: ['test/fixtures/Valid.md', 'test/fixtures/Invalid.md'],
|
|
config: {
|
|
default: false,
|
|
'relative-links': true
|
|
},
|
|
customRules: [relativeLinks]
|
|
})
|
|
assert.equal(lintResults['test/fixtures/Valid.md'].length, 0)
|
|
assert.equal(lintResults['test/fixtures/Invalid.md'].length, 3)
|
|
|
|
assert.equal(
|
|
lintResults['test/fixtures/Invalid.md'][0]?.ruleDescription,
|
|
'Relative links should be valid'
|
|
)
|
|
assert.equal(
|
|
lintResults['test/fixtures/Invalid.md'][0]?.errorDetail,
|
|
'Link "./basic.test.js" is not valid'
|
|
)
|
|
|
|
assert.equal(
|
|
lintResults['test/fixtures/Invalid.md'][1]?.ruleDescription,
|
|
'Relative links should be valid'
|
|
)
|
|
assert.equal(
|
|
lintResults['test/fixtures/Invalid.md'][1]?.errorDetail,
|
|
'Link "../image.png" is not valid'
|
|
)
|
|
|
|
assert.equal(
|
|
lintResults['test/fixtures/Invalid.md'][2]?.ruleDescription,
|
|
'Relative links should be valid'
|
|
)
|
|
assert.equal(
|
|
lintResults['test/fixtures/Invalid.md'][2]?.errorDetail,
|
|
'Link "./Valid.md#not-existing-heading" is not valid'
|
|
)
|
|
})
|