Skip to content

Commit

Permalink
Use ruleId to differentiate between messages
Browse files Browse the repository at this point in the history
Closes GH-13.
  • Loading branch information
wooorm committed Aug 22, 2017
1 parent b1c646b commit fa88c60
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 129 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module.exports = attacher;
var referenceId = 'remarkValidateLinksReferences';
var landmarkId = 'remarkValidateLinksLandmarks';
var sourceId = 'remark-validate-links';
var headingRuleId = 'missing-heading';
var headingInFileRuleId = 'missing-heading-in-file';
var fileRuleId = 'missing-file';

cliCompleter.pluginId = sourceId;

Expand Down Expand Up @@ -189,6 +192,7 @@ function validate(exposed, file) {
var pathname;
var warning;
var suggestion;
var ruleId;

for (reference in references) {
nodes = references[reference];
Expand All @@ -209,14 +213,17 @@ function validate(exposed, file) {
if (hash) {
pathname = getPathname(reference);
warning = 'Link to unknown heading';
ruleId = headingRuleId;

if (pathname !== filePath) {
warning += ' in `' + pathname + '`';
ruleId = headingInFileRuleId;
}

warning += ': `' + hash + '`';
} else {
warning = 'Link to unknown file: `' + reference + '`';
ruleId = fileRuleId;
}

suggestion = getClosest(reference, exposed);
Expand All @@ -225,7 +232,7 @@ function validate(exposed, file) {
warning += '. Did you mean `' + suggestion + '`';
}

warnAll(file, nodes, warning);
warnAll(file, nodes, warning, ruleId);
}
}
}
Expand Down Expand Up @@ -346,13 +353,13 @@ function gatherReferences(file, tree, info, fileSet) {

/* Utilitity to warn `reason` for each node in `nodes`,
* on `file`. */
function warnAll(file, nodes, reason) {
function warnAll(file, nodes, reason, ruleId) {
nodes.forEach(one);

function one(node) {
var message = file.message(reason, node);
message.source = sourceId;
message.ruleId = sourceId;
message.ruleId = ruleId;
}
}

Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Now, running `remark -u validate-links .` yields:

```text
example.md
3:11-3:48 warning Link to unknown heading: `world` remark-validate-links remark-validate-links
5:27-5:51 warning Link to unknown heading in `readme.md`: `foo` remark-validate-links remark-validate-links
3:11-3:48 warning Link to unknown heading: `world` missing-heading remark-validate-links
5:27-5:51 warning Link to unknown heading in `readme.md`: `foo` missing-heading-in-file remark-validate-links
readme.md: no issues found
Expand Down Expand Up @@ -121,7 +121,7 @@ remark --use 'validate-links=repository:"foo/bar"' example.md
```

When a repository is given or detected (supporting GitHub, GitLab, and
Bitbucket), links to the only files are normalized to the file-system.
Bitbucket), links to the files are normalized to the file-system.
For example, `https://github.com/foo/bar/blob/master/example.md` becomes
`example.md`.

Expand Down
Loading

0 comments on commit fa88c60

Please sign in to comment.