Sha256: 2b7ec837b2adc4c83551d7db55763ea13b6e98622768e1aac2e2956e654ba669
Contents?: true
Size: 989 Bytes
Versions: 10
Compression:
Stored size: 989 Bytes
Contents
# frozen_string_literal: true module RailsBestPractices module Reviews # Check if method definition has parentheses around parameters. # # Review process: # check def node in all files, # if params node with values, but not wrapped by paren node, # then it should use parentheses around parameters. class UseParenthesesInMethodDefReview < Review interesting_nodes :def interesting_files ALL_FILES # check def node to see if parameters are wrapped by parentheses. add_callback :start_def do |node| if no_parentheses_around_parameters?(node) && has_parameters?(node) add_error('use parentheses around parameters in method definitions') end end protected def no_parentheses_around_parameters?(def_node) def_node[2][0] != :parent end def has_parameters?(def_node) def_node[2][0] == :params && !def_node[2][1..-1].compact.empty? end end end end
Version data entries
10 entries across 10 versions & 1 rubygems