From 958a00608023e34ba865d349d3d319f77d81e262 Mon Sep 17 00:00:00 2001 From: yuta0709 Date: Fri, 5 Sep 2025 14:23:56 +0900 Subject: [PATCH 1/2] fix: prevent token mutation --- src/no-doubled-joshi.ts | 6 +++--- src/token-utils.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/no-doubled-joshi.ts b/src/no-doubled-joshi.ts index 39bb050..6612cdb 100644 --- a/src/no-doubled-joshi.ts +++ b/src/no-doubled-joshi.ts @@ -275,7 +275,7 @@ const report: TextlintRuleModule = function (context, options = {}) { } // strict mode ではない時例外を除去する if (!isStrict) { - if (matchExceptionRule(joshiTokenSurfaceTokens, tokens)) { + if (matchExceptionRule(joshiTokenSurfaceTokens, concatedJoshiTokens)) { return; } } @@ -292,11 +292,11 @@ const report: TextlintRuleModule = function (context, options = {}) { if (differenceIndex <= minInterval) { // 連続する助詞を集める const startWord = toTextWithPrevWord(prev, { - tokens: tokens, + tokens: concatedJoshiTokens, sentence: sentence }); const endWord = toTextWithPrevWord(current, { - tokens: tokens, + tokens: concatedJoshiTokens, sentence: sentence }); // padding positionを計算する diff --git a/src/token-utils.ts b/src/token-utils.ts index 1db70c4..decf2e5 100644 --- a/src/token-utils.ts +++ b/src/token-utils.ts @@ -36,10 +36,12 @@ export const create読点Matcher = (commaCharacters: string[]) => { * @returns {Object} */ const concatToken = (aToken: KuromojiToken, bToken: KuromojiToken) => { - aToken.surface_form += bToken.surface_form; - aToken.pos += bToken.pos; - aToken.pos_detail_1 += bToken.surface_form; - return aToken; + return { + ...aToken, + surface_form: aToken.surface_form + bToken.surface_form, + pos: aToken.pos + bToken.pos, + pos_detail_1: aToken.pos_detail_1 + bToken.surface_form + }; }; /** * 助詞+助詞 というように連続しているtokenを結合し直したtokenの配列を返す From 7bd8254467fa6bcd6507596c2df0ca5a661963e9 Mon Sep 17 00:00:00 2001 From: azu Date: Fri, 5 Sep 2025 23:20:11 +0900 Subject: [PATCH 2/2] fix: accept readonly array in concatJoishiTokens function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/token-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/token-utils.ts b/src/token-utils.ts index decf2e5..5cbe1cc 100644 --- a/src/token-utils.ts +++ b/src/token-utils.ts @@ -48,7 +48,7 @@ const concatToken = (aToken: KuromojiToken, bToken: KuromojiToken) => { * @param {Array} tokens * @returns {Array} */ -export const concatJoishiTokens = (tokens: KuromojiToken[]) => { +export const concatJoishiTokens = (tokens: readonly KuromojiToken[]) => { const newTokens: KuromojiToken[] = []; tokens.forEach((token) => { const prevToken = newTokens[newTokens.length - 1];