Skip to content

Commit

Permalink
feat: use locator for reporting error
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jan 6, 2024
1 parent da658aa commit 9d96ae5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/no-doubled-joshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
const allow = options.allow || defaultOptions.allow;
const separatorCharacters = options.separatorCharacters || defaultOptions.separatorCharacters;
const commaCharacters = options.commaCharacters || defaultOptions.commaCharacters;
const { Syntax, report, RuleError } = context;
const { Syntax, report, RuleError, locator } = context;
const is読点Token = create読点Matcher(commaCharacters);
return {
[Syntax.Paragraph](node) {
Expand Down Expand Up @@ -301,6 +301,10 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
});
// padding positionを計算する
const originalIndex = sentenceSource.originalIndexFromIndex(current.word_position - 1);
// originalIndexがない場合は基本的にはないが、ない場合は無視する
if (originalIndex === undefined) {
return current;
}
report(
// @ts-expect-error: SentenceNodeは独自であるため
sentence,
Expand All @@ -315,7 +319,10 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
同じ助詞を連続して利用しない、文の中で順番を入れ替える、文を分割するなどを検討してください。
`,
{
index: originalIndex
padding: locator.range([
originalIndex,
originalIndex + current.surface_form.length
])
}
)
);
Expand Down
2 changes: 1 addition & 1 deletion test/no-doubled-joshi-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ tester.run("no-double-joshi", rule, {
同じ助詞を連続して利用しない、文の中で順番を入れ替える、文を分割するなどを検討してください。
`,
range: [15, 16]
range: [15, 17]
}
]
},
Expand Down

0 comments on commit 9d96ae5

Please sign in to comment.