ruby - Rubocop guard clause dilemma -


i have piece of code:

def validate_index index   # change sizeerror   raise argumenterror, "size of index (#{index.size}) not matches"\     "size of vector (#{size})" if size != index.size end 

on this, rubocop gives offence:

style/multilineifmodifier: favor normal if-statement on modifier clause in multiline statement. 

i modified code this:

def validate_index index   # change sizeerror   if size != index.size     raise argumenterror, "size of index (#{index.size}) not matches"\       "size of vector (#{size})"   end end 

but gives offence:

style/guardclause: use guard clause instead of wrapping code inside conditional expression. 

am doing wrong or bug?

rubocop wants write this:

def validate_index index   # change sizeerror   return if size == index.size   raise argumenterror, "size of index (#{index.size}) not matches"\   "size of vector (#{size})" end 

it if want go route. either way, rubocop recommending:

def validate_index(index) 

if go original route , ignore rubocop, should consider changing if != unless:

unless size == index.size 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -