Skip to content

Commit 36ee575

Browse files
committed
fix(rule): ignore Code node
1 parent fa46b84 commit 36ee575

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
]
5959
},
6060
"dependencies": {
61-
"sentence-splitter": "^3.0.11"
61+
"sentence-splitter": "^3.0.11",
62+
"textlint-rule-helper": "^2.0.0"
6263
}
6364
}

src/textlint-rule-no-unmatched-pair.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter";
33
import { PairMaker } from "./parser/PairMaker.js";
44
import { SourceCode } from "./parser/SourceCode.js";
5+
import { IgnoreNodeManager } from "textlint-rule-helper";
56

67
const report = context => {
78
const { Syntax, report, RuleError } = context;
9+
const ignoreNodeManager = new IgnoreNodeManager();
810
return {
911
[Syntax.Paragraph](node) {
1012
const sentences = splitAST(node);
13+
ignoreNodeManager.ignoreChildrenByTypes(node, [Syntax.Code]);
1114
sentences.children.filter(node => node.type === SentenceSyntax.Sentence).forEach(sentence => {
1215
const source = new SourceCode(sentence.raw);
1316
const pairMaker = new PairMaker();
@@ -17,16 +20,16 @@ const report = context => {
1720
}
1821
// Report Error for each existing context keys
1922
source.contextLocations.forEach((contextLocation) => {
23+
if (ignoreNodeManager.isIgnoredIndex(node.range[0] + contextLocation.index)) {
24+
return;
25+
}
2026
report(node, new RuleError(`Not found pair character for ${contextLocation.pairMark.start}.
2127
2228
You should close this sentence with ${contextLocation.pairMark.end}.
2329
This pair mark is called ${contextLocation.pairMark.key}.`, {
2430
index: contextLocation.index
2531
}));
2632
});
27-
if (source.contextLocations.length > 0) {
28-
29-
}
3033
});
3134
}
3235
};

test/textlint-rule-no-unmatched-pair-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ tester.run("textlint-rule-no-unmatched-pair", rule, {
1212
},
1313
{
1414
text: `John said "Hello World!".`
15+
},
16+
17+
{
18+
text: "`(` is ok."
1519
}
1620
],
1721
invalid: [

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,6 +3180,12 @@ text-table@^0.2.0:
31803180
version "0.2.0"
31813181
resolved "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
31823182

3183+
textlint-rule-helper@^2.0.0:
3184+
version "2.0.0"
3185+
resolved "https://registry.npmjs.org/textlint-rule-helper/-/textlint-rule-helper-2.0.0.tgz#95cb4696c95c4258d2e3389e9e64b849f9721382"
3186+
dependencies:
3187+
unist-util-visit "^1.1.0"
3188+
31833189
textlint-scripts@^2.1.0:
31843190
version "2.1.0"
31853191
resolved "https://registry.npmjs.org/textlint-scripts/-/textlint-scripts-2.1.0.tgz#7fb05b87bba40b8c94d7500c043930b91f413e11"

0 commit comments

Comments
 (0)