Files
codeql/ruby/ql/test/query-tests/performance/UseDetect/UseDetect.rb
2021-10-15 11:47:28 +02:00

22 lines
621 B
Ruby

class DetectTest
def test
# These are bad
[].select { |i| true }.first
[].select { |i| true }.last
[].select { |i| true }[0]
[].select { |i| true }[-1]
[].filter { |i| true }.first
[].find_all { |i| true }.last
selection1 = [].select { |i| true }
selection1.first
# These are good
[].select("").first # Selecting a string
[].select { |i| true }[1] # Selecting the second element
selection2 = [].select { |i| true }
selection2.first # Selection used elsewhere
selection3 = selection2
end
end