Skip to content

Commit

Permalink
fix(rule): correct ignore implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Oct 20, 2018
1 parent f41eff3 commit 302aaaf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/textlint-rule-no-unmatched-pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ const report = context => {
sentences.children.filter(node => node.type === SentenceSyntax.Sentence).forEach(sentence => {
const source = new SourceCode(sentence.raw);
const pairMaker = new PairMaker();
const sentenceIndex = sentence.range[0];
while (source.canRead) {
pairMaker.mark(source);
// If the character is in ignored range, skip it
const characterIndex = sentenceIndex + source.index;
if (!ignoreNodeManager.isIgnoredIndex(characterIndex)) {
pairMaker.mark(source);
}
source.peek();
}
// Report Error for each existing context keys
source.contextLocations.forEach((contextLocation) => {
if (ignoreNodeManager.isIgnoredIndex(node.range[0] + contextLocation.index)) {
return;
}
report(node, new RuleError(`Not found pair character for ${contextLocation.pairMark.start}.
You should close this sentence with ${contextLocation.pairMark.end}.
Expand Down
6 changes: 5 additions & 1 deletion test/textlint-rule-no-unmatched-pair-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ tester.run("textlint-rule-no-unmatched-pair", rule, {
valid: [
"これは(秘密)です。",
`John said "Hello World!".`,
"`(` is ok.", "文字列リテラルには3種類ありますが、まずは`\"`(ダブルクオート)と`'`(シングルクオート)について見ていきます。"
"`(` is ok.", "文字列リテラルには3種類ありますが、まずは`\"`(ダブルクオート)と`'`(シングルクオート)について見ていきます。",
`a is b.
\`"\`(ダブルクオート)と\`'\`(シングルクオート)に意味的な違いはありません。
この書籍では、\`"\`(ダブルクオート)を主に文字列リテラルとして利用します。`
],
invalid: [
{
Expand Down

0 comments on commit 302aaaf

Please sign in to comment.