NOTE

This was a feature for πŸ§‘β€πŸ’»οΈ My Custom VSCode Extension, but it was replaced by πŸ”» Markdown Linting instead.

This feature was discontinued because the Markdownlint extension validates this automatically.

Feature description

Perhaps I’m a bit of a perfectionist, but one thing I hate is having unused information in a file. An example is Markdown links that aren’t in use (this, of course, is related to the fact that the links themselves are defined at the end of the file using [some-text][x] (...) [x]: some-url).

VSCode can easily listen to each time a file is saved using:

vscode.workspace.onDidSaveTextDocument((document) => {
    (...)
})

The code to find the defined links and the used links are:

const definedLinks = lib.regexMatch(/^\[(\d*)\]: (.*)$/gm, document.getText())
const usedLinks = lib.regexMatch(/\[.*?\]\[(\d*)\]/gms, document.getText())

For the used links it is very important to add gms instead of just gm because the text can span multiple lines.