5
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/VariableName

Posted at

RuboCop | Style/VariableName

概要

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

変数名をチェックします。
デフォルトはsanake caseを正とします。

設定値一覧

設定対象 設定値 内容 デフォルト
EnforcedStyle snake_case sanake caseではない場合は警告する
EnforcedStyle camelCase camel caseではない場合は警告する --

VariableName

各設定値での検証結果をまとめます。

検証プログラム

variable_name.rb

snake_case = 'snake case'
puts snake_case

camelCase = 'camelCase'
puts camelCase

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

.rubocop.yml

VariableName:
  EnforcedStyle: snake_case
$ rubocop variable_name.rb
Inspecting 1 file
C

Offenses:

variable_name.rb:4:1: C: Use snake_case for variables.
camelCase = 'camelCase'
^^^^^^^^^

1 file inspected, 1 offense detected

実行結果 camelCase に設定します

.rubocop.yml

VariableName:
  EnforcedStyle: camelCase
$ rubocop variable_name.rb
Inspecting 1 file
C

Offenses:

variable_name.rb:1:1: C: Use camelCase for variables.
snake_case = 'snake case'
^^^^^^^^^^

1 file inspected, 1 offense detected

対象コード

https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/style/variable_name.rb
https://github.com/bbatsov/rubocop/blob/master/spec/rubocop/cop/style/variable_name_spec.rb

RuboCopまとめ記事

5
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
5
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?