diff --git a/.mocharc.yml b/.mocharc.yml new file mode 100644 index 0000000..599a007 --- /dev/null +++ b/.mocharc.yml @@ -0,0 +1 @@ +timeout: '10000' diff --git a/src/max-ten.js b/src/max-ten.js index 49facfc..086b7fa 100644 --- a/src/max-ten.js +++ b/src/max-ten.js @@ -94,7 +94,9 @@ module.exports = function (context, options = {}) { // report if (currentTenCount > maxLen) { const positionInSentence = source.originalIndexFromIndex(lastToken.word_position - 1); - const index = sentence.range[0] + positionInSentence; + // relative index from Paragraph Node + // Sentence start(relative) + word position(relative) + const index = sentence.range[0] - node.range[0] + positionInSentence; const ruleError = new context.RuleError( `一つの文で"${touten}"を${maxLen + 1}つ以上使用しています`, { diff --git a/test/max-ten-test.js b/test/max-ten-test.js index 3102a42..fee98ec 100644 --- a/test/max-ten-test.js +++ b/test/max-ten-test.js @@ -1,3 +1,5 @@ +import fs from "fs"; +import path from "path"; import TextLintTester from "textlint-tester"; import rule from "../src/max-ten"; @@ -115,6 +117,7 @@ tester.run("max-ten", rule, { }, { text: `複数のセンテンスがある場合。これでも、columnが、ちゃんと計算、されているはず、そのためのテキストです。`, + // ^ 42 options: { max: 3 }, @@ -138,6 +141,23 @@ tester.run("max-ten", rule, { column: 39 } ] + }, + // multiple paragraph + { + // 3行目が、の問題 + text: `このパラグラフはOKです。 + +変数の名前は、半角のアルファベットであるAからZ(大文字)とaからz(小文字)、_(アンダースコア)、$(ダラー)、数字の0から9を組み合わせた名前にします。 + +3つめのパラグラフはもOKです。 + +`, + errors: [ + { + message: '一つの文で"、"を4つ以上使用しています', + line: 3 + } + ] } ] });