LoginSignup
5
6

More than 5 years have passed since last update.

RuboCop | Style/FileName

Posted at

RuboCop | Style/FileName

概要

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

Rubyのファイル名が snake_case になっているかチェックします。
Excludeによって除外対象を設定可能です。

デフォルト除外一覧

  • Rakefile
  • Gemfile
  • Capfile

FileName

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

検証プログラム

snake_case.rb

print 'snake_case'

CamelCase.rb

print 'CamelCase'

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

.rubocop.yml

※明示的に設定しているが、デフォルト値なので何も設定しなくてもよい

FileName:
  Exclude:
    - '**/Rakefile'
    - '**/Gemfile'
    - '**/Capfile'
$ rubocop snake_case.rb CamelCase.rb
Inspecting 2 files
.C

Offenses:

CamelCase.rb:2:1: C: Use snake_case for source file names.

2 files inspected, 1 offense detected

実行結果 ExcludeCamelCase.rb を追加

.rubocop.yml

FileName:
  Exclude:
    - '**/Rakefile'
    - '**/Gemfile'
    - '**/Capfile'
    - '**/CamelCase.rb'
$ rubocop snake_case.rb CamelCase.rb
Inspecting 2 files
..

2 files inspected, no offenses detected
5
6
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
6