Skip to content

Commit 6fab9ba

Browse files
committed
fix: fix wrong position report
1 parent 22dc880 commit 6fab9ba

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

.mocharc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
timeout: '10000'

src/max-ten.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ module.exports = function (context, options = {}) {
9494
// report
9595
if (currentTenCount > maxLen) {
9696
const positionInSentence = source.originalIndexFromIndex(lastToken.word_position - 1);
97-
const index = sentence.range[0] + positionInSentence;
97+
// relative index from Paragraph Node
98+
// Sentence start(relative) + word position(relative)
99+
const index = sentence.range[0] - node.range[0] + positionInSentence;
98100
const ruleError = new context.RuleError(
99101
`一つの文で"${touten}"を${maxLen + 1}つ以上使用しています`,
100102
{

test/max-ten-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import fs from "fs";
2+
import path from "path";
13
import TextLintTester from "textlint-tester";
24
import rule from "../src/max-ten";
35

@@ -115,6 +117,7 @@ tester.run("max-ten", rule, {
115117
},
116118
{
117119
text: `複数のセンテンスがある場合。これでも、columnが、ちゃんと計算、されているはず、そのためのテキストです。`,
120+
// ^ 42
118121
options: {
119122
max: 3
120123
},
@@ -138,6 +141,23 @@ tester.run("max-ten", rule, {
138141
column: 39
139142
}
140143
]
144+
},
145+
// multiple paragraph
146+
{
147+
// 3行目が、の問題
148+
text: `このパラグラフはOKです。
149+
150+
変数の名前は、半角のアルファベットであるAからZ(大文字)とaからz(小文字)、_(アンダースコア)、$(ダラー)、数字の0から9を組み合わせた名前にします。
151+
152+
3つめのパラグラフはもOKです。
153+
154+
`,
155+
errors: [
156+
{
157+
message: '一つの文で"、"を4つ以上使用しています',
158+
line: 3
159+
}
160+
]
141161
}
142162
]
143163
});

0 commit comments

Comments
 (0)