Sha256: 94763db19cfc57c124529a2d76659149b0bae3015d27e2b1e361751bb62f5c31
Contents?: true
Size: 690 Bytes
Versions: 6
Compression:
Stored size: 690 Bytes
Contents
# encoding: utf-8 module RuboCop module Cop module Style # TODO: Make configurable. # Checks for uses of if/then/else/end on a single line. class OneLineConditional < Cop include OnNormalIfUnless MSG = 'Favor the ternary operator (`?:`) ' \ 'over `%s/then/else/end` constructs.' def on_normal_if_unless(node) exp = node.loc.expression.source return if exp.include?("\n") return unless node.loc.respond_to?(:else) && node.loc.else condition = exp.include?('if') ? 'if' : 'unless' add_offense(node, :expression, format(MSG, condition)) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems