Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip URLs in spell check rule #134

Merged
merged 1 commit into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions rules/spell-check.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const isUrl = require('is-url-superb');
const rule = require('unified-lint-rule');
const visit = require('unist-util-visit');
const arrify = require('arrify');
Expand All @@ -14,20 +15,29 @@ module.exports = rule('remark-lint:awesome-spell-check', (ast, file) => {
return;
}

const sanitizedSegments = [];
for (const segment of node.value.split(/\s/g)) {
if (!isUrl(segment)) {
sanitizedSegments.push(segment);
}
}

const sanitizedValue = sanitizedSegments.join(' ');

for (const rule of spellCheckRules) {
const {test, value} = rule;
const regs = arrify(test).map(reg => new RegExp(reg));

for (const re of regs) {
for (;;) {
const match = re.exec(node.value);
const match = re.exec(sanitizedValue);
if (!match) {
break;
}

if (match[0] !== value) {
const previousCharacter = node.value[match.index - 1];
const nextCharacter = node.value[match.index + match[0].length];
const previousCharacter = sanitizedValue[match.index - 1];
const nextCharacter = sanitizedValue[match.index + match[0].length];

if (wordBreakCharacterWhitelist.has(previousCharacter)) {
continue;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/spell-check/success0.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ These are special-cases which should not cause errors.
You might also like [awesome-nodejs](https://github.com/sindresorhus/awesome-nodejs).
- [awesome-github](https://github.com/phillipadsmith/awesome-github) -
[GitHub]( https://github.com) is awesome.
- [https://github.com/phillipadsmith/awesome-github](https://github.com/phillipadsmith/awesome-github) -
[GitHub]( https://github.com) is awesome.
- https://github.com/sindresorhus/awesome is meta awesome.