7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RuboCop | Style/WordArray

Last updated at Posted at 2014-08-05

RuboCop | Style/WordArray

概要

RuboCopの「Style/WordArray」警告について。

文字列配列を %w / %W 記法で記述しているかどうかチェックする。
デフォルトでは、文字列の配列の場合はすべて %w / %W 記法 で記述する必要がある。

MinSize を設定することで、任意のサイズまでブラケットによる配列の記法も許容される。

WordArray

検証プログラム

word_array.rb
print ['hoge', 'hige', 'hage']
print ['hoge', 'hige', 'hage', 'hege']

実行結果 デフォルト の場合

.rubocop.yml
WordArray:
  MinSize: 0
$ rubocop word_array.rb
Inspecting 1 file
C

Offenses:

word_array.rb:1:7: C: Use %w or %W for array of words.
print ['hoge', 'hige', 'hage']
      ^^^^^^^^^^^^^^^^^^^^^^^^
word_array.rb:2:7: C: Use %w or %W for array of words.
print ['hoge', 'hige', 'hage', 'hege']
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 2 offenses detected

実行結果 MinSize を 3 にした場合

.rubocop.yml
WordArray:
  MinSize: 3
$ rubocop word_array.rb
Inspecting 1 file
C

Offenses:

word_array.rb:2:7: C: Use %w or %W for array of words.
print ['hoge', 'hige', 'hage', 'hege']
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

対象コード

https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/style/word_array.rb
https://github.com/bbatsov/rubocop/blob/master/spec/rubocop/cop/style/word_array_spec.rb

RuboCopまとめ記事

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?