Skip to content

Commit 958a006

Browse files
committed
fix: prevent token mutation
1 parent b7bef06 commit 958a006

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/no-doubled-joshi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
275275
}
276276
// strict mode ではない時例外を除去する
277277
if (!isStrict) {
278-
if (matchExceptionRule(joshiTokenSurfaceTokens, tokens)) {
278+
if (matchExceptionRule(joshiTokenSurfaceTokens, concatedJoshiTokens)) {
279279
return;
280280
}
281281
}
@@ -292,11 +292,11 @@ const report: TextlintRuleModule<Options> = function (context, options = {}) {
292292
if (differenceIndex <= minInterval) {
293293
// 連続する助詞を集める
294294
const startWord = toTextWithPrevWord(prev, {
295-
tokens: tokens,
295+
tokens: concatedJoshiTokens,
296296
sentence: sentence
297297
});
298298
const endWord = toTextWithPrevWord(current, {
299-
tokens: tokens,
299+
tokens: concatedJoshiTokens,
300300
sentence: sentence
301301
});
302302
// padding positionを計算する

src/token-utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ export const create読点Matcher = (commaCharacters: string[]) => {
3636
* @returns {Object}
3737
*/
3838
const concatToken = (aToken: KuromojiToken, bToken: KuromojiToken) => {
39-
aToken.surface_form += bToken.surface_form;
40-
aToken.pos += bToken.pos;
41-
aToken.pos_detail_1 += bToken.surface_form;
42-
return aToken;
39+
return {
40+
...aToken,
41+
surface_form: aToken.surface_form + bToken.surface_form,
42+
pos: aToken.pos + bToken.pos,
43+
pos_detail_1: aToken.pos_detail_1 + bToken.surface_form
44+
};
4345
};
4446
/**
4547
* 助詞+助詞 というように連続しているtokenを結合し直したtokenの配列を返す

0 commit comments

Comments
 (0)