Apply rubocop rules

Apply rubocop rules

From d03c09e182f821265edd7cb0a96b3c2c4cd23605 Mon Sep 17 00:00:00 2001
From: Gerhard Schlager <mail@gerhard-schlager.at>
Date: Mon, 3 Dec 2018 11:41:36 +0100
Subject: [PATCH] Apply rubocop rules


diff --git a/Gemfile b/Gemfile
index 44c6bf1..9dc719e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,6 +1,6 @@
 source "https://rubygems.org"
 
-git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
+git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
 
 # Specify your gem's dependencies in prometheus_exporter.gemspec
 gemspec
diff --git a/Guardfile b/Guardfile
index ff783e6..22e1112 100644
--- a/Guardfile
+++ b/Guardfile
@@ -4,4 +4,3 @@ guard :minitest do
   watch(%r{^lib/prometheus_exporter/(.*/)?([^/]+)\.rb$})     { |m| "test/#{m[1]}#{m[2]}_test.rb" }
   watch(%r{^test/test_helper\.rb$})      { 'test' }
 end
-
diff --git a/Rakefile b/Rakefile
index d433a1e..3d52175 100644
--- a/Rakefile
+++ b/Rakefile
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
   t.test_files = FileList["test/**/*_test.rb"]
 end
 
-task :default => :test
+task default: :test
diff --git a/lib/prometheus_exporter/instrumentation/sidekiq.rb b/lib/prometheus_exporter/instrumentation/sidekiq.rb
index 20f80bd..c6e3add 100644
--- a/lib/prometheus_exporter/instrumentation/sidekiq.rb
+++ b/lib/prometheus_exporter/instrumentation/sidekiq.rb
@@ -15,11 +15,8 @@ module PrometheusExporter::Instrumentation
       result
     ensure
       duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
-      class_name = if worker.class.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper'
-                     msg['wrapped']
-                   else
-                     worker.class.to_s
-                   end
+      class_name = worker.class.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper' ?
+                     msg['wrapped'] : worker.class.to_s
 
       @client.send_json(
         type: "sidekiq",
diff --git a/lib/prometheus_exporter/metric/histogram.rb b/lib/prometheus_exporter/metric/histogram.rb
index fd4ae05..c997bbe 100644
--- a/lib/prometheus_exporter/metric/histogram.rb
+++ b/lib/prometheus_exporter/metric/histogram.rb
@@ -52,7 +52,7 @@ module PrometheusExporter::Metric
       @counts[labels] ||= 0
       buckets = @observations[labels]
       if buckets.nil?
-        buckets = @buckets.map{|b| [b, 0]}.to_h
+        buckets = @buckets.map { |b| [b, 0] }.to_h
         @observations[labels] = buckets
       end
       buckets
@@ -66,7 +66,7 @@ module PrometheusExporter::Metric
     end
 
     def with_bucket(labels, bucket)
-      labels.merge({"le" => bucket})
+      labels.merge("le" => bucket)
     end
 
   end
diff --git a/lib/prometheus_exporter/middleware.rb b/lib/prometheus_exporter/middleware.rb
index d068d71..705526c 100644
--- a/lib/prometheus_exporter/middleware.rb
+++ b/lib/prometheus_exporter/middleware.rb
@@ -85,6 +85,6 @@ class PrometheusExporter::Middleware
   # this method takes care to convert both into a proper second + fractions timestamp
   def convert_header_to_ms(str)
     str = str.gsub(/t=|\./, '')
-    "#{str[0,10]}.#{str[10,13]}".to_f
+    "#{str[0, 10]}.#{str[10, 13]}".to_f
   end
 end
diff --git a/test/metric/base_test.rb b/test/metric/base_test.rb
index f8bcbb3..000ff2b 100644
--- a/test/metric/base_test.rb
+++ b/test/metric/base_test.rb
@@ -1,8 +1,6 @@
 require 'test_helper'
 require 'prometheus_exporter/metric'
 
-
-
 module PrometheusExporter::Metric
   describe Base do
     let :counter do
diff --git a/test/server/collector_test.rb b/test/server/collector_test.rb
index dc3f2ce..dc161b1 100644
--- a/test/server/collector_test.rb
+++ b/test/server/collector_test.rb
@@ -47,7 +47,7 @@ class PrometheusCollectorTest < Minitest::Test
       type: :gauge,
       help: help,
       name: name,
-      keys: {key1: 'test1'},
+      keys: { key1: 'test1' },
       prometheus_exporter_action: :increment,
       value: 1
     }.to_json
@@ -73,7 +73,7 @@ class PrometheusCollectorTest < Minitest::Test
       type: :gauge,
       help: help,
       name: name,
-      keys: {key1: 'test1'},
+      keys: { key1: 'test1' },
       prometheus_exporter_action: :decrement,
       value: 5
     }.to_json
@@ -175,7 +175,7 @@ class PrometheusCollectorTest < Minitest::Test
     job.expect(:handler, "job_class: Class")
     job.expect(:attempts, 0)
 
-    instrument.call(job,20, nil, "default") do
+    instrument.call(job, 20, nil, "default") do
       # nothing
     end
 
@@ -209,7 +209,7 @@ class PrometheusCollectorTest < Minitest::Test
     job.expect(:handler, "job_class: Class")
     job.expect(:attempts, 0)
 
-    instrument.call(job, 25,nil, "default") do
+    instrument.call(job, 25, nil, "default") do
       # nothing
     end
 
@@ -217,7 +217,6 @@ class PrometheusCollectorTest < Minitest::Test
     failed_job.expect(:handler, "job_class: Object")
     failed_job.expect(:attempts, 1)
 
-
     begin
       instrument.call(failed_job, 25, nil, "default") do
         boom
diff --git a/test/server/web_collector_test.rb b/test/server/web_collector_test.rb
index 804f850..a52fe21 100644
--- a/test/server/web_collector_test.rb
+++ b/test/server/web_collector_test.rb
@@ -9,13 +9,13 @@ class PrometheusWebCollectorTest < Minitest::Test
   end
 
   def test_collecting_metrics_without_specific_timings
-    collector.collect({
+    collector.collect(
       type: "web",
       timings: nil,
       action: 'index',
       controller: 'home',
       status: 200
-    })
+    )
 
     metrics = collector.metrics
 
@@ -23,7 +23,7 @@ class PrometheusWebCollectorTest < Minitest::Test
   end
 
   def test_collecting_metrics
-    collector.collect({
+    collector.collect(
       "type" => "web",
       "timings" => {
         "sql" => {
@@ -40,14 +40,14 @@ class PrometheusWebCollectorTest < Minitest::Test
       "action" => 'index',
       "controller" => 'home',
       "status" => 200
-    })
+    )
 
     metrics = collector.metrics
     assert_equal 5, metrics.size
   end
 
   def test_collecting_metrics_with_custom_labels
-    collector.collect({
+    collector.collect(
       'type' => 'web',
       'timings' => nil,
       'action' => 'index',
@@ -56,7 +56,7 @@ class PrometheusWebCollectorTest < Minitest::Test
       'custom_labels' => {
         'service' => 'service1'
       }
-    })
+    )
 
     metrics = collector.metrics
 
diff --git a/test/test_helper.rb b/test/test_helper.rb
index cbf875f..1280979 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -5,7 +5,7 @@ require "minitest/autorun"
 
 class TestHelper
   def self.wait_for(time, &blk)
-    (time/0.001).to_i.times do
+    (time / 0.001).to_i.times do
       return true if blk.call
       sleep 0.001
     end

GitHub

Just to clarify, this is rubocop --auto-correct at play here?

Nope. I changed that one manually. The if - else - end was kinda hard to get in a format that was accepted by rubocop and was visually pleasing to my eyes.

2 Likes