Skip to content

Commit 8641f55

Browse files
authored
fix: reporter use index instead of line and column (#12)
1 parent 7a30b30 commit 8641f55

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/no-doubled-joshi.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const defaultOptions = {
6262
6363
TODO: need abstraction
6464
*/
65-
export default function (context, options = {}) {
65+
export default function(context, options = {}) {
6666
const helper = new RuleHelper(context);
6767
// 最低間隔値
6868
const minInterval = options.min_interval || defaultOptions.min_interval;
@@ -128,16 +128,13 @@ export default function (context, options = {}) {
128128
// 助詞token同士の距離が設定値以下ならエラーを報告する
129129
const differenceIndex = otherPosition - startPosition;
130130
if (differenceIndex <= minInterval) {
131-
const originalPosition = source.originalPositionFor({
131+
const originalIndex = source.originalIndexFromPosition({
132132
line: sentence.loc.start.line,
133133
column: sentence.loc.start.column + (current.word_position - 1)
134134
});
135135
// padding positionを計算する
136136
const padding = {
137-
line: originalPosition.line - 1,
138-
// matchLastToken.word_position start with 1
139-
// this is padding column start with 0 (== -1)
140-
column: originalPosition.column
137+
index: originalIndex
141138
};
142139
report(node, new RuleError(`一文に二回以上利用されている助詞 "${joshiName}" がみつかりました。`, padding));
143140
}

test/no-doubled-joshi-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ tester.run("no-double-joshi", rule, {
143143
column: 6
144144
}
145145
]
146+
},{
147+
text: `この行にはtextlintによる警告は出ない。
148+
この行にはtextlintにより警告が発せられる。この行に何かしようとすると起きるという
149+
この行にはtextlintによる警告は出ない。
150+
`,
151+
ext: ".txt",
152+
errors: [
153+
{
154+
message: `一文に二回以上利用されている助詞 "と" がみつかりました。`,
155+
line: 2,
156+
column: 38
157+
}
158+
]
146159
}
147160
]
148161
});

0 commit comments

Comments
 (0)