Skip to content

Commit d2d3d20

Browse files
authored
feat: use locator for reporting error (#65)
1 parent da658aa commit d2d3d20

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/no-doubled-joshi.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
194194
const allow = options.allow || defaultOptions.allow;
195195
const separatorCharacters = options.separatorCharacters || defaultOptions.separatorCharacters;
196196
const commaCharacters = options.commaCharacters || defaultOptions.commaCharacters;
197-
const { Syntax, report, RuleError } = context;
197+
const { Syntax, report, RuleError, locator } = context;
198198
const is読点Token = create読点Matcher(commaCharacters);
199199
return {
200200
[Syntax.Paragraph](node) {
@@ -301,6 +301,10 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
301301
});
302302
// padding positionを計算する
303303
const originalIndex = sentenceSource.originalIndexFromIndex(current.word_position - 1);
304+
// originalIndexがない場合は基本的にはないが、ない場合は無視する
305+
if (originalIndex === undefined) {
306+
return current;
307+
}
304308
report(
305309
// @ts-expect-error: SentenceNodeは独自であるため
306310
sentence,
@@ -315,7 +319,10 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
315319
同じ助詞を連続して利用しない、文の中で順番を入れ替える、文を分割するなどを検討してください。
316320
`,
317321
{
318-
index: originalIndex
322+
padding: locator.range([
323+
originalIndex,
324+
originalIndex + current.surface_form.length
325+
])
319326
}
320327
)
321328
);

test/no-doubled-joshi-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ tester.run("no-double-joshi", rule, {
338338
339339
同じ助詞を連続して利用しない、文の中で順番を入れ替える、文を分割するなどを検討してください。
340340
`,
341-
range: [15, 16]
341+
range: [15, 17]
342342
}
343343
]
344344
},

0 commit comments

Comments
 (0)