2
2

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/MethodDefParentheses

Last updated at Posted at 2014-07-11

RuboCop | Style/MethodDefParentheses

概要

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

メソッド宣言時の引数指定部に括弧が必要かどうかをチェックします。
デフォルトでは括弧が必要です。

設定値一覧

設定対象 設定値 内容 デフォルト
EnforcedStyle require_parentheses 括弧が必要
EnforcedStyle require_no_parentheses 括弧が不要 --

MethodDefParentheses

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

検証プログラム

non_nil_check.rb

def hoge msg
  puts msg
end

def hige(msg)
  puts msg
end

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

.rubocop.yml

MethodDefParentheses:
  EnforcedStyle: require_parentheses
$ rubocop method_def_parentheses.rb
Inspecting 1 file
C

Offenses:

method_def_parentheses.rb:1:10: C: Use def with parentheses when there are parameters.
def hoge msg
         ^^^

1 file inspected, 1 offense detected

実行結果 require_no_parentheses に設定します

.rubocop.yml

MethodDefParentheses:
  EnforcedStyle: require_no_parentheses
$ rubocop method_def_parentheses.rb
Inspecting 1 file
C

Offenses:

method_def_parentheses.rb:5:9: C: Use def without parentheses.
def hige(msg)
        ^^^^^

1 file inspected, 1 offense detected

補足

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

RuboCopまとめ記事

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?