Sha256: 45d90d1263927efb209bdeccb9fd0fa74efebda446a8f3295971b2e21e8b849a
Contents?: true
Size: 1.45 KB
Versions: 8
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Lint # Checks for the presence of `if`, `elsif` and `unless` branches without a body. # @example # # bad # if condition # end # # # bad # unless condition # end # # # bad # if condition # do_something # elsif other_condition # end # # # good # if condition # do_something # end # # # good # unless condition # do_something # end # # # good # if condition # do_something # elsif other_condition # do_something_else # end # # @example AllowComments: true (default) # # good # if condition # do_something # elsif other_condition # # noop # end # # @example AllowComments: false # # bad # if condition # do_something # elsif other_condition # # noop # end # class EmptyConditionalBody < Base include CommentsHelp MSG = 'Avoid `%<keyword>s` branches without a body.' def on_if(node) return if node.body return if cop_config['AllowComments'] && contains_comments?(node) add_offense(node, message: format(MSG, keyword: node.keyword)) end end end end end
Version data entries
8 entries across 8 versions & 2 rubygems