mirror of
https://github.com/theoludwig/markdownlint-rule-relative-links.git
synced 2025-05-27 11:37:24 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
c985af6156 | |||
77b8988bea | |||
b6b092dc1f | |||
56882727fc |
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
||||
lint:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.0.0'
|
||||
- uses: 'actions/checkout@v3.5.0'
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.1.0'
|
||||
uses: 'actions/setup-node@v3.6.0'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'npm'
|
||||
|
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@ -8,13 +8,13 @@ jobs:
|
||||
release:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.0.0'
|
||||
- uses: 'actions/checkout@v3.5.0'
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.1.0'
|
||||
uses: 'actions/setup-node@v3.6.0'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'npm'
|
||||
|
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
||||
test:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.0.0'
|
||||
- uses: 'actions/checkout@v3.5.0'
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.1.0'
|
||||
uses: 'actions/setup-node@v3.6.0'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'npm'
|
||||
|
31
README.md
31
README.md
@ -4,15 +4,13 @@
|
||||
<strong>Custom rule for <a href="https://github.com/DavidAnson/markdownlint">markdownlint</a> to validate relative links.</strong>
|
||||
</p>
|
||||
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="./CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" /></a>
|
||||
<a href="./LICENSE"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="Licence MIT"/></a>
|
||||
<a href="./CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" /></a>
|
||||
<br />
|
||||
<a href="https://github.com/Divlo/markdownlint-rule-relative-links/actions/workflows/lint.yml"><img src="https://github.com/Divlo/markdownlint-rule-relative-links/actions/workflows/lint.yml/badge.svg?branch=develop" /></a>
|
||||
<a href="https://github.com/Divlo/emarkdownlint-rule-relative-linksactions/workflows/test.yml"><img src="https://github.com/Divlo/markdownlint-rule-relative-links/actions/workflows/test.yml/badge.svg?branch=develop" /></a>
|
||||
<a href="https://github.com/Divlo/markdownlint-rule-relative-linksactions/workflows/test.yml"><img src="https://github.com/Divlo/markdownlint-rule-relative-links/actions/workflows/test.yml/badge.svg?branch=develop" /></a>
|
||||
<br />
|
||||
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits" /></a>
|
||||
<a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release" /></a>
|
||||
@ -23,9 +21,32 @@
|
||||
|
||||
**markdownlint-rule-relative-links** is a [markdownlint](https://github.com/DavidAnson/markdownlint) custom rule to validate relative links.
|
||||
|
||||
It ensures that relative links that start with `./` or `../` (or not starting with external protocols like `http://` or `https://`) are working and not "dead" which means that it exists in the file system of the project that uses `markdownlint`.
|
||||
It ensures that relative links (using `file:` protocol) are working and not "dead" which means that it exists in the file system of the project that uses `markdownlint`.
|
||||
|
||||
Related links:
|
||||
### Example
|
||||
|
||||
File structure:
|
||||
|
||||
```txt
|
||||
├── abc.txt
|
||||
└── awesome.md
|
||||
```
|
||||
|
||||
With `awesome.md` content:
|
||||
|
||||
```md
|
||||
[abc](./abc.txt)
|
||||
|
||||
[Dead link](./dead.txt)
|
||||
```
|
||||
|
||||
Running `markdownlint-cli2` with `markdownlint-rule-relative-links` will output:
|
||||
|
||||
```sh
|
||||
awesome.md:3 relative-links Relative links should be valid [Link "./dead.txt" is dead]
|
||||
```
|
||||
|
||||
### Related links
|
||||
|
||||
- [DavidAnson/markdownlint#253](https://github.com/DavidAnson/markdownlint/issues/253)
|
||||
- [DavidAnson/markdownlint#121](https://github.com/DavidAnson/markdownlint/issues/121)
|
||||
|
13809
package-lock.json
generated
13809
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@ -29,7 +29,7 @@
|
||||
"lint:commit": "commitlint",
|
||||
"lint:editorconfig": "editorconfig-checker",
|
||||
"lint:markdown": "markdownlint-cli2",
|
||||
"lint:eslint": "eslint \"**/*.{js,jsx,ts,tsx}\" --ignore-path \".gitignore\"",
|
||||
"lint:eslint": "eslint \".\" --ignore-path \".gitignore\"",
|
||||
"lint:prettier": "prettier \".\" --check --ignore-path \".gitignore\"",
|
||||
"lint:staged": "lint-staged",
|
||||
"test": "tap",
|
||||
@ -39,24 +39,24 @@
|
||||
"postpublish": "pinst --enable"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "17.3.0",
|
||||
"@commitlint/config-conventional": "17.3.0",
|
||||
"@types/tap": "15.0.7",
|
||||
"editorconfig-checker": "4.0.2",
|
||||
"eslint": "8.31.0",
|
||||
"eslint-config-conventions": "6.0.0",
|
||||
"eslint-config-prettier": "8.5.0",
|
||||
"eslint-plugin-import": "2.26.0",
|
||||
"@commitlint/cli": "17.5.1",
|
||||
"@commitlint/config-conventional": "17.4.4",
|
||||
"@types/tap": "15.0.8",
|
||||
"editorconfig-checker": "5.0.1",
|
||||
"eslint": "8.37.0",
|
||||
"eslint-config-conventions": "8.0.0",
|
||||
"eslint-config-prettier": "8.8.0",
|
||||
"eslint-plugin-import": "2.27.5",
|
||||
"eslint-plugin-prettier": "4.2.1",
|
||||
"eslint-plugin-promise": "6.1.1",
|
||||
"eslint-plugin-unicorn": "45.0.2",
|
||||
"husky": "8.0.2",
|
||||
"lint-staged": "13.1.0",
|
||||
"markdownlint": "0.27.0",
|
||||
"eslint-plugin-unicorn": "46.0.0",
|
||||
"husky": "8.0.3",
|
||||
"lint-staged": "13.2.0",
|
||||
"markdownlint": "0.28.0",
|
||||
"markdownlint-cli2": "0.6.0",
|
||||
"pinst": "3.0.0",
|
||||
"prettier": "2.8.1",
|
||||
"semantic-release": "19.0.5",
|
||||
"tap": "16.3.2"
|
||||
"prettier": "2.8.7",
|
||||
"semantic-release": "21.0.1",
|
||||
"tap": "16.3.4"
|
||||
}
|
||||
}
|
||||
|
14
src/index.js
14
src/index.js
@ -40,14 +40,6 @@ const addError = (onError, lineNumber, detail, context, range, fixInfo) => {
|
||||
})
|
||||
}
|
||||
|
||||
const EXTERNAL_PROTOCOLS = new Set([
|
||||
'http:',
|
||||
'https:',
|
||||
'mailto:',
|
||||
'tel:',
|
||||
'ftp:'
|
||||
])
|
||||
|
||||
const customRule = {
|
||||
names: ['relative-links'],
|
||||
description: 'Relative links should be valid',
|
||||
@ -80,10 +72,8 @@ const customRule = {
|
||||
const url = new URL(hrefSrc, pathToFileURL(params.name))
|
||||
url.hash = ''
|
||||
const isRelative =
|
||||
hrefSrc.startsWith('./') ||
|
||||
hrefSrc.startsWith('../') ||
|
||||
!EXTERNAL_PROTOCOLS.has(url.protocol)
|
||||
if (isRelative && !fs.existsSync(url.pathname)) {
|
||||
url.protocol === 'file:' && !hrefSrc.startsWith('/')
|
||||
if (isRelative && !fs.existsSync(url)) {
|
||||
const detail = `Link "${hrefSrc}" is dead`
|
||||
addError(onError, lineNumber, detail)
|
||||
}
|
||||
|
8
test/fixtures/Valid.md
vendored
8
test/fixtures/Valid.md
vendored
@ -3,3 +3,11 @@
|
||||
[basic.js](../basic.test.js)
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
[External https link](https://example.com/)
|
||||
|
||||
[External https link 2](https:./external.https)
|
||||
|
||||
[External ftp link](ftp:./external.ftp)
|
||||
|
Reference in New Issue
Block a user