Commit e77a9a34 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'casecmp-cop' into 'master'

Enable Rubocop Casecmp Performance Cop.

Also fixes the errors caused by enabling the cop.

`casecmp` is more performant than `.downcase` and `==`.

See also: https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/performance/casecmp.rb

See merge request !3957
parents de5ae1bf 377583a3
...@@ -937,10 +937,9 @@ Lint/Void: ...@@ -937,10 +937,9 @@ Lint/Void:
##################### Performance ############################ ##################### Performance ############################
# TODO: Enable Casecmp Cop.
# Use `casecmp` rather than `downcase ==`. # Use `casecmp` rather than `downcase ==`.
Performance/Casecmp: Performance/Casecmp:
Enabled: false Enabled: true
# TODO: Enable DoubleStartEndWith Cop. # TODO: Enable DoubleStartEndWith Cop.
# Use `str.{start,end}_with?(x, ..., y, ...)` instead of # Use `str.{start,end}_with?(x, ..., y, ...)` instead of
......
...@@ -453,7 +453,7 @@ class Repository ...@@ -453,7 +453,7 @@ class Repository
def version def version
cache.fetch(:version) do cache.fetch(:version) do
tree(:head).blobs.find do |file| tree(:head).blobs.find do |file|
file.name.downcase == 'version' file.name.casecmp('version').zero?
end end
end end
end end
......
...@@ -5,11 +5,11 @@ module Gitlab ...@@ -5,11 +5,11 @@ module Gitlab
end end
def self.mysql? def self.mysql?
adapter_name.downcase == 'mysql2' adapter_name.casecmp('mysql2').zero?
end end
def self.postgresql? def self.postgresql?
adapter_name.downcase == 'postgresql' adapter_name.casecmp('postgresql').zero?
end end
def self.version def self.version
......
...@@ -40,7 +40,7 @@ module Gitlab ...@@ -40,7 +40,7 @@ module Gitlab
# Returns boolean # Returns boolean
def plain?(filename) def plain?(filename)
filename.downcase.end_with?('.txt') || filename.downcase.end_with?('.txt') ||
filename.downcase == 'readme' filename.casecmp('readme').zero?
end end
def previewable?(filename) def previewable?(filename)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment