Fix an error for Naming/InclusiveLanguage string with invalid byte sequence in UTF-8

このエントリーをはてなブックマークに追加

Fix an error for Naming/InclusiveLanguage string with invalid byte sequence in UTF-8
https://github.com/rubocop/rubocop/pull/10610

以下の対応をしているときに見つけた問題を対処した。

Tweak uniformity of expression was implemented
https://github.com/rubocop/rubocop/pull/10602

Naming/InclusiveLanguageは設定でCheckStrings: trueの場合には String も指摘の対象となる。
そこで UTF-8 として不正なバイト列を持つ文字列がいくつかテストコードに存在していて。それを解析しようとするとエラーが発生する問題があったので修正した。

実際、rubocop/rubocop 自身のコードでも以下のようにエラーが発生していた。

rubocop.yml

Naming/InclusiveLanguage:
+  CheckStrings: true
  FlaggedTerms:
    behaviour:
      Suggestions:
        - behavior
    offence:
      Suggestions:
        - offense
  Exclude:
    - lib/rubocop/cop/naming/inclusive_language.rb

command

bundle exec rubocop --only Naming/InclusiveLanguage

result

6 errors occurred:
An error occurred while Naming/InclusiveLanguage cop was inspecting /Users/ydah/rubocop/spec/rubocop/cop/layout/end_of_line_spec.rb.
An error occurred while Naming/InclusiveLanguage cop was inspecting /Users/ydah/rubocop/spec/rubocop/cop/lint/percent_string_array_spec.rb.
An error occurred while Naming/InclusiveLanguage cop was inspecting /Users/ydah/rubocop/spec/rubocop/cop/lint/percent_symbol_array_spec.rb.
An error occurred while Naming/InclusiveLanguage cop was inspecting /Users/ydah/rubocop/spec/rubocop/cop/lint/syntax_spec.rb.
An error occurred while Naming/InclusiveLanguage cop was inspecting /Users/ydah/rubocop/spec/rubocop/path_util_spec.rb.
An error occurred while Naming/InclusiveLanguage cop was inspecting /Users/ydah/rubocop/spec/rubocop/result_cache_spec.rb.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.29.0 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 3.1.0 x86_64-darwin21)