-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: move to ESM, generated typescript types from JSDoc (#44)
* feat!: move to ESM, generated typescript types from JSDoc * types: leverage types from check-links * test: initial tests with esm implementation leverage node:test and node:assert * ci: add github actions * test: pass test suite and lint checks * docs: update badges in readme * docs: add coverage badge * build: widen version range * docs: add notes on new features to changelog * ci: upgrade covecov github action
- Loading branch information
1 parent
f86eefe
commit e6489d4
Showing
14 changed files
with
393 additions
and
6,865 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: main | ||
on: | ||
- pull_request | ||
- push | ||
jobs: | ||
main: | ||
name: ${{matrix.node}} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{matrix.node}} | ||
- run: npm install | ||
- run: npm test | ||
- uses: codecov/codecov-action@v3 | ||
strategy: | ||
matrix: | ||
node: | ||
- lts/hydrogen | ||
- node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
node_modules | ||
*.log | ||
coverage/ | ||
node_modules/ | ||
.DS_Store | ||
coverage | ||
*.d.ts | ||
*.log | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package-lock=false | ||
ignore-scripts=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
coverage/ | ||
*.md |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,49 @@ | ||
# Changelog | ||
|
||
## 2.0.0 | ||
|
||
* Migrate package to [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) | ||
* Add [TypeScript](https://www.typescriptlang.org/) typings | ||
* Support `remark` version 14 | ||
|
||
## 1.1.0 | ||
|
||
- Add `skipUrlPatterns` option. | ||
* Add `skipUrlPatterns` option. | ||
|
||
## 1.0.2 | ||
|
||
- Walk the AST fewer times. | ||
* Walk the AST fewer times. | ||
|
||
## 1.0.1 | ||
|
||
- Bump patch versions of dependencies. | ||
* Bump patch versions of dependencies. | ||
|
||
## 1.0.0 | ||
|
||
- Add `skipLocalhost` option. | ||
* Add `skipLocalhost` option. | ||
|
||
## 0.5.0 | ||
|
||
- Drop Node 6 support. | ||
- Update dependencies to remove deprecation notice about `OutgoingMessage.prototype._headers`. | ||
* Drop Node 6 support. | ||
* Update dependencies to remove deprecation notice about `OutgoingMessage.prototype._headers`. | ||
|
||
## 0.4.1 | ||
|
||
- Bump check-links dependency. | ||
* Bump check-links dependency. | ||
|
||
## 0.4.0 | ||
|
||
- Use [check-links](https://github.com/transitive-bullshit/check-links). | ||
- Replace `baseUrl` option with `gotOptions.baseUrl`. | ||
- Remove `cache` option. check-links does not expose similar cache configuration. | ||
- Drop Node 4 support. | ||
* Use [check-links](https://github.com/transitive-bullshit/check-links). | ||
* Replace `baseUrl` option with `gotOptions.baseUrl`. | ||
* Remove `cache` option. | ||
check-links does not expose similar cache configuration. | ||
* Drop Node 4 support. | ||
|
||
## 0.3.0 | ||
|
||
- Skip URLs with protocols other than `http:` and `https:`. | ||
- Handle offline smoothly and add `skipOffline` option. | ||
* Skip URLs with protocols other than `http:` and `https:`. | ||
* Handle offline smoothly and add `skipOffline` option. | ||
|
||
## 0.2.0 | ||
|
||
- Start this log. | ||
* Start this log. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,82 @@ | ||
'use strict'; | ||
import {lintRule} from 'unified-lint-rule' | ||
import {visit} from 'unist-util-visit' | ||
import checkLinks from 'check-links' | ||
import isOnline from 'is-online' | ||
|
||
const rule = require('unified-lint-rule'); | ||
const visit = require('unist-util-visit'); | ||
const checkLinks = require('check-links'); | ||
const isOnline = require('is-online'); | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast').Link} Link | ||
* @typedef {import('mdast').Image} Image | ||
* @typedef {import('mdast').Definition} Definition | ||
* | ||
* @typedef {Object} Options | ||
* @property {import('got').OptionsOfTextResponseBody} [gotOptions] | ||
* @property {boolean} [skipLocalhost] | ||
* @property {boolean} [skipOffline] | ||
* @property {Array<string | RegExp>} [skipUrlPatterns] | ||
*/ | ||
|
||
/** @type {import('unified-lint-rule').Rule<Root, Options>} */ | ||
function noDeadUrls(ast, file, options) { | ||
const urlToNodes = {}; | ||
/** @type {{[url: string]: Array<Link | Image | Definition>}} */ | ||
const urlToNodes = {} | ||
|
||
const aggregate = (node) => { | ||
const url = node.url; | ||
if (!url) return; | ||
visit(ast, ['link', 'image', 'definition'], (node) => { | ||
const url = /** @type {Link | Image | Definition} */ (node).url | ||
if ( | ||
options.skipLocalhost && | ||
/^(https?:\/\/)(localhost|127\.0\.0\.1)(:\d+)?/.test(url) | ||
) { | ||
return; | ||
return | ||
} | ||
|
||
if ( | ||
options.skipUrlPatterns && | ||
options.skipUrlPatterns.some((skipPattern) => | ||
new RegExp(skipPattern).test(url) | ||
) | ||
) { | ||
return; | ||
return | ||
} | ||
|
||
if (!urlToNodes[url]) { | ||
urlToNodes[url] = []; | ||
urlToNodes[url] = [] | ||
} | ||
|
||
urlToNodes[url].push(node); | ||
}; | ||
|
||
visit(ast, ['link', 'image', 'definition'], aggregate); | ||
urlToNodes[url].push(/** @type {Link | Image | Definition} */ (node)) | ||
}) | ||
|
||
return checkLinks(Object.keys(urlToNodes), options.gotOptions).then( | ||
(results) => { | ||
Object.keys(results).forEach((url) => { | ||
const result = results[url]; | ||
if (result.status !== 'dead') return; | ||
for (const url of Object.keys(results)) { | ||
const result = results[url] | ||
if (result.status !== 'dead') continue | ||
|
||
const nodes = urlToNodes[url]; | ||
if (!nodes) return; | ||
const nodes = urlToNodes[url] | ||
|
||
for (const node of nodes) { | ||
file.message(`Link to ${url} is dead`, node); | ||
file.message(`Link to ${url} is dead`, node) | ||
} | ||
}); | ||
} | ||
} | ||
); | ||
) | ||
} | ||
|
||
function wrapper(ast, file, options) { | ||
options = options || {}; | ||
/** @type {import('unified-lint-rule').Rule<Root, Options>} */ | ||
function wrapper(ast, file, options = {}) { | ||
return isOnline().then((online) => { | ||
if (!online) { | ||
if (!options.skipOffline) { | ||
file.message('You are not online and have not set skipOffline: true.'); | ||
file.message('You are not online and have not set skipOffline: true.') | ||
} | ||
return; | ||
|
||
return | ||
} | ||
return noDeadUrls(ast, file, options); | ||
}); | ||
|
||
return noDeadUrls(ast, file, options) | ||
}) | ||
} | ||
|
||
module.exports = rule('remark-lint:no-dead-urls', wrapper); | ||
const remarkLintNoDeadLinks = lintRule('remark-lint:no-dead-urls', wrapper) | ||
|
||
export default remarkLintNoDeadLinks |
Oops, something went wrong.