Skip to content

Commit 3dbc6b2

Browse files
yuta0709azuclaude
authored
fix: prevent token mutation (#71)
* fix: prevent token mutation * fix: accept readonly array in concatJoishiTokens function Fixed TypeScript compilation error where concatJoishiTokens was expecting a mutable array but received a readonly array from the tokenize function. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: azu <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent b7bef06 commit 3dbc6b2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ 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の配列を返す
4648
* @param {Array} tokens
4749
* @returns {Array}
4850
*/
49-
export const concatJoishiTokens = (tokens: KuromojiToken[]) => {
51+
export const concatJoishiTokens = (tokens: readonly KuromojiToken[]) => {
5052
const newTokens: KuromojiToken[] = [];
5153
tokens.forEach((token) => {
5254
const prevToken = newTokens[newTokens.length - 1];

0 commit comments

Comments
 (0)