Skip to content

Conversation

@yuta0709
Copy link
Contributor

@yuta0709 yuta0709 commented Sep 5, 2025

概要

concatToken が引数として渡された元トークンを変更せずに処理するよう修正しました。

背景

kuromojin は同一テキストに対してトークンをキャッシュします。そのため、リントを複数回実行すると、キャッシュされたトークンが書き換えられ、同一の入力に対して実行するたびにエラー範囲やメッセージが変化してしまう不具合がありました。
こちらが不具合の再現のリポジトリです。

変更点

token-utils.ts

  • concatToken で引数のオブジェクトを書き換えず、新しいオブジェクトを返すようにしました。

no-doubled-joshi.ts

  • matchExceptionRuletoTextWithPrevWord に渡す配列を concatedJoshiTokens に変更
    • トークンが書き換えられる前提でindexOfが使われている場所があったため、concatTokenが新しいオブジェクトを返しても正しく動作するように変更しました。

補足

↓のように、モジュールとしてtextlintを使用した際に起こる不具合の修正です。
https://textlint.org/docs/use-as-modules#overview

@azu azu added the Type: Refactoring A code change that neither fixes a bug nor adds a feature label Sep 5, 2025
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]>
@azu azu merged commit 3dbc6b2 into textlint-ja:master Sep 5, 2025
2 checks passed
@azu
Copy link
Member

azu commented Sep 5, 2025

Thanks

@github-actions github-actions bot mentioned this pull request Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Refactoring A code change that neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants