Skip to content

Commit

Permalink
fix: fix wrong position report
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Apr 25, 2021
1 parent 22dc880 commit 6fab9ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
timeout: '10000'
4 changes: 3 additions & 1 deletion src/max-ten.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}つ以上使用しています`,
{
Expand Down
20 changes: 20 additions & 0 deletions test/max-ten-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from "fs";
import path from "path";
import TextLintTester from "textlint-tester";
import rule from "../src/max-ten";

Expand Down Expand Up @@ -115,6 +117,7 @@ tester.run("max-ten", rule, {
},
{
text: `複数のセンテンスがある場合。これでも、columnが、ちゃんと計算、されているはず、そのためのテキストです。`,
// ^ 42
options: {
max: 3
},
Expand All @@ -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
}
]
}
]
});

0 comments on commit 6fab9ba

Please sign in to comment.