textlint-ja / textlint-rule-no-dropping-i

い抜き言葉をチェックするtextlintルール
MIT License
8 stars 2 forks source link

kuromojiで空の検出があったときにエラー発生する #13

Closed makiRails closed 1 year ago

makiRails commented 1 year ago

表題の事象があったため、エラーの Stack trace を報告します。

Stack trace
TypeError: Reduce of empty array with no initial value
at ***.md
    at Array.reduce (<anonymous>)
    at ***/node_modules/@textlint-ja/textlint-rule-no-dropping-i/lib/no-dropping-i.js:32:16
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 2)
    at async Promise.all (index 58)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

空の配列に対して reduce を行う際は初期値を与える必要があるようです。 以下のようにしたところエラーは出なくなり、そのままローカルで使用させていただいております。

no-dropping-i.js

...
      return (0, _kuromojin.tokenize)(text).then(tokens => {
        tokens.reduce((prev, current) => {
          if (isTargetWord(prev) && isMasuWord(current)) {
            report(node, new RuleError("い抜き言葉を使用しています。", {
              index: current.word_position - 1
            }));
          }

          return current;
        }, 0);
...

恐れ入りますが入力に使ったファイルは公開できる文章ではなく、提示できません。 空の検出があること自体が想定外かどうか、根本的なところを作者の方でご判断いただければ幸いです。

azu commented 1 year ago

バグ報告ありがとうございます。

再現できるテストケースを作れてませんが、おそらく https://github.com/textlint-ja/textlint-rule-no-dropping-i/releases/tag/v2.0.1 で修正しました。

npm update @textlint-ja/textlint-rule-no-dropping-i@^2.0.1
makiRails commented 1 year ago

返信が遅くなり恐縮です。 再現環境でv2.0.1が問題なく動作することを確認しました。 ご対応いただきありがとうございます。