LoginSignup
6
6

More than 5 years have passed since last update.

RuboCop | Style/NumericLiterals

Last updated at Posted at 2014-07-14

RuboCop | Style/NumericLiterals

概要

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

数値リテラルを3ケタ区切りで _ で区切っているかどうかチェックする。
デフォルトは5ケタ以上の場合にチェックする。

NumericLiterals

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

検証プログラム

numeric_literals.rb
print 1234
print 12345
print 123456

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

.rubocop.yml
NumericLiterals:
  MinDigits: 5
$ rubocop numeric_literals.rb
Inspecting 1 file
C

Offenses:

numeric_literals.rb:2:7: C: Separate every 3 digits in the integer portion of a number with underscores(_).
print 12345
      ^^^^^
numeric_literals.rb:3:7: C: Separate every 3 digits in the integer portion of a number with underscores(_).
print 123456
      ^^^^^^

1 file inspected, 2 offenses detected

実行結果 6桁 に設定します

.rubocop.yml
NumericLiterals:
  MinDigits: 6
$ rubocop numeric_literals.rb
Inspecting 1 file
C

Offenses:

numeric_literals.rb:3:7: C: Separate every 3 digits in the integer portion of a number with underscores(_).
print 123456
      ^^^^^^

1 file inspected, 1 offense detected

補足

この警告は rubocop -a で修正可能です。

RuboCopまとめ記事

6
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
6
6