Skip to content

Commit 703b523

Browse files
authored
Merge pull request #12 from textlint-ja/fix-11
fix incorrect number in multiple lines
2 parents a78b9b5 + 624a85f commit 703b523

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/no-doubled-conjunctive-particle-ga.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export default function (context, options = {}) {
4141
separatorCharacters: separatorChars
4242
}
4343
}).children.filter(isSentenceNode);
44+
const source = new StringSource(node);
4445
return getTokenizer().then(tokenizer => {
4546
const checkSentence = (sentence) => {
46-
const source = new StringSource(sentence);
47-
const sentenceText = source.toString();
47+
const sentenceText = getSource(sentence);
4848
const tokens = tokenizer.tokenizeForSentence(sentenceText);
4949
const isConjunctiveParticleGaToken = token => {
5050
return token.pos_detail_1 === "接続助詞" && token.surface_form === "が";
@@ -54,12 +54,10 @@ export default function (context, options = {}) {
5454
return;
5555
}
5656
const current = conjunctiveParticleGaTokens[0];
57-
const originalIndex = source.originalIndexFromPosition({
58-
line: sentence.loc.start.line,
59-
column: sentence.loc.start.column + (current.word_position - 1)
60-
});
57+
const sentenceIndex = source.originalIndexFromPosition(sentence.loc.start);
58+
const currentIndex = sentenceIndex + (current.word_position - 1);
6159
report(node, new RuleError(`文中に逆接の接続助詞 "が" が二回以上使われています。`, {
62-
index: originalIndex
60+
index: currentIndex
6361
}));
6462
return current;
6563
}

test/no-doubled-conjunctive-particle-ga-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,15 @@ tester.run("no-doubled-conjunctive-particle-ga", rule, {
5959
}
6060
]
6161
},
62+
{
63+
text: "こんにちは。\n今日は早朝から出発したが、定刻には間に合わなかったが、無事会場に到着した。",
64+
errors: [
65+
{
66+
message: `文中に逆接の接続助詞 "が" が二回以上使われています。`,
67+
line: 2,
68+
column: 12
69+
}
70+
]
71+
},
6272
]
6373
});

0 commit comments

Comments
 (0)