From 7ec0b7b519ed78b0a72f65bca64fb5faeb16f747 Mon Sep 17 00:00:00 2001
From: Igor Drozdov <idrozdov@gitlab.com>
Date: Wed, 22 Apr 2020 18:49:32 +0300
Subject: [PATCH] Fix Style/TernaryParentheses offenses

The cop checks for unneeded parentheses for ternary operators
It would be cool to have it enabled for all files
---
 .rubocop_todo.yml                               | 12 ------------
 app/finders/projects_finder.rb                  |  4 ++--
 app/helpers/namespaces_helper.rb                |  4 ++--
 lib/gitlab/ci/build/artifacts/metadata/entry.rb |  2 +-
 spec/requests/api/pipeline_schedules_spec.rb    |  2 +-
 spec/support/capybara.rb                        |  2 +-
 6 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 344a880760ea0..bd0f9184cd662 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -613,18 +613,6 @@ Style/StringLiteralsInInterpolation:
 Style/SymbolProc:
   Enabled: false
 
-# Offense count: 7
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
-# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
-Style/TernaryParentheses:
-  Exclude:
-    - 'app/finders/projects_finder.rb'
-    - 'app/helpers/namespaces_helper.rb'
-    - 'lib/gitlab/ci/build/artifacts/metadata/entry.rb'
-    - 'spec/requests/api/pipeline_schedules_spec.rb'
-    - 'spec/support/capybara.rb'
-
 # Offense count: 99
 # Cop supports --auto-correct.
 Style/UnneededInterpolation:
diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb
index 3a84600b09f20..8846ff54eb20a 100644
--- a/app/finders/projects_finder.rb
+++ b/app/finders/projects_finder.rb
@@ -151,11 +151,11 @@ def union(items)
   end
 
   def by_personal(items)
-    (params[:personal].present? && current_user) ? items.personal(current_user) : items
+    params[:personal].present? && current_user ? items.personal(current_user) : items
   end
 
   def by_starred(items)
-    (params[:starred].present? && current_user) ? items.starred_by(current_user) : items
+    params[:starred].present? && current_user ? items.starred_by(current_user) : items
   end
 
   def by_trending(items)
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb
index 9de28fb3ed919..228dc2cc27f2e 100644
--- a/app/helpers/namespaces_helper.rb
+++ b/app/helpers/namespaces_helper.rb
@@ -80,8 +80,8 @@ def options_for_group(namespaces, display_path:, type:)
          visibility_level: n.visibility_level_value,
          visibility: n.visibility,
          name: n.name,
-         show_path: (type == 'group') ? group_path(n) : user_path(n),
-         edit_path: (type == 'group') ? edit_group_path(n) : nil
+         show_path: type == 'group' ? group_path(n) : user_path(n),
+         edit_path: type == 'group' ? edit_group_path(n) : nil
        }]
     end
 
diff --git a/lib/gitlab/ci/build/artifacts/metadata/entry.rb b/lib/gitlab/ci/build/artifacts/metadata/entry.rb
index 80e69cdcc9591..ef354832e8e2f 100644
--- a/lib/gitlab/ci/build/artifacts/metadata/entry.rb
+++ b/lib/gitlab/ci/build/artifacts/metadata/entry.rb
@@ -50,7 +50,7 @@ def parent
             end
 
             def basename
-              (directory? && !blank_node?) ? name + '/' : name
+              directory? && !blank_node? ? name + '/' : name
             end
 
             def name
diff --git a/spec/requests/api/pipeline_schedules_spec.rb b/spec/requests/api/pipeline_schedules_spec.rb
index 14b292db04568..98eaf36b14e2a 100644
--- a/spec/requests/api/pipeline_schedules_spec.rb
+++ b/spec/requests/api/pipeline_schedules_spec.rb
@@ -67,7 +67,7 @@ def create_pipeline_schedules(count)
         end
 
         def active?(str)
-          (str == 'active') ? true : false
+          str == 'active'
         end
       end
     end
diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb
index 90adfb1a2eecf..e80b69e4fd56c 100644
--- a/spec/support/capybara.rb
+++ b/spec/support/capybara.rb
@@ -7,7 +7,7 @@
 require 'selenium-webdriver'
 
 # Give CI some extra time
-timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 60 : 30
+timeout = ENV['CI'] || ENV['CI_SERVER'] ? 60 : 30
 
 # Define an error class for JS console messages
 JSConsoleError = Class.new(StandardError)
-- 
GitLab