Skip to content

Commit 302aaaf

Browse files
committed
fix(rule): correct ignore implementation
1 parent f41eff3 commit 302aaaf

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ const report = context => {
2222
sentences.children.filter(node => node.type === SentenceSyntax.Sentence).forEach(sentence => {
2323
const source = new SourceCode(sentence.raw);
2424
const pairMaker = new PairMaker();
25+
const sentenceIndex = sentence.range[0];
2526
while (source.canRead) {
26-
pairMaker.mark(source);
27+
// If the character is in ignored range, skip it
28+
const characterIndex = sentenceIndex + source.index;
29+
if (!ignoreNodeManager.isIgnoredIndex(characterIndex)) {
30+
pairMaker.mark(source);
31+
}
2732
source.peek();
2833
}
2934
// Report Error for each existing context keys
3035
source.contextLocations.forEach((contextLocation) => {
31-
if (ignoreNodeManager.isIgnoredIndex(node.range[0] + contextLocation.index)) {
32-
return;
33-
}
3436
report(node, new RuleError(`Not found pair character for ${contextLocation.pairMark.start}.
3537
3638
You should close this sentence with ${contextLocation.pairMark.end}.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ tester.run("textlint-rule-no-unmatched-pair", rule, {
99
valid: [
1010
"これは(秘密)です。",
1111
`John said "Hello World!".`,
12-
"`(` is ok.", "文字列リテラルには3種類ありますが、まずは`\"`(ダブルクオート)と`'`(シングルクオート)について見ていきます。"
12+
"`(` is ok.", "文字列リテラルには3種類ありますが、まずは`\"`(ダブルクオート)と`'`(シングルクオート)について見ていきます。",
13+
`a is b.
14+
15+
\`"\`(ダブルクオート)と\`'\`(シングルクオート)に意味的な違いはありません。
16+
この書籍では、\`"\`(ダブルクオート)を主に文字列リテラルとして利用します。`
1317
],
1418
invalid: [
1519
{

0 commit comments

Comments
 (0)