Checking basic code formatting with Ruby
You may not have seen an example of it, but Ruby actually ships with a built-in syntax checker that will warn about syntax that is almost universally considered problematic. It can catch issues such as the following:
- Unused variables:
def a b = 1 # b not used 2 end
- Unreachable code:
def a return 2 # not reachable end
- Mismatched and possibly misleading indentation:
if a if b p 3 end # misleading, appears to close "if a" instead of "if b" end
- Unused literal expressions:
def a 1 # unused literal value 2 end
- Duplicated keyword arguments and hash keys:
a(b: 1, b: 2) # duplicate keyword argument {c: 3, c: 4} # duplicate hash key
- Using
meth *args
whenmeth
is a local variable (which is parsed asmeth.*(args)
instead ofmeth(*args)
) - Using
if var = val
conditionals, whereval
is a static value such...