From 3641a4443114789c73832067221bcc1ed4bb968f Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 10:39:49 +0200 Subject: [PATCH 01/64] fix Style/FrozenStringLiteralComment --- .rubocop_todo.yml | 123 ------------------ Gemfile | 2 + Rakefile | 2 + bin/pliny-generate | 1 + bin/pliny-new | 1 + bin/pliny-update | 1 + lib/pliny.rb | 2 + lib/pliny/canonical_log_line_helpers.rb | 2 + lib/pliny/commands/creator.rb | 2 + lib/pliny/commands/generator.rb | 2 + lib/pliny/commands/generator/base.rb | 2 + lib/pliny/commands/generator/endpoint.rb | 2 + lib/pliny/commands/generator/mediator.rb | 2 + lib/pliny/commands/generator/migration.rb | 2 + lib/pliny/commands/generator/model.rb | 2 + lib/pliny/commands/generator/schema.rb | 2 + lib/pliny/commands/generator/serializer.rb | 2 + lib/pliny/commands/updater.rb | 2 + lib/pliny/config_helpers.rb | 2 + lib/pliny/db_support.rb | 10 +- lib/pliny/error_reporters.rb | 2 + lib/pliny/error_reporters/rollbar.rb | 2 + lib/pliny/errors.rb | 2 + lib/pliny/helpers/encode.rb | 2 + lib/pliny/helpers/params.rb | 2 + lib/pliny/helpers/serialize.rb | 2 + lib/pliny/helpers/zulu_time.rb | 2 + lib/pliny/log.rb | 2 + lib/pliny/metrics.rb | 2 + lib/pliny/metrics/backends/logger.rb | 2 + lib/pliny/middleware/canonical_log_line.rb | 2 + lib/pliny/middleware/cors.rb | 2 + lib/pliny/middleware/instruments.rb | 2 + lib/pliny/middleware/metrics.rb | 2 + lib/pliny/middleware/request_id.rb | 2 + lib/pliny/middleware/request_store/clear.rb | 2 + lib/pliny/middleware/request_store/seed.rb | 2 + lib/pliny/middleware/rescue_errors.rb | 2 + lib/pliny/middleware/versioning.rb | 2 + lib/pliny/request_store.rb | 2 + lib/pliny/rollbar_logger.rb | 2 + lib/pliny/router.rb | 2 + lib/pliny/tasks.rb | 2 + lib/pliny/tasks/db.rake | 2 + lib/pliny/tasks/schema.rake | 2 + lib/pliny/utils.rb | 2 + lib/pliny/version.rb | 2 + lib/template/.rubocop.yml | 3 - lib/template/Gemfile | 2 + lib/template/Rakefile | 1 + lib/template/bin/console | 1 + lib/template/bin/run | 1 + lib/template/config.ru | 2 + lib/template/config/config.rb | 2 + lib/template/config/initializers/database.rb | 2 + lib/template/config/initializers/log.rb | 2 + lib/template/config/initializers/metrics.rb | 2 + lib/template/config/initializers/rollbar.rb | 2 + lib/template/config/puma.rb | 2 + lib/template/db/seeds.rb | 2 + lib/template/lib/application.rb | 2 + lib/template/lib/endpoints/base.rb | 2 + lib/template/lib/endpoints/health.rb | 2 + lib/template/lib/endpoints/root.rb | 2 + lib/template/lib/endpoints/schema.rb | 2 + lib/template/lib/initializer.rb | 2 + lib/template/lib/mediators/base.rb | 2 + lib/template/lib/routes.rb | 2 + lib/template/lib/serializers/base.rb | 2 + lib/template/lib/tasks/rubocop.rake | 2 + lib/template/lib/tasks/spec.rake | 1 + lib/template/spec/endpoints/health_spec.rb | 2 + lib/template/spec/endpoints/schema_spec.rb | 2 + lib/template/spec/spec_helper.rb | 2 + .../spec/spec_support/auto_define_rack_app.rb | 2 + lib/template/spec/spec_support/coverage.rb | 2 + lib/template/spec/spec_support/log.rb | 2 + pliny.gemspec | 2 + spec/canonical_log_line_helpers_spec.rb | 2 + spec/commands/creator_spec.rb | 2 + spec/commands/generator/base_spec.rb | 2 + spec/commands/generator/endpoint_spec.rb | 2 + spec/commands/generator/mediator_spec.rb | 2 + spec/commands/generator/migration_spec.rb | 2 + spec/commands/generator/model_spec.rb | 2 + spec/commands/generator/schema_spec.rb | 2 + spec/commands/generator/serializer_spec.rb | 2 + spec/commands/generator_spec.rb | 2 + spec/commands/updater_spec.rb | 2 + spec/config_helpers_spec.rb | 2 + spec/db_support_spec.rb | 2 + spec/error_reporters/rollbar_spec.rb | 2 + spec/error_reporters_spec.rb | 2 + spec/errors_spec.rb | 2 + spec/helpers/encode_spec.rb | 2 + spec/helpers/params_spec.rb | 2 + spec/helpers/serialize_spec.rb | 2 + spec/helpers/zulu_time_spec.rb | 2 + spec/integration_spec.rb | 2 + spec/log_spec.rb | 2 + spec/metrics/backends/logger_spec.rb | 2 + spec/metrics_spec.rb | 2 + spec/middleware/canonical_log_line_spec.rb | 2 + spec/middleware/cors_spec.rb | 2 + spec/middleware/instruments_spec.rb | 2 + spec/middleware/metrics_spec.rb | 2 + spec/middleware/request_id_spec.rb | 2 + spec/middleware/request_store/clear_spec.rb | 2 + spec/middleware/request_store/seed_spec.rb | 2 + spec/middleware/rescue_errors_spec.rb | 2 + spec/middleware/versioning_spec.rb | 2 + spec/request_store_spec.rb | 2 + spec/rollbar_logger_spec.rb | 2 + spec/router_spec.rb | 2 + spec/spec_helper.rb | 2 + spec/support/config.rb | 2 + spec/support/endpoints.rb | 2 + 117 files changed, 227 insertions(+), 130 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 852a55aa..a931e448 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -331,129 +331,6 @@ Style/FileWrite: Exclude: - 'lib/pliny/commands/creator.rb' -# Offense count: 115 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Exclude: - - '**/*.arb' - - 'Gemfile' - - 'Rakefile' - - 'bin/pliny-generate' - - 'bin/pliny-new' - - 'bin/pliny-update' - - 'lib/pliny.rb' - - 'lib/pliny/canonical_log_line_helpers.rb' - - 'lib/pliny/commands/creator.rb' - - 'lib/pliny/commands/generator.rb' - - 'lib/pliny/commands/generator/base.rb' - - 'lib/pliny/commands/generator/endpoint.rb' - - 'lib/pliny/commands/generator/mediator.rb' - - 'lib/pliny/commands/generator/migration.rb' - - 'lib/pliny/commands/generator/model.rb' - - 'lib/pliny/commands/generator/schema.rb' - - 'lib/pliny/commands/generator/serializer.rb' - - 'lib/pliny/commands/updater.rb' - - 'lib/pliny/config_helpers.rb' - - 'lib/pliny/db_support.rb' - - 'lib/pliny/error_reporters.rb' - - 'lib/pliny/error_reporters/rollbar.rb' - - 'lib/pliny/errors.rb' - - 'lib/pliny/helpers/encode.rb' - - 'lib/pliny/helpers/params.rb' - - 'lib/pliny/helpers/serialize.rb' - - 'lib/pliny/helpers/zulu_time.rb' - - 'lib/pliny/log.rb' - - 'lib/pliny/metrics.rb' - - 'lib/pliny/metrics/backends/logger.rb' - - 'lib/pliny/middleware/canonical_log_line.rb' - - 'lib/pliny/middleware/cors.rb' - - 'lib/pliny/middleware/instruments.rb' - - 'lib/pliny/middleware/metrics.rb' - - 'lib/pliny/middleware/request_id.rb' - - 'lib/pliny/middleware/request_store/clear.rb' - - 'lib/pliny/middleware/request_store/seed.rb' - - 'lib/pliny/middleware/rescue_errors.rb' - - 'lib/pliny/middleware/versioning.rb' - - 'lib/pliny/request_store.rb' - - 'lib/pliny/rollbar_logger.rb' - - 'lib/pliny/router.rb' - - 'lib/pliny/tasks.rb' - - 'lib/pliny/tasks/db.rake' - - 'lib/pliny/tasks/schema.rake' - - 'lib/pliny/utils.rb' - - 'lib/pliny/version.rb' - - 'lib/template/Gemfile' - - 'lib/template/Rakefile' - - 'lib/template/bin/console' - - 'lib/template/bin/run' - - 'lib/template/config.ru' - - 'lib/template/config/config.rb' - - 'lib/template/config/initializers/database.rb' - - 'lib/template/config/initializers/log.rb' - - 'lib/template/config/initializers/metrics.rb' - - 'lib/template/config/initializers/rollbar.rb' - - 'lib/template/config/puma.rb' - - 'lib/template/db/seeds.rb' - - 'lib/template/lib/application.rb' - - 'lib/template/lib/endpoints/base.rb' - - 'lib/template/lib/endpoints/health.rb' - - 'lib/template/lib/endpoints/root.rb' - - 'lib/template/lib/endpoints/schema.rb' - - 'lib/template/lib/initializer.rb' - - 'lib/template/lib/mediators/base.rb' - - 'lib/template/lib/routes.rb' - - 'lib/template/lib/serializers/base.rb' - - 'lib/template/lib/tasks/rubocop.rake' - - 'lib/template/lib/tasks/spec.rake' - - 'lib/template/spec/endpoints/health_spec.rb' - - 'lib/template/spec/endpoints/schema_spec.rb' - - 'lib/template/spec/spec_helper.rb' - - 'lib/template/spec/spec_support/auto_define_rack_app.rb' - - 'lib/template/spec/spec_support/coverage.rb' - - 'lib/template/spec/spec_support/log.rb' - - 'pliny.gemspec' - - 'spec/canonical_log_line_helpers_spec.rb' - - 'spec/commands/creator_spec.rb' - - 'spec/commands/generator/base_spec.rb' - - 'spec/commands/generator/endpoint_spec.rb' - - 'spec/commands/generator/mediator_spec.rb' - - 'spec/commands/generator/migration_spec.rb' - - 'spec/commands/generator/model_spec.rb' - - 'spec/commands/generator/schema_spec.rb' - - 'spec/commands/generator/serializer_spec.rb' - - 'spec/commands/generator_spec.rb' - - 'spec/commands/updater_spec.rb' - - 'spec/config_helpers_spec.rb' - - 'spec/db_support_spec.rb' - - 'spec/error_reporters/rollbar_spec.rb' - - 'spec/error_reporters_spec.rb' - - 'spec/errors_spec.rb' - - 'spec/helpers/encode_spec.rb' - - 'spec/helpers/params_spec.rb' - - 'spec/helpers/serialize_spec.rb' - - 'spec/helpers/zulu_time_spec.rb' - - 'spec/integration_spec.rb' - - 'spec/log_spec.rb' - - 'spec/metrics/backends/logger_spec.rb' - - 'spec/metrics_spec.rb' - - 'spec/middleware/canonical_log_line_spec.rb' - - 'spec/middleware/cors_spec.rb' - - 'spec/middleware/instruments_spec.rb' - - 'spec/middleware/metrics_spec.rb' - - 'spec/middleware/request_id_spec.rb' - - 'spec/middleware/request_store/clear_spec.rb' - - 'spec/middleware/request_store/seed_spec.rb' - - 'spec/middleware/rescue_errors_spec.rb' - - 'spec/middleware/versioning_spec.rb' - - 'spec/request_store_spec.rb' - - 'spec/rollbar_logger_spec.rb' - - 'spec/router_spec.rb' - - 'spec/spec_helper.rb' - - 'spec/support/config.rb' - - 'spec/support/endpoints.rb' - # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSplatArgument. diff --git a/Gemfile b/Gemfile index cd7558b7..fd3e4b2c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" gemspec diff --git a/Rakefile b/Rakefile index ca385ce9..55e51169 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $:.unshift File.expand_path("../lib", __FILE__) require "pliny/version" diff --git a/bin/pliny-generate b/bin/pliny-generate index 89cee34b..b81e5eab 100755 --- a/bin/pliny-generate +++ b/bin/pliny-generate @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require_relative '../lib/pliny/commands/generator' Pliny::Commands::Generator.start diff --git a/bin/pliny-new b/bin/pliny-new index 733deae3..addef6e7 100755 --- a/bin/pliny-new +++ b/bin/pliny-new @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require "optparse" require_relative '../lib/pliny/commands/creator' diff --git a/bin/pliny-update b/bin/pliny-update index bdfd4a3b..af730192 100755 --- a/bin/pliny-update +++ b/bin/pliny-update @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require "optparse" require_relative '../lib/pliny/commands/updater' diff --git a/lib/pliny.rb b/lib/pliny.rb index bedb6e98..6f6b7b40 100644 --- a/lib/pliny.rb +++ b/lib/pliny.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "json" require "sinatra/base" diff --git a/lib/pliny/canonical_log_line_helpers.rb b/lib/pliny/canonical_log_line_helpers.rb index 413fb60a..0157ef24 100644 --- a/lib/pliny/canonical_log_line_helpers.rb +++ b/lib/pliny/canonical_log_line_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny # Helpers to produce a canonical log line. This mostly amounts to a set of # accessors that do basic type checking combined with tracking an internal diff --git a/lib/pliny/commands/creator.rb b/lib/pliny/commands/creator.rb index dd971e63..eeb41b8c 100644 --- a/lib/pliny/commands/creator.rb +++ b/lib/pliny/commands/creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'fileutils' require 'pathname' require 'pliny/version' diff --git a/lib/pliny/commands/generator.rb b/lib/pliny/commands/generator.rb index 91dea1b1..ad6dc2c5 100644 --- a/lib/pliny/commands/generator.rb +++ b/lib/pliny/commands/generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/version' require 'thor' diff --git a/lib/pliny/commands/generator/base.rb b/lib/pliny/commands/generator/base.rb index 74937f86..de89cc21 100644 --- a/lib/pliny/commands/generator/base.rb +++ b/lib/pliny/commands/generator/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/inflector' require 'ostruct' require 'erb' diff --git a/lib/pliny/commands/generator/endpoint.rb b/lib/pliny/commands/generator/endpoint.rb index 26aa92ce..6323f66f 100644 --- a/lib/pliny/commands/generator/endpoint.rb +++ b/lib/pliny/commands/generator/endpoint.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'base' module Pliny::Commands diff --git a/lib/pliny/commands/generator/mediator.rb b/lib/pliny/commands/generator/mediator.rb index d70bd5bd..b7847048 100644 --- a/lib/pliny/commands/generator/mediator.rb +++ b/lib/pliny/commands/generator/mediator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'base' module Pliny::Commands diff --git a/lib/pliny/commands/generator/migration.rb b/lib/pliny/commands/generator/migration.rb index dd816fa1..bc3696c7 100644 --- a/lib/pliny/commands/generator/migration.rb +++ b/lib/pliny/commands/generator/migration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'base' module Pliny::Commands diff --git a/lib/pliny/commands/generator/model.rb b/lib/pliny/commands/generator/model.rb index 6b65a49a..758eab71 100644 --- a/lib/pliny/commands/generator/model.rb +++ b/lib/pliny/commands/generator/model.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'base' module Pliny::Commands diff --git a/lib/pliny/commands/generator/schema.rb b/lib/pliny/commands/generator/schema.rb index 293cae3e..4c8e2daa 100644 --- a/lib/pliny/commands/generator/schema.rb +++ b/lib/pliny/commands/generator/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'base' require 'prmd' diff --git a/lib/pliny/commands/generator/serializer.rb b/lib/pliny/commands/generator/serializer.rb index 24631417..11c39849 100644 --- a/lib/pliny/commands/generator/serializer.rb +++ b/lib/pliny/commands/generator/serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'base' module Pliny::Commands diff --git a/lib/pliny/commands/updater.rb b/lib/pliny/commands/updater.rb index d60039de..7c216cab 100644 --- a/lib/pliny/commands/updater.rb +++ b/lib/pliny/commands/updater.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "fileutils" require "pathname" require "pliny/version" diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index 27a3ecc3..a6395010 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny module CastingConfigHelpers def mandatory(name, method=nil) diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index 0c3f755e..bcf38162 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "logger" require "sequel" require "sequel/extensions/migration" @@ -91,9 +93,9 @@ def status class MigrationStatusPresenter PADDING = 2 - UP = "UP".freeze - DOWN = "DOWN".freeze - FILE_MISSING = "FILE MISSING".freeze + UP = "UP" + DOWN = "DOWN" + FILE_MISSING = "FILE MISSING" STATUS_MAP = { up: UP, @@ -210,7 +212,7 @@ def disconnect private - MIGRATION_DIR = "./db/migrate".freeze + MIGRATION_DIR = "./db/migrate" private_constant :MIGRATION_DIR end end diff --git a/lib/pliny/error_reporters.rb b/lib/pliny/error_reporters.rb index d7723b25..a7a35013 100644 --- a/lib/pliny/error_reporters.rb +++ b/lib/pliny/error_reporters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::ErrorReporters extend self diff --git a/lib/pliny/error_reporters/rollbar.rb b/lib/pliny/error_reporters/rollbar.rb index f37c66cd..8ac65653 100644 --- a/lib/pliny/error_reporters/rollbar.rb +++ b/lib/pliny/error_reporters/rollbar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rollbar/exception_reporter' require 'rollbar/request_data_extractor' diff --git a/lib/pliny/errors.rb b/lib/pliny/errors.rb index 69db9f23..a9191287 100644 --- a/lib/pliny/errors.rb +++ b/lib/pliny/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny module Errors class Error < StandardError diff --git a/lib/pliny/helpers/encode.rb b/lib/pliny/helpers/encode.rb index ec531b4b..7b2c9e99 100644 --- a/lib/pliny/helpers/encode.rb +++ b/lib/pliny/helpers/encode.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Helpers module Encode def encode(object) diff --git a/lib/pliny/helpers/params.rb b/lib/pliny/helpers/params.rb index d15aa6b7..9acab394 100644 --- a/lib/pliny/helpers/params.rb +++ b/lib/pliny/helpers/params.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Helpers module Params def body_params diff --git a/lib/pliny/helpers/serialize.rb b/lib/pliny/helpers/serialize.rb index 9fe65859..4afb6b0f 100644 --- a/lib/pliny/helpers/serialize.rb +++ b/lib/pliny/helpers/serialize.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Helpers module Serialize def self.registered(base) diff --git a/lib/pliny/helpers/zulu_time.rb b/lib/pliny/helpers/zulu_time.rb index 5c05c3d3..3431d73a 100644 --- a/lib/pliny/helpers/zulu_time.rb +++ b/lib/pliny/helpers/zulu_time.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Helpers module ZuluTime def zulu_time(time) diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index 308e4d11..6719f808 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny module Log def log(data, &block) diff --git a/lib/pliny/metrics.rb b/lib/pliny/metrics.rb index 7d8ecf9d..5957565b 100644 --- a/lib/pliny/metrics.rb +++ b/lib/pliny/metrics.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny module Metrics extend self diff --git a/lib/pliny/metrics/backends/logger.rb b/lib/pliny/metrics/backends/logger.rb index 887af51f..c0d054d1 100644 --- a/lib/pliny/metrics/backends/logger.rb +++ b/lib/pliny/metrics/backends/logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny module Metrics module Backends diff --git a/lib/pliny/middleware/canonical_log_line.rb b/lib/pliny/middleware/canonical_log_line.rb index 2b088210..e2aaaca1 100644 --- a/lib/pliny/middleware/canonical_log_line.rb +++ b/lib/pliny/middleware/canonical_log_line.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Middleware # Emits a "canonical log line", i.e. a single log line that contains as much # relevant information about a request as possible and which makes for a diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index 430ebd18..f74df816 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Middleware class CORS diff --git a/lib/pliny/middleware/instruments.rb b/lib/pliny/middleware/instruments.rb index a9b91f22..c1d1744b 100644 --- a/lib/pliny/middleware/instruments.rb +++ b/lib/pliny/middleware/instruments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Middleware class Instruments def initialize(app) diff --git a/lib/pliny/middleware/metrics.rb b/lib/pliny/middleware/metrics.rb index aa3f543b..e31443f9 100644 --- a/lib/pliny/middleware/metrics.rb +++ b/lib/pliny/middleware/metrics.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Middleware class Metrics def initialize(app) diff --git a/lib/pliny/middleware/request_id.rb b/lib/pliny/middleware/request_id.rb index 1c620662..e9660fba 100644 --- a/lib/pliny/middleware/request_id.rb +++ b/lib/pliny/middleware/request_id.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # please add changes here to core's Instruments as well module Pliny::Middleware diff --git a/lib/pliny/middleware/request_store/clear.rb b/lib/pliny/middleware/request_store/clear.rb index 327fe9f0..101e2ddf 100644 --- a/lib/pliny/middleware/request_store/clear.rb +++ b/lib/pliny/middleware/request_store/clear.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Middleware::RequestStore class Clear def initialize(app, options={}) diff --git a/lib/pliny/middleware/request_store/seed.rb b/lib/pliny/middleware/request_store/seed.rb index 7f4ffec8..be0c771d 100644 --- a/lib/pliny/middleware/request_store/seed.rb +++ b/lib/pliny/middleware/request_store/seed.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Middleware::RequestStore class Seed def initialize(app, options={}) diff --git a/lib/pliny/middleware/rescue_errors.rb b/lib/pliny/middleware/rescue_errors.rb index 6809a1cf..bbc2b1db 100644 --- a/lib/pliny/middleware/rescue_errors.rb +++ b/lib/pliny/middleware/rescue_errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny::Middleware class RescueErrors def initialize(app, options = {}) diff --git a/lib/pliny/middleware/versioning.rb b/lib/pliny/middleware/versioning.rb index 3fa5d2fc..eb76e87d 100644 --- a/lib/pliny/middleware/versioning.rb +++ b/lib/pliny/middleware/versioning.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'http_accept' module Pliny::Middleware diff --git a/lib/pliny/request_store.rb b/lib/pliny/request_store.rb index 4d5d190f..899901e8 100644 --- a/lib/pliny/request_store.rb +++ b/lib/pliny/request_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny module RequestStore def self.clear! diff --git a/lib/pliny/rollbar_logger.rb b/lib/pliny/rollbar_logger.rb index 7aa67511..1d4ea804 100644 --- a/lib/pliny/rollbar_logger.rb +++ b/lib/pliny/rollbar_logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny class RollbarLogger def debug(message) diff --git a/lib/pliny/router.rb b/lib/pliny/router.rb index a90fdd1c..60696440 100644 --- a/lib/pliny/router.rb +++ b/lib/pliny/router.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'sinatra/router' module Pliny diff --git a/lib/pliny/tasks.rb b/lib/pliny/tasks.rb index 4a1eddea..882a690d 100644 --- a/lib/pliny/tasks.rb +++ b/lib/pliny/tasks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Dir[File.expand_path("../tasks", __FILE__) + "/*.rake"].sort.each do |f| load(f) end diff --git a/lib/pliny/tasks/db.rake b/lib/pliny/tasks/db.rake index 1ae7ada8..ed8428c0 100644 --- a/lib/pliny/tasks/db.rake +++ b/lib/pliny/tasks/db.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "logger" require "uri" require "pliny/utils" diff --git a/lib/pliny/tasks/schema.rake b/lib/pliny/tasks/schema.rake index cc790ce0..615bae3c 100644 --- a/lib/pliny/tasks/schema.rake +++ b/lib/pliny/tasks/schema.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + desc "Rebuild schema.json" task :schema do require 'pliny/commands/generator/schema' diff --git a/lib/pliny/utils.rb b/lib/pliny/utils.rb index 2b32c6d9..79298806 100644 --- a/lib/pliny/utils.rb +++ b/lib/pliny/utils.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny module Utils def self.parse_env(file) diff --git a/lib/pliny/version.rb b/lib/pliny/version.rb index 8b204fcc..6388bc83 100644 --- a/lib/pliny/version.rb +++ b/lib/pliny/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Pliny VERSION = "1.2.0" end diff --git a/lib/template/.rubocop.yml b/lib/template/.rubocop.yml index 0450d15d..eb43772b 100644 --- a/lib/template/.rubocop.yml +++ b/lib/template/.rubocop.yml @@ -23,6 +23,3 @@ Style/Documentation: Style/StringLiterals: Enabled: true EnforcedStyle: double_quotes - -Style/FrozenStringLiteralComment: - Enabled: false diff --git a/lib/template/Gemfile b/lib/template/Gemfile index 10ff6d33..bf0dc99b 100644 --- a/lib/template/Gemfile +++ b/lib/template/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" ruby "2.4.0" diff --git a/lib/template/Rakefile b/lib/template/Rakefile index 861b2e2b..2f90a0ad 100644 --- a/lib/template/Rakefile +++ b/lib/template/Rakefile @@ -1,3 +1,4 @@ +# frozen_string_literal: true require "pliny/tasks" diff --git a/lib/template/bin/console b/lib/template/bin/console index 31e16488..6c6eaf65 100755 --- a/lib/template/bin/console +++ b/lib/template/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require_relative "../lib/application" diff --git a/lib/template/bin/run b/lib/template/bin/run index 45dc3835..58398090 100755 --- a/lib/template/bin/run +++ b/lib/template/bin/run @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # rubocop:disable Security/Eval diff --git a/lib/template/config.ru b/lib/template/config.ru index 0d3a5a85..8a2f9995 100644 --- a/lib/template/config.ru +++ b/lib/template/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "lib/application" $stdout.sync = true diff --git a/lib/template/config/config.rb b/lib/template/config/config.rb index 713d6c4a..e4520635 100644 --- a/lib/template/config/config.rb +++ b/lib/template/config/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pliny/config_helpers" # Access all config keys like the following: diff --git a/lib/template/config/initializers/database.rb b/lib/template/config/initializers/database.rb index 1f1bff95..faf4ea0e 100644 --- a/lib/template/config/initializers/database.rb +++ b/lib/template/config/initializers/database.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + database_setup_proc = lambda do |conn| # identify postgres connections coming from this process in pg_stat_activity process_identifier = ENV["DYNO"] || File.basename($PROGRAM_NAME).gsub(/\W+/, "_") diff --git a/lib/template/config/initializers/log.rb b/lib/template/config/initializers/log.rb index 2f3bb2ec..0f62e728 100644 --- a/lib/template/config/initializers/log.rb +++ b/lib/template/config/initializers/log.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Pliny.default_context = {} Pliny.default_context[:app] = Config.app_name if Config.app_name Pliny.default_context[:deployment] = Config.deployment diff --git a/lib/template/config/initializers/metrics.rb b/lib/template/config/initializers/metrics.rb index c2b8aa09..ea59d6bf 100644 --- a/lib/template/config/initializers/metrics.rb +++ b/lib/template/config/initializers/metrics.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + Pliny::Metrics.backends = [Pliny::Metrics::Backends::Logger] diff --git a/lib/template/config/initializers/rollbar.rb b/lib/template/config/initializers/rollbar.rb index 79329f26..365e584b 100644 --- a/lib/template/config/initializers/rollbar.rb +++ b/lib/template/config/initializers/rollbar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pliny/error_reporters/rollbar" Pliny::ErrorReporters.error_reporters << Pliny::ErrorReporters::Rollbar diff --git a/lib/template/config/puma.rb b/lib/template/config/puma.rb index 53a24c02..0d1100b8 100644 --- a/lib/template/config/puma.rb +++ b/lib/template/config/puma.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "./config/config" environment Config.rack_env diff --git a/lib/template/db/seeds.rb b/lib/template/db/seeds.rb index 0f14889d..d462bd7f 100644 --- a/lib/template/db/seeds.rb +++ b/lib/template/db/seeds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file should contain all the record creation needed to seed the database # with its default values. # The data can then be loaded with the rake db:seed (or created alongside the diff --git a/lib/template/lib/application.rb b/lib/template/lib/application.rb index 898a00b5..32320b85 100644 --- a/lib/template/lib/application.rb +++ b/lib/template/lib/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "bundler" Bundler.require diff --git a/lib/template/lib/endpoints/base.rb b/lib/template/lib/endpoints/base.rb index dd925574..1729086a 100644 --- a/lib/template/lib/endpoints/base.rb +++ b/lib/template/lib/endpoints/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Endpoints # The base class for all Sinatra-based endpoints. Use sparingly. class Base < Sinatra::Base diff --git a/lib/template/lib/endpoints/health.rb b/lib/template/lib/endpoints/health.rb index f44eb836..9bc14e65 100644 --- a/lib/template/lib/endpoints/health.rb +++ b/lib/template/lib/endpoints/health.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Endpoints class Health < Base namespace "/health" do diff --git a/lib/template/lib/endpoints/root.rb b/lib/template/lib/endpoints/root.rb index 22297709..dd4a7fe3 100644 --- a/lib/template/lib/endpoints/root.rb +++ b/lib/template/lib/endpoints/root.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Endpoints class Root < Base get "/" do diff --git a/lib/template/lib/endpoints/schema.rb b/lib/template/lib/endpoints/schema.rb index 94e50bb2..7fd982ea 100644 --- a/lib/template/lib/endpoints/schema.rb +++ b/lib/template/lib/endpoints/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Endpoints class Schema < Base get "/schema.json" do diff --git a/lib/template/lib/initializer.rb b/lib/template/lib/initializer.rb index 1360c70c..a782148e 100644 --- a/lib/template/lib/initializer.rb +++ b/lib/template/lib/initializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Initializer def self.run require_config diff --git a/lib/template/lib/mediators/base.rb b/lib/template/lib/mediators/base.rb index f0cb45b8..d138552e 100644 --- a/lib/template/lib/mediators/base.rb +++ b/lib/template/lib/mediators/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Mediators class Base def self.run(options = {}) diff --git a/lib/template/lib/routes.rb b/lib/template/lib/routes.rb index 832e13cc..31bc0145 100644 --- a/lib/template/lib/routes.rb +++ b/lib/template/lib/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Routes = Rack::Builder.new do use Pliny::Middleware::RequestStore::Clear, store: Pliny::RequestStore use Pliny::Middleware::CORS diff --git a/lib/template/lib/serializers/base.rb b/lib/template/lib/serializers/base.rb index 8006eb20..ead7c738 100644 --- a/lib/template/lib/serializers/base.rb +++ b/lib/template/lib/serializers/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Serializers class Base extend Pliny::Helpers::ZuluTime diff --git a/lib/template/lib/tasks/rubocop.rake b/lib/template/lib/tasks/rubocop.rake index 3a3b67fb..b1ba8511 100644 --- a/lib/template/lib/tasks/rubocop.rake +++ b/lib/template/lib/tasks/rubocop.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if Gem.loaded_specs.has_key?("rubocop-rspec") require "rubocop/rake_task" diff --git a/lib/template/lib/tasks/spec.rake b/lib/template/lib/tasks/spec.rake index f8d1a98c..fa1035c1 100644 --- a/lib/template/lib/tasks/spec.rake +++ b/lib/template/lib/tasks/spec.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true # define our own version of the spec task because rspec might not be available # in the production environment, so we can't rely on RSpec::Core::RakeTask diff --git a/lib/template/spec/endpoints/health_spec.rb b/lib/template/spec/endpoints/health_spec.rb index ec0bc431..d4116305 100644 --- a/lib/template/spec/endpoints/health_spec.rb +++ b/lib/template/spec/endpoints/health_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" RSpec.describe Endpoints::Health do diff --git a/lib/template/spec/endpoints/schema_spec.rb b/lib/template/spec/endpoints/schema_spec.rb index 31c9cbc0..9e114056 100644 --- a/lib/template/spec/endpoints/schema_spec.rb +++ b/lib/template/spec/endpoints/schema_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" RSpec.describe Endpoints::Schema do diff --git a/lib/template/spec/spec_helper.rb b/lib/template/spec/spec_helper.rb index b12d1b6a..f0aee210 100644 --- a/lib/template/spec/spec_helper.rb +++ b/lib/template/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # Require this file using `require "spec_helper"` to ensure that it is only diff --git a/lib/template/spec/spec_support/auto_define_rack_app.rb b/lib/template/spec/spec_support/auto_define_rack_app.rb index 1352c44a..1e858860 100644 --- a/lib/template/spec/spec_support/auto_define_rack_app.rb +++ b/lib/template/spec/spec_support/auto_define_rack_app.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.configure do |config| config.before(:context) do |spec| # weird ruby syntax, but test if the described_class inherits Sinatra::Base: diff --git a/lib/template/spec/spec_support/coverage.rb b/lib/template/spec/spec_support/coverage.rb index 8d5071a9..480cab6d 100644 --- a/lib/template/spec/spec_support/coverage.rb +++ b/lib/template/spec/spec_support/coverage.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # setting ENV["CI"] configures simplecov for continuous integration output # setting ENV["COVERAGE"] generates a report when running tests locally if ENV["COVERAGE"] || ENV["CI"] diff --git a/lib/template/spec/spec_support/log.rb b/lib/template/spec/spec_support/log.rb index 6034b8e6..e6d5d99b 100644 --- a/lib/template/spec/spec_support/log.rb +++ b/lib/template/spec/spec_support/log.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + unless ENV["TEST_LOGS"] == "true" module Pliny module Log diff --git a/pliny.gemspec b/pliny.gemspec index c25b76a7..cfe12051 100644 --- a/pliny.gemspec +++ b/pliny.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $:.unshift File.expand_path("../lib", __FILE__) require "pliny/version" diff --git a/spec/canonical_log_line_helpers_spec.rb b/spec/canonical_log_line_helpers_spec.rb index 0290dec0..12aac07a 100644 --- a/spec/canonical_log_line_helpers_spec.rb +++ b/spec/canonical_log_line_helpers_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::CanonicalLogLineHelpers do diff --git a/spec/commands/creator_spec.rb b/spec/commands/creator_spec.rb index 567c31a7..f89d04a7 100644 --- a/spec/commands/creator_spec.rb +++ b/spec/commands/creator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pliny/commands/creator" require "spec_helper" diff --git a/spec/commands/generator/base_spec.rb b/spec/commands/generator/base_spec.rb index 6b138245..fb1a4d09 100644 --- a/spec/commands/generator/base_spec.rb +++ b/spec/commands/generator/base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/generator' require 'pliny/commands/generator/base' require 'spec_helper' diff --git a/spec/commands/generator/endpoint_spec.rb b/spec/commands/generator/endpoint_spec.rb index f73b7dc9..750c849a 100644 --- a/spec/commands/generator/endpoint_spec.rb +++ b/spec/commands/generator/endpoint_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/generator' require 'pliny/commands/generator/endpoint' require 'spec_helper' diff --git a/spec/commands/generator/mediator_spec.rb b/spec/commands/generator/mediator_spec.rb index 78acf3aa..8a721feb 100644 --- a/spec/commands/generator/mediator_spec.rb +++ b/spec/commands/generator/mediator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/generator/mediator' require 'spec_helper' diff --git a/spec/commands/generator/migration_spec.rb b/spec/commands/generator/migration_spec.rb index 4f421009..4a12a8b2 100644 --- a/spec/commands/generator/migration_spec.rb +++ b/spec/commands/generator/migration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/generator/migration' require 'spec_helper' diff --git a/spec/commands/generator/model_spec.rb b/spec/commands/generator/model_spec.rb index 5ebfe2ca..6f7ede2e 100644 --- a/spec/commands/generator/model_spec.rb +++ b/spec/commands/generator/model_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/generator/model' require 'spec_helper' diff --git a/spec/commands/generator/schema_spec.rb b/spec/commands/generator/schema_spec.rb index 6a48d5e4..f0aa4ba2 100644 --- a/spec/commands/generator/schema_spec.rb +++ b/spec/commands/generator/schema_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/creator' require 'pliny/commands/generator' require 'pliny/commands/generator/schema' diff --git a/spec/commands/generator/serializer_spec.rb b/spec/commands/generator/serializer_spec.rb index 7f0745b8..ffc5d95b 100644 --- a/spec/commands/generator/serializer_spec.rb +++ b/spec/commands/generator/serializer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/generator/serializer' require 'spec_helper' diff --git a/spec/commands/generator_spec.rb b/spec/commands/generator_spec.rb index fffeb398..52803694 100644 --- a/spec/commands/generator_spec.rb +++ b/spec/commands/generator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pliny/commands/creator' require 'pliny/commands/generator' require 'pliny/commands/generator/base' diff --git a/spec/commands/updater_spec.rb b/spec/commands/updater_spec.rb index 8ad79857..57b5b67c 100644 --- a/spec/commands/updater_spec.rb +++ b/spec/commands/updater_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pliny/commands/updater" require "spec_helper" diff --git a/spec/config_helpers_spec.rb b/spec/config_helpers_spec.rb index a61032c0..595838cf 100644 --- a/spec/config_helpers_spec.rb +++ b/spec/config_helpers_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" require "pliny/config_helpers" diff --git a/spec/db_support_spec.rb b/spec/db_support_spec.rb index 6744fc23..ab0909d9 100644 --- a/spec/db_support_spec.rb +++ b/spec/db_support_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" require "pliny/db_support" diff --git a/spec/error_reporters/rollbar_spec.rb b/spec/error_reporters/rollbar_spec.rb index 808f88cf..3a81117c 100644 --- a/spec/error_reporters/rollbar_spec.rb +++ b/spec/error_reporters/rollbar_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" require "rollbar" require "pliny/error_reporters/rollbar" diff --git a/spec/error_reporters_spec.rb b/spec/error_reporters_spec.rb index 5ac9e4e8..7f86c176 100644 --- a/spec/error_reporters_spec.rb +++ b/spec/error_reporters_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::ErrorReporters do diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 2c115aa2..978b656c 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Errors do diff --git a/spec/helpers/encode_spec.rb b/spec/helpers/encode_spec.rb index 8f077756..c69e111b 100644 --- a/spec/helpers/encode_spec.rb +++ b/spec/helpers/encode_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Helpers::Encode do diff --git a/spec/helpers/params_spec.rb b/spec/helpers/params_spec.rb index b6f66e8e..72ac79b8 100644 --- a/spec/helpers/params_spec.rb +++ b/spec/helpers/params_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Helpers::Params do diff --git a/spec/helpers/serialize_spec.rb b/spec/helpers/serialize_spec.rb index c56eaabc..70dedc27 100644 --- a/spec/helpers/serialize_spec.rb +++ b/spec/helpers/serialize_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Helpers::Serialize do diff --git a/spec/helpers/zulu_time_spec.rb b/spec/helpers/zulu_time_spec.rb index d4ca9a01..132fcda8 100644 --- a/spec/helpers/zulu_time_spec.rb +++ b/spec/helpers/zulu_time_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Helpers::ZuluTime do diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index f1997676..c99c733c 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" require "open3" diff --git a/spec/log_spec.rb b/spec/log_spec.rb index bace7e22..10828dd3 100644 --- a/spec/log_spec.rb +++ b/spec/log_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Log do diff --git a/spec/metrics/backends/logger_spec.rb b/spec/metrics/backends/logger_spec.rb index caf91467..1bb0bfd0 100644 --- a/spec/metrics/backends/logger_spec.rb +++ b/spec/metrics/backends/logger_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Metrics::Backends::Logger do diff --git a/spec/metrics_spec.rb b/spec/metrics_spec.rb index 4735437d..18bb341d 100644 --- a/spec/metrics_spec.rb +++ b/spec/metrics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Metrics do diff --git a/spec/middleware/canonical_log_line_spec.rb b/spec/middleware/canonical_log_line_spec.rb index 51888d9e..6f980c22 100644 --- a/spec/middleware/canonical_log_line_spec.rb +++ b/spec/middleware/canonical_log_line_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::CanonicalLogLine do diff --git a/spec/middleware/cors_spec.rb b/spec/middleware/cors_spec.rb index 3dcd246b..7bad0b8e 100644 --- a/spec/middleware/cors_spec.rb +++ b/spec/middleware/cors_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::CORS do diff --git a/spec/middleware/instruments_spec.rb b/spec/middleware/instruments_spec.rb index 8a3626d9..263000f3 100644 --- a/spec/middleware/instruments_spec.rb +++ b/spec/middleware/instruments_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::Instruments do diff --git a/spec/middleware/metrics_spec.rb b/spec/middleware/metrics_spec.rb index 71150555..f4cde43e 100644 --- a/spec/middleware/metrics_spec.rb +++ b/spec/middleware/metrics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::Instruments do diff --git a/spec/middleware/request_id_spec.rb b/spec/middleware/request_id_spec.rb index ca254a95..faf3bdf7 100644 --- a/spec/middleware/request_id_spec.rb +++ b/spec/middleware/request_id_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::RequestID do diff --git a/spec/middleware/request_store/clear_spec.rb b/spec/middleware/request_store/clear_spec.rb index ec7a19f0..7a6f7f14 100644 --- a/spec/middleware/request_store/clear_spec.rb +++ b/spec/middleware/request_store/clear_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::RequestStore::Clear do diff --git a/spec/middleware/request_store/seed_spec.rb b/spec/middleware/request_store/seed_spec.rb index 8f0c709e..8006a2bf 100644 --- a/spec/middleware/request_store/seed_spec.rb +++ b/spec/middleware/request_store/seed_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::RequestStore::Seed do diff --git a/spec/middleware/rescue_errors_spec.rb b/spec/middleware/rescue_errors_spec.rb index 14cb1ccf..e703acf3 100644 --- a/spec/middleware/rescue_errors_spec.rb +++ b/spec/middleware/rescue_errors_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::RescueErrors do diff --git a/spec/middleware/versioning_spec.rb b/spec/middleware/versioning_spec.rb index 8f5b776f..c03b639f 100644 --- a/spec/middleware/versioning_spec.rb +++ b/spec/middleware/versioning_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Middleware::Versioning do diff --git a/spec/request_store_spec.rb b/spec/request_store_spec.rb index 76f4769c..989eb52e 100644 --- a/spec/request_store_spec.rb +++ b/spec/request_store_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::RequestStore do diff --git a/spec/rollbar_logger_spec.rb b/spec/rollbar_logger_spec.rb index 340b5251..069ad3ef 100644 --- a/spec/rollbar_logger_spec.rb +++ b/spec/rollbar_logger_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::RollbarLogger do diff --git a/spec/router_spec.rb b/spec/router_spec.rb index 7a0fc950..b6dd7749 100644 --- a/spec/router_spec.rb +++ b/spec/router_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Pliny::Router do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ec51dfed..564d0b36 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # make sure this is set before Sinatra is required ENV["RACK_ENV"] = "test" diff --git a/spec/support/config.rb b/spec/support/config.rb index 86e48f94..bd2a7672 100644 --- a/spec/support/config.rb +++ b/spec/support/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pliny/config_helpers" # Supress the "use RbConfig instead" warning. diff --git a/spec/support/endpoints.rb b/spec/support/endpoints.rb index d679afb8..2e87e78d 100644 --- a/spec/support/endpoints.rb +++ b/spec/support/endpoints.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # create Endpoints::Base so we can test subclasses generated by Pliny: module Endpoints class Base < Sinatra::Base From 8dbd267fbdae6b645334d9fbb7523396291baf73 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:16:56 +0200 Subject: [PATCH 02/64] fix Layout/LeadingEmptyLines --- .rubocop_todo.yml | 13 ------------ lib/pliny/commands/generator/endpoint.rb | 22 ++++++++++---------- lib/pliny/commands/generator/mediator.rb | 4 ++-- lib/pliny/commands/generator/model.rb | 10 ++++----- lib/pliny/commands/generator/serializer.rb | 4 ++-- lib/template/config/initializers/database.rb | 4 ++-- lib/template/lib/routes.rb | 12 +++++------ 7 files changed, 28 insertions(+), 41 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a931e448..d2d44049 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,19 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 26 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'lib/pliny/commands/generator/endpoint.rb' - - 'lib/pliny/commands/generator/mediator.rb' - - 'lib/pliny/commands/generator/model.rb' - - 'lib/pliny/commands/generator/serializer.rb' - - 'lib/template/config/initializers/database.rb' - - 'lib/template/lib/routes.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleAlignWith, Severity. diff --git a/lib/pliny/commands/generator/endpoint.rb b/lib/pliny/commands/generator/endpoint.rb index 6323f66f..527f368f 100644 --- a/lib/pliny/commands/generator/endpoint.rb +++ b/lib/pliny/commands/generator/endpoint.rb @@ -9,10 +9,10 @@ def create endpoint = "./lib/endpoints/#{pluralized_file_name}.rb" template = options[:scaffold] ? 'endpoint_scaffold.erb' : 'endpoint.erb' write_template(template, endpoint, - plural_class_name: plural_class_name, - singular_class_name: singular_class_name, - field_name: field_name, - url_path: url_path) + plural_class_name: plural_class_name, + singular_class_name: singular_class_name, + field_name: field_name, + url_path: url_path) display "created endpoint file #{endpoint}" display 'add the following to lib/routes.rb:' display " mount Endpoints::#{plural_class_name}" @@ -21,9 +21,9 @@ def create def create_test test = "./spec/endpoints/#{pluralized_file_name}_spec.rb" write_template('endpoint_test.erb', test, - plural_class_name: plural_class_name, - singular_class_name: singular_class_name, - url_path: url_path) + plural_class_name: plural_class_name, + singular_class_name: singular_class_name, + url_path: url_path) display "created test #{test}" end @@ -31,10 +31,10 @@ def create_acceptance_test test = "./spec/acceptance/#{pluralized_file_name}_spec.rb" template = options[:scaffold] ? 'endpoint_scaffold_acceptance_test.erb' : 'endpoint_acceptance_test.erb' write_template(template, test, - plural_class_name: plural_class_name, - field_name: field_name, - singular_class_name: singular_class_name, - url_path: url_path) + plural_class_name: plural_class_name, + field_name: field_name, + singular_class_name: singular_class_name, + url_path: url_path) display "created test #{test}" end diff --git a/lib/pliny/commands/generator/mediator.rb b/lib/pliny/commands/generator/mediator.rb index b7847048..e8734c37 100644 --- a/lib/pliny/commands/generator/mediator.rb +++ b/lib/pliny/commands/generator/mediator.rb @@ -8,14 +8,14 @@ class Mediator < Base def create mediator = "./lib/mediators/#{field_name}.rb" write_template('mediator.erb', mediator, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name) display "created mediator file #{mediator}" end def create_test test = "./spec/mediators/#{field_name}_spec.rb" write_template('mediator_test.erb', test, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name) display "created test #{test}" end end diff --git a/lib/pliny/commands/generator/model.rb b/lib/pliny/commands/generator/model.rb index 758eab71..53fd5ed9 100644 --- a/lib/pliny/commands/generator/model.rb +++ b/lib/pliny/commands/generator/model.rb @@ -8,23 +8,23 @@ class Model < Base def create model = "./lib/models/#{field_name}.rb" write_template('model.erb', model, - singular_class_name: singular_class_name, - paranoid: options[:paranoid]) + singular_class_name: singular_class_name, + paranoid: options[:paranoid]) display "created model file #{model}" end def create_migration migration = "./db/migrate/#{Time.now.to_i}_create_#{table_name}.rb" write_template('model_migration.erb', migration, - table_name: table_name, - paranoid: options[:paranoid]) + table_name: table_name, + paranoid: options[:paranoid]) display "created migration #{migration}" end def create_test test = "./spec/models/#{field_name}_spec.rb" write_template('model_test.erb', test, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name) display "created test #{test}" end end diff --git a/lib/pliny/commands/generator/serializer.rb b/lib/pliny/commands/generator/serializer.rb index 11c39849..08eaa71d 100644 --- a/lib/pliny/commands/generator/serializer.rb +++ b/lib/pliny/commands/generator/serializer.rb @@ -8,14 +8,14 @@ class Serializer < Base def create serializer = "./lib/serializers/#{field_name}.rb" write_template('serializer.erb', serializer, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name) display "created serializer file #{serializer}" end def create_test test = "./spec/serializers/#{field_name}_spec.rb" write_template('serializer_test.erb', test, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name) display "created test #{test}" end end diff --git a/lib/template/config/initializers/database.rb b/lib/template/config/initializers/database.rb index faf4ea0e..49f9cee4 100644 --- a/lib/template/config/initializers/database.rb +++ b/lib/template/config/initializers/database.rb @@ -8,5 +8,5 @@ end DB = Sequel.connect(Config.database_url, - max_connections: Config.db_pool, - after_connect: database_setup_proc) + max_connections: Config.db_pool, + after_connect: database_setup_proc) diff --git a/lib/template/lib/routes.rb b/lib/template/lib/routes.rb index 31bc0145..0bb345d3 100644 --- a/lib/template/lib/routes.rb +++ b/lib/template/lib/routes.rb @@ -8,18 +8,18 @@ use Pliny::Middleware::Metrics use Pliny::Middleware::Instruments use Pliny::Middleware::CanonicalLogLine, - emitter: -> (data) { - Pliny.log_with_default_context({ canonical_log_line: true }.merge(data)) - } + emitter: -> (data) { + Pliny.log_with_default_context({ canonical_log_line: true }.merge(data)) + } use Pliny::Middleware::RescueErrors, raise: Config.raise_errors? if Config.timeout.positive? use Rack::Timeout, - service_timeout: Config.timeout + service_timeout: Config.timeout end if Config.versioning? use Pliny::Middleware::Versioning, - default: Config.versioning_default, - app_name: Config.versioning_app_name + default: Config.versioning_default, + app_name: Config.versioning_app_name end use Rack::Deflater use Rack::MethodOverride From 7b263dd1b687f4b2c9e1d1deb2bdd49567c5d76a Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:19:29 +0200 Subject: [PATCH 03/64] fix Layout/BeginEndAlignment --- .rubocop_todo.yml | 8 -------- spec/log_spec.rb | 3 ++- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d2d44049..604becad 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleAlignWith, Severity. -# SupportedStylesAlignWith: start_of_line, begin -Layout/BeginEndAlignment: - Exclude: - - 'spec/log_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines. diff --git a/spec/log_spec.rb b/spec/log_spec.rb index 10828dd3..567f349b 100644 --- a/spec/log_spec.rb +++ b/spec/log_spec.rb @@ -104,7 +104,8 @@ begin Pliny.log_scrubber = Object.new fail - rescue ArgumentError; end + rescue ArgumentError + end end describe "when a scrubber is present" do From f9041b1463b8d6ecb3db9f6fb4fddb6a59625652 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:20:25 +0200 Subject: [PATCH 04/64] fix Layout/EmptyLineBetweenDefs --- .rubocop_todo.yml | 7 ------- spec/helpers/serialize_spec.rb | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 604becad..2b946ee3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, DefLikeMacros, AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'spec/helpers/serialize_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Layout/EmptyLines: diff --git a/spec/helpers/serialize_spec.rb b/spec/helpers/serialize_spec.rb index 70dedc27..feb0d0dd 100644 --- a/spec/helpers/serialize_spec.rb +++ b/spec/helpers/serialize_spec.rb @@ -24,6 +24,7 @@ def app context "with a serializer" do class Serializer def initialize(opts); end + def serialize(data) data end From 6475b0533f25519efd9249932830dbca018aeb24 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:20:51 +0200 Subject: [PATCH 05/64] fix Layout/EmptyLines --- .rubocop_todo.yml | 6 ------ spec/commands/generator/schema_spec.rb | 1 - 2 files changed, 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2b946ee3..9bffdcf0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLines: - Exclude: - - 'spec/commands/generator/schema_spec.rb' - # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/spec/commands/generator/schema_spec.rb b/spec/commands/generator/schema_spec.rb index f0aa4ba2..c24f2af8 100644 --- a/spec/commands/generator/schema_spec.rb +++ b/spec/commands/generator/schema_spec.rb @@ -18,7 +18,6 @@ end end - describe '#create' do context 'with new layout' do before do From 75d6ad68a3632fcce71f57b404e26b59c9168c5f Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:21:15 +0200 Subject: [PATCH 06/64] fix Layout/EmptyLinesAroundBlockBody --- .rubocop_todo.yml | 10 ---------- spec/commands/generator/endpoint_spec.rb | 1 - spec/config_helpers_spec.rb | 1 - spec/log_spec.rb | 1 - 4 files changed, 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9bffdcf0..7d955198 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,16 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/commands/generator/endpoint_spec.rb' - - 'spec/config_helpers_spec.rb' - - 'spec/log_spec.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/spec/commands/generator/endpoint_spec.rb b/spec/commands/generator/endpoint_spec.rb index 750c849a..226086ef 100644 --- a/spec/commands/generator/endpoint_spec.rb +++ b/spec/commands/generator/endpoint_spec.rb @@ -54,6 +54,5 @@ assert_equal 200, last_response.status assert_equal Hash.new, JSON.parse(last_response.body) end - end end diff --git a/spec/config_helpers_spec.rb b/spec/config_helpers_spec.rb index 595838cf..1408b9e8 100644 --- a/spec/config_helpers_spec.rb +++ b/spec/config_helpers_spec.rb @@ -4,7 +4,6 @@ require "pliny/config_helpers" describe Pliny::CastingConfigHelpers do - describe "#rack_env" do it "is development if app_env is development" do config = Class.new do diff --git a/spec/log_spec.rb b/spec/log_spec.rb index 567f349b..6d4d1181 100644 --- a/spec/log_spec.rb +++ b/spec/log_spec.rb @@ -97,7 +97,6 @@ end describe "scrubbing" do - it "allows a Proc to be assigned as a log scrubber" do Pliny.log_scrubber = -> (hash) { hash } From f49f893227752a05446214356068b47646cbd5f6 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:21:35 +0200 Subject: [PATCH 07/64] fix Layout/EmptyLinesAroundClassBody --- .rubocop_todo.yml | 9 --------- lib/pliny/middleware/cors.rb | 1 - lib/pliny/router.rb | 1 - 3 files changed, 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7d955198..923744ad 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,15 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'lib/pliny/middleware/cors.rb' - - 'lib/pliny/router.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index f74df816..e8f74910 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -2,7 +2,6 @@ module Pliny::Middleware class CORS - ALLOW_METHODS = %w( GET POST PUT PATCH DELETE OPTIONS ).freeze ALLOW_HEADERS = diff --git a/lib/pliny/router.rb b/lib/pliny/router.rb index 60696440..73b2540c 100644 --- a/lib/pliny/router.rb +++ b/lib/pliny/router.rb @@ -4,7 +4,6 @@ module Pliny class Router < Sinatra::Router - # yield to a builder block in which all defined apps will only respond for # the given version def version(*versions, &block) From 1212aebf12c754e20dec0fb354cdc7770740b820 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:21:58 +0200 Subject: [PATCH 08/64] fix Layout/EmptyLinesAroundModuleBody --- .rubocop_todo.yml | 8 -------- lib/pliny/config_helpers.rb | 1 - 2 files changed, 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 923744ad..7e911748 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines -Layout/EmptyLinesAroundModuleBody: - Exclude: - - 'lib/pliny/config_helpers.rb' - # Offense count: 49 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index a6395010..a33e3f8f 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -132,7 +132,6 @@ def self.add_question_method(attr) end end end - end # Supress the "use RbConfig instead" warning From 2183e30cfc018b1a53827eac595c4d40e7063efe Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:22:53 +0200 Subject: [PATCH 09/64] fix Layout/ExtraSpacing --- .rubocop_todo.yml | 15 ------------- lib/pliny/commands/updater.rb | 2 +- lib/pliny/errors.rb | 4 ++-- lib/pliny/middleware/cors.rb | 4 ++-- lib/template/config/config.rb | 32 ++++++++++++++-------------- pliny.gemspec | 12 +++++------ spec/db_support_spec.rb | 16 +++++++------- spec/error_reporters/rollbar_spec.rb | 4 ++-- spec/error_reporters_spec.rb | 4 ++-- spec/integration_spec.rb | 4 ++-- 10 files changed, 41 insertions(+), 56 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7e911748..53d97923 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,21 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 49 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. -Layout/ExtraSpacing: - Exclude: - - 'lib/pliny/commands/updater.rb' - - 'lib/pliny/errors.rb' - - 'lib/pliny/middleware/cors.rb' - - 'lib/template/config/config.rb' - - 'pliny.gemspec' - - 'spec/db_support_spec.rb' - - 'spec/error_reporters/rollbar_spec.rb' - - 'spec/error_reporters_spec.rb' - - 'spec/integration_spec.rb' - # Offense count: 63 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. diff --git a/lib/pliny/commands/updater.rb b/lib/pliny/commands/updater.rb index 7c216cab..b7b49e27 100644 --- a/lib/pliny/commands/updater.rb +++ b/lib/pliny/commands/updater.rb @@ -23,7 +23,7 @@ def run! end version_current = get_current_version - version_target = Gem::Version.new(Pliny::VERSION) + version_target = Gem::Version.new(Pliny::VERSION) if version_current == version_target display "Version #{version_current} is current, nothing to update." diff --git a/lib/pliny/errors.rb b/lib/pliny/errors.rb index a9191287..197321de 100644 --- a/lib/pliny/errors.rb +++ b/lib/pliny/errors.rb @@ -21,9 +21,9 @@ class HTTPStatusError < Error attr_accessor :status def initialize(message = nil, id = nil, status = nil) - meta = Pliny::Errors::META[self.class] + meta = Pliny::Errors::META[self.class] message = message || meta[1] + "." - id = id || meta[1].downcase.tr(' ', '_').to_sym + id = id || meta[1].downcase.tr(' ', '_').to_sym @status = status || meta[0] super(message, id) end diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index e8f74910..e7028f4d 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -2,9 +2,9 @@ module Pliny::Middleware class CORS - ALLOW_METHODS = + ALLOW_METHODS = %w( GET POST PUT PATCH DELETE OPTIONS ).freeze - ALLOW_HEADERS = + ALLOW_HEADERS = %w( Content-Type Accept Authorization Cache-Control If-None-Match If-Modified-Since Origin).freeze EXPOSE_HEADERS = %w( Cache-Control Content-Language Content-Type Expires Last-Modified Pragma ).freeze diff --git a/lib/template/config/config.rb b/lib/template/config/config.rb index e4520635..2406e2ec 100644 --- a/lib/template/config/config.rb +++ b/lib/template/config/config.rb @@ -15,23 +15,23 @@ module Config mandatory :database_url, string # Optional -- value is returned or `nil` if it wasn't present. - optional :app_name, string - optional :versioning_default, string + optional :app_name, string + optional :versioning_default, string optional :versioning_app_name, string # Override -- value is returned or the set default. - override :database_timeout, 10, int - override :db_pool, 5, int - override :deployment, "production", string - override :force_ssl, true, bool - override :app_env, "production", string - override :port, 5000, int - override :pretty_json, false, bool - override :puma_max_threads, 16, int - override :puma_min_threads, 1, int - override :puma_workers, 3, int - override :raise_errors, false, bool - override :root, File.expand_path("../../", __FILE__), string - override :timeout, 10, int - override :versioning, false, bool + override :database_timeout, 10, int + override :db_pool, 5, int + override :deployment, "production", string + override :force_ssl, true, bool + override :app_env, "production", string + override :port, 5000, int + override :pretty_json, false, bool + override :puma_max_threads, 16, int + override :puma_min_threads, 1, int + override :puma_workers, 3, int + override :raise_errors, false, bool + override :root, File.expand_path("../../", __FILE__), string + override :timeout, 10, int + override :versioning, false, bool end diff --git a/pliny.gemspec b/pliny.gemspec index cfe12051..223ead2e 100644 --- a/pliny.gemspec +++ b/pliny.gemspec @@ -4,15 +4,15 @@ $:.unshift File.expand_path("../lib", __FILE__) require "pliny/version" Gem::Specification.new do |gem| - gem.name = "pliny" + gem.name = "pliny" gem.version = Pliny::VERSION - gem.authors = ["Brandur Leach", "Pedro Belo"] - gem.email = ["brandur@mutelight.org", "pedrobelo@gmail.com"] - gem.homepage = "https://github.com/interagent/pliny" - gem.summary = "Basic tooling to support API apps in Sinatra" + gem.authors = ["Brandur Leach", "Pedro Belo"] + gem.email = ["brandur@mutelight.org", "pedrobelo@gmail.com"] + gem.homepage = "https://github.com/interagent/pliny" + gem.summary = "Basic tooling to support API apps in Sinatra" gem.description = "Pliny is a set of base classes and helpers to help developers write excellent APIs in Sinatra" - gem.license = "MIT" + gem.license = "MIT" gem.executables = %x{ git ls-files }.split("\n").select { |d| d =~ /^bin\// }.map { |d| d.gsub(/^bin\//, "") } gem.files = %x{ git ls-files }.split("\n").select { |d| d =~ %r{^(License|README|bin/|data/|ext/|lib/|spec/|test/)} } diff --git a/spec/db_support_spec.rb b/spec/db_support_spec.rb index ab0909d9..5827c4db 100644 --- a/spec/db_support_spec.rb +++ b/spec/db_support_spec.rb @@ -211,7 +211,7 @@ describe '#header' do let(:barrier) { '+--------------+--------------------------------+' } - let(:header) { '| STATUS | MIGRATION |' } + let(:header) { '| STATUS | MIGRATION |' } it 'wraps the title in barriers' do assert_equal [barrier, header, barrier], presenter.header @@ -250,8 +250,8 @@ end describe '#statuses' do - let(:up_expectation) { '| UP | 001630551344_latest_change.rb |' } - let(:down_expectation) { '| DOWN | 01630551344_latest_change.rb |' } + let(:up_expectation) { '| UP | 001630551344_latest_change.rb |' } + let(:down_expectation) { '| DOWN | 01630551344_latest_change.rb |' } let(:file_missing_expectation) { '| FILE MISSING | 0001630551344_latest_change.rb |' } it 'returns strings' do @@ -260,12 +260,12 @@ end describe '#rows' do - let(:barrier) { '+--------------+--------------------------------+' } - let(:header) { '| STATUS | MIGRATION |' } - let(:up_expectation) { '| UP | 001630551344_latest_change.rb |' } - let(:down_expectation) { '| DOWN | 01630551344_latest_change.rb |' } + let(:barrier) { '+--------------+--------------------------------+' } + let(:header) { '| STATUS | MIGRATION |' } + let(:up_expectation) { '| UP | 001630551344_latest_change.rb |' } + let(:down_expectation) { '| DOWN | 01630551344_latest_change.rb |' } let(:file_missing_expectation) { '| FILE MISSING | 0001630551344_latest_change.rb |' } - let(:footer) { '+--------------+--------------------------------+' } + let(:footer) { '+--------------+--------------------------------+' } it 'is the table as an array' do expectation = [ diff --git a/spec/error_reporters/rollbar_spec.rb b/spec/error_reporters/rollbar_spec.rb index 3a81117c..64608ea1 100644 --- a/spec/error_reporters/rollbar_spec.rb +++ b/spec/error_reporters/rollbar_spec.rb @@ -9,8 +9,8 @@ describe "#notify" do let(:exception) { StandardError.new("Something went wrong") } - let(:context) { { step: :foo } } - let(:rack_env) { { "rack.input" => StringIO.new } } + let(:context) { { step: :foo } } + let(:rack_env) { { "rack.input" => StringIO.new } } subject(:notify) do reporter.notify(exception, context: context, rack_env: rack_env) diff --git a/spec/error_reporters_spec.rb b/spec/error_reporters_spec.rb index 7f86c176..64d38d3b 100644 --- a/spec/error_reporters_spec.rb +++ b/spec/error_reporters_spec.rb @@ -9,8 +9,8 @@ describe ".notify" do let(:exception) { RuntimeError.new } - let(:context) { { context: "foo" } } - let(:rack_env) { { rack_env: "bar" } } + let(:context) { { context: "foo" } } + let(:rack_env) { { rack_env: "bar" } } subject(:notify_reporter) do reporter.notify(exception, context: context, rack_env: rack_env) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index c99c733c..1818bf96 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -115,7 +115,7 @@ end def bash_with_output(cmd) - bin = File.expand_path('../bin', File.dirname(__FILE__)) + bin = File.expand_path('../bin', File.dirname(__FILE__)) path = "#{bin}:#{ENV["PATH"]}" env = { "PATH" => path } stdout, stderr, status = Open3.capture3(env, cmd) @@ -128,7 +128,7 @@ def bash_with_output(cmd) end def bash(cmd) - bin = File.expand_path('../bin', File.dirname(__FILE__)) + bin = File.expand_path('../bin', File.dirname(__FILE__)) path = "#{bin}:#{ENV["PATH"]}" env = { "PATH" => path } unless system(env, "#{cmd} > /dev/null") From af980410598e4f16f9a10dcadcd7b22045d08a0b Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:23:25 +0200 Subject: [PATCH 10/64] fix Layout/HashAlignment --- .rubocop_todo.yml | 15 ----- lib/pliny/errors.rb | 80 ++++++++++++------------ lib/pliny/log.rb | 8 +-- lib/pliny/middleware/cors.rb | 10 +-- lib/pliny/middleware/instruments.rb | 12 ++-- spec/commands/generator/endpoint_spec.rb | 2 +- spec/middleware/instruments_spec.rb | 14 ++--- 7 files changed, 63 insertions(+), 78 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 53d97923..d1794b01 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,21 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 63 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'lib/pliny/errors.rb' - - 'lib/pliny/log.rb' - - 'lib/pliny/middleware/cors.rb' - - 'lib/pliny/middleware/instruments.rb' - - 'spec/commands/generator/endpoint_spec.rb' - - 'spec/middleware/instruments_spec.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Layout/HeredocIndentation: diff --git a/lib/pliny/errors.rb b/lib/pliny/errors.rb index 197321de..9905d60d 100644 --- a/lib/pliny/errors.rb +++ b/lib/pliny/errors.rb @@ -73,47 +73,47 @@ class GatewayTimeout < HTTPStatusError; end # 504 # Messages for nicer exceptions, from rfc2616 META = { - Continue => [100, 'Continue'], - SwitchingProtocols => [101, 'Switching protocols'], - OK => [200, 'OK'], - Created => [201, 'Created'], - Accepted => [202, 'Accepted'], - NonAuthoritativeInformation => [203, 'Non-authoritative information'], - NoContent => [204, 'No content'], - ResetContent => [205, 'Reset content'], - PartialContent => [206, 'Partial content'], - MultipleChoices => [300, 'Multiple choices'], - MovedPermanently => [301, 'Moved permanently'], - Found => [302, 'Found'], - SeeOther => [303, 'See other'], - NotModified => [304, 'Not modified'], - UseProxy => [305, 'Use proxy'], - TemporaryRedirect => [307, 'Temporary redirect'], - BadRequest => [400, 'Bad request'], - Unauthorized => [401, 'Unauthorized'], - PaymentRequired => [402, 'Payment required'], - Forbidden => [403, 'Forbidden'], - NotFound => [404, 'Not found'], - MethodNotAllowed => [405, 'Method not allowed'], - NotAcceptable => [406, 'Not acceptable'], - ProxyAuthenticationRequired => [407, 'Proxy authentication required'], - RequestTimeout => [408, 'Request timeout'], - Conflict => [409, 'Conflict'], - Gone => [410, 'Gone'], - LengthRequired => [411, 'Length required'], - PreconditionFailed => [412, 'Precondition failed'], - RequestEntityTooLarge => [413, 'Request entity too large'], - RequestURITooLong => [414, 'Request-URI too long'], - UnsupportedMediaType => [415, 'Unsupported media type'], + Continue => [100, 'Continue'], + SwitchingProtocols => [101, 'Switching protocols'], + OK => [200, 'OK'], + Created => [201, 'Created'], + Accepted => [202, 'Accepted'], + NonAuthoritativeInformation => [203, 'Non-authoritative information'], + NoContent => [204, 'No content'], + ResetContent => [205, 'Reset content'], + PartialContent => [206, 'Partial content'], + MultipleChoices => [300, 'Multiple choices'], + MovedPermanently => [301, 'Moved permanently'], + Found => [302, 'Found'], + SeeOther => [303, 'See other'], + NotModified => [304, 'Not modified'], + UseProxy => [305, 'Use proxy'], + TemporaryRedirect => [307, 'Temporary redirect'], + BadRequest => [400, 'Bad request'], + Unauthorized => [401, 'Unauthorized'], + PaymentRequired => [402, 'Payment required'], + Forbidden => [403, 'Forbidden'], + NotFound => [404, 'Not found'], + MethodNotAllowed => [405, 'Method not allowed'], + NotAcceptable => [406, 'Not acceptable'], + ProxyAuthenticationRequired => [407, 'Proxy authentication required'], + RequestTimeout => [408, 'Request timeout'], + Conflict => [409, 'Conflict'], + Gone => [410, 'Gone'], + LengthRequired => [411, 'Length required'], + PreconditionFailed => [412, 'Precondition failed'], + RequestEntityTooLarge => [413, 'Request entity too large'], + RequestURITooLong => [414, 'Request-URI too long'], + UnsupportedMediaType => [415, 'Unsupported media type'], RequestedRangeNotSatisfiable => [416, 'Requested range not satisfiable'], - ExpectationFailed => [417, 'Expectation failed'], - UnprocessableEntity => [422, 'Unprocessable entity'], - TooManyRequests => [429, 'Too many requests'], - InternalServerError => [500, 'Internal server error'], - NotImplemented => [501, 'Not implemented'], - BadGateway => [502, 'Bad gateway'], - ServiceUnavailable => [503, 'Service unavailable'], - GatewayTimeout => [504, 'Gateway timeout'], + ExpectationFailed => [417, 'Expectation failed'], + UnprocessableEntity => [422, 'Unprocessable entity'], + TooManyRequests => [429, 'Too many requests'], + InternalServerError => [500, 'Internal server error'], + NotImplemented => [501, 'Not implemented'], + BadGateway => [502, 'Bad gateway'], + ServiceUnavailable => [503, 'Service unavailable'], + GatewayTimeout => [504, 'Gateway timeout'], }.freeze end end diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index 6719f808..adf50586 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -22,7 +22,7 @@ def log_exception(e, data = {}) e.backtrace.reverse.each do |backtrace| log_to_stream(stderr || $stderr, merge_log_contexts( exception_id: exception_id, - backtrace: backtrace + backtrace: backtrace )) end end @@ -30,9 +30,9 @@ def log_exception(e, data = {}) # then log the exception message last so that it's as close to the end of # a log trace as possible data.merge!( - exception: true, - class: e.class.name, - message: e.message, + exception: true, + class: e.class.name, + message: e.message, exception_id: exception_id ) diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index e7028f4d..b6fcbe04 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -45,12 +45,12 @@ def allow_headers def cors_headers(env) { - 'access-control-allow-origin' => env["HTTP_ORIGIN"], - 'access-control-allow-methods' => ALLOW_METHODS.join(', '), - 'access-control-allow-headers' => allow_headers.join(', '), + 'access-control-allow-origin' => env["HTTP_ORIGIN"], + 'access-control-allow-methods' => ALLOW_METHODS.join(', '), + 'access-control-allow-headers' => allow_headers.join(', '), 'access-control-allow-credentials' => "true", - 'access-control-max-age' => "1728000", - 'access-control-expose-headers' => EXPOSE_HEADERS.join(', ') + 'access-control-max-age' => "1728000", + 'access-control-expose-headers' => EXPOSE_HEADERS.join(', ') } end end diff --git a/lib/pliny/middleware/instruments.rb b/lib/pliny/middleware/instruments.rb index c1d1744b..a0c1ce31 100644 --- a/lib/pliny/middleware/instruments.rb +++ b/lib/pliny/middleware/instruments.rb @@ -11,8 +11,8 @@ def call(env) data = { instrumentation: true, - method: env["REQUEST_METHOD"], - path: env["PATH_INFO"] + method: env["REQUEST_METHOD"], + path: env["PATH_INFO"] } Pliny.log(data.merge(at: "start")) @@ -25,10 +25,10 @@ def call(env) elapsed = (Time.now - start).to_f Pliny.log(data.merge( - at: "finish", - status: status, - length: headers["Content-Length"], - elapsed: elapsed + at: "finish", + status: status, + length: headers["Content-Length"], + elapsed: elapsed )) [status, headers, response] diff --git a/spec/commands/generator/endpoint_spec.rb b/spec/commands/generator/endpoint_spec.rb index 226086ef..0cdd98bf 100644 --- a/spec/commands/generator/endpoint_spec.rb +++ b/spec/commands/generator/endpoint_spec.rb @@ -19,7 +19,7 @@ # render the stub endpoint template to a string template = subject.render_template("endpoint.erb", plural_class_name: "Artists", - url_path: "/artists") + url_path: "/artists") # eval and assign it to rack_app so tests are pointing to it @rack_app = eval(template) diff --git a/spec/middleware/instruments_spec.rb b/spec/middleware/instruments_spec.rb index 263000f3..d7eae94c 100644 --- a/spec/middleware/instruments_spec.rb +++ b/spec/middleware/instruments_spec.rb @@ -27,17 +27,17 @@ def app it "performs logging" do expect(Pliny).to receive(:log).with(hash_including( instrumentation: true, - at: "start", - method: "GET", - path: "/apps/123", + at: "start", + method: "GET", + path: "/apps/123", )) expect(Pliny).to receive(:log).with(hash_including( instrumentation: true, - at: "finish", - method: "GET", - path: "/apps/123", + at: "finish", + method: "GET", + path: "/apps/123", route_signature: "/apps/:id", - status: 201 + status: 201 )) get "/apps/123" end From b6da89dc92980a921c15523a146ebd3c1e86ff2e Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:23:58 +0200 Subject: [PATCH 11/64] fix Layout/HeredocIndentation --- .rubocop_todo.yml | 7 ------- lib/pliny/middleware/versioning.rb | 4 ++-- spec/middleware/versioning_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d1794b01..e6a7d2f6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Layout/HeredocIndentation: - Exclude: - - 'lib/pliny/middleware/versioning.rb' - - 'spec/middleware/versioning_spec.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Layout/LeadingEmptyLines: diff --git a/lib/pliny/middleware/versioning.rb b/lib/pliny/middleware/versioning.rb index eb76e87d..d2d9f729 100644 --- a/lib/pliny/middleware/versioning.rb +++ b/lib/pliny/middleware/versioning.rb @@ -25,8 +25,8 @@ def detect_api_version(env) media_types.map! do |media_type| if accept_headers.include?(media_type.format) unless media_type.params['version'] - error = { id: :bad_version, message: <<-eos } -Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`. + error = { id: :bad_version, message: <<~eos } + Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`. eos return [400, { "content-type" => "application/json; charset=utf-8" }, [JSON.generate(error)]] diff --git a/spec/middleware/versioning_spec.rb b/spec/middleware/versioning_spec.rb index c03b639f..4962f6b1 100644 --- a/spec/middleware/versioning_spec.rb +++ b/spec/middleware/versioning_spec.rb @@ -30,8 +30,8 @@ def app it "errors without a version specified on application/vnd.pliny+json" do get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json'} - error = { id: :bad_version, message: <<-eos } -Please specify a version along with the MIME type. For example, `Accept: application/vnd.pliny+json; version=1`. + error = { id: :bad_version, message: <<~eos } + Please specify a version along with the MIME type. For example, `Accept: application/vnd.pliny+json; version=1`. eos assert_equal 400, last_response.status From bddd65855a5ed9269af1d530348ed92404c571cf Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:24:44 +0200 Subject: [PATCH 12/64] fix Layout/MultilineMethodCallBraceLayout --- .rubocop_todo.yml | 11 ----------- lib/pliny/log.rb | 6 ++++-- spec/errors_spec.rb | 3 ++- spec/metrics/backends/logger_spec.rb | 6 ++++-- spec/middleware/canonical_log_line_spec.rb | 3 ++- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e6a7d2f6..8747448f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,17 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: symmetrical, new_line, same_line -Layout/MultilineMethodCallBraceLayout: - Exclude: - - 'lib/pliny/log.rb' - - 'spec/errors_spec.rb' - - 'spec/metrics/backends/logger_spec.rb' - - 'spec/middleware/canonical_log_line_spec.rb' - # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index adf50586..a7d2f6b4 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -115,11 +115,13 @@ def log_to_stream(stream, data, &block) begin res = yield log_to_stream(stream, data.merge( - at: "finish", elapsed: (Time.now - start).to_f)) + at: "finish", elapsed: (Time.now - start).to_f + )) res rescue log_to_stream(stream, data.merge( - at: "exception", elapsed: (Time.now - start).to_f)) + at: "exception", elapsed: (Time.now - start).to_f + )) raise $! end end diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 978b656c..faf9432a 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -11,7 +11,8 @@ it "includes an HTTP error that will take generic parameters" do e = Pliny::Errors::HTTPStatusError.new( - "Custom HTTP error.", :custom_http_error, 499) + "Custom HTTP error.", :custom_http_error, 499 + ) assert_equal "Custom HTTP error.", e.message assert_equal :custom_http_error, e.id assert_equal 499, e.status diff --git a/spec/metrics/backends/logger_spec.rb b/spec/metrics/backends/logger_spec.rb index 1bb0bfd0..35250cd1 100644 --- a/spec/metrics/backends/logger_spec.rb +++ b/spec/metrics/backends/logger_spec.rb @@ -27,7 +27,8 @@ it "logs multiple keys with values" do backend.report_counts('app.foo' => 1, 'app.bar' => 2) expect(io).to have_received(:print).with( - "count#app.foo=1 count#app.bar=2\n") + "count#app.foo=1 count#app.bar=2\n", + ) end end @@ -40,7 +41,8 @@ it "logs multiple keys with values" do backend.report_measures('pliny.foo' => 0.3, 'pliny.bar' => 0.5) expect(io).to have_received(:print).with( - "measure#pliny.foo=0.300 measure#pliny.bar=0.500\n") + "measure#pliny.foo=0.300 measure#pliny.bar=0.500\n", + ) end end end diff --git a/spec/middleware/canonical_log_line_spec.rb b/spec/middleware/canonical_log_line_spec.rb index 6f980c22..c3e756f7 100644 --- a/spec/middleware/canonical_log_line_spec.rb +++ b/spec/middleware/canonical_log_line_spec.rb @@ -50,7 +50,8 @@ def app it "never fails a request on failure" do expect(Pliny).to receive(:log).with( - message: "Failed to emit canonical log line") + message: "Failed to emit canonical log line", + ) expect(Pliny).to receive(:log_without_context) { |d| raise "bang!" } get "/apps/123" From 32998a87a0df41d6461920ae7f6449f69221ab58 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:25:05 +0200 Subject: [PATCH 13/64] fix Layout/SpaceAroundEqualsInParameterDefault --- .rubocop_todo.yml | 12 ------------ lib/pliny/config_helpers.rb | 6 +++--- lib/pliny/db_support.rb | 2 +- lib/pliny/middleware/request_store/clear.rb | 2 +- lib/pliny/middleware/request_store/seed.rb | 2 +- lib/pliny/middleware/versioning.rb | 2 +- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8747448f..d16b9699 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,18 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: space, no_space -Layout/SpaceAroundEqualsInParameterDefault: - Exclude: - - 'lib/pliny/config_helpers.rb' - - 'lib/pliny/db_support.rb' - - 'lib/pliny/middleware/request_store/clear.rb' - - 'lib/pliny/middleware/request_store/seed.rb' - - 'lib/pliny/middleware/versioning.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals. diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index a33e3f8f..e6a8db15 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -2,17 +2,17 @@ module Pliny module CastingConfigHelpers - def mandatory(name, method=nil) + def mandatory(name, method = nil) value = cast(ENV.fetch(name.to_s.upcase), method) create(name, value) end - def optional(name, method=nil) + def optional(name, method = nil) value = cast(ENV[name.to_s.upcase], method) create(name, value) end - def override(name, default, method=nil) + def override(name, default, method = nil) value = cast(ENV.fetch(name.to_s.upcase, default), method) create(name, value) end diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index bcf38162..9ba1d5be 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -22,7 +22,7 @@ def self.setup?(database_url) return false end - def self.run(url, sequel_log_io=StringIO.new) + def self.run(url, sequel_log_io = StringIO.new) logger = Logger.new(sequel_log_io) instance = new(url, logger) yield instance diff --git a/lib/pliny/middleware/request_store/clear.rb b/lib/pliny/middleware/request_store/clear.rb index 101e2ddf..e521c005 100644 --- a/lib/pliny/middleware/request_store/clear.rb +++ b/lib/pliny/middleware/request_store/clear.rb @@ -2,7 +2,7 @@ module Pliny::Middleware::RequestStore class Clear - def initialize(app, options={}) + def initialize(app, options = {}) @app = app @store = options[:store] || Pliny::RequestStore end diff --git a/lib/pliny/middleware/request_store/seed.rb b/lib/pliny/middleware/request_store/seed.rb index be0c771d..11cd8b8d 100644 --- a/lib/pliny/middleware/request_store/seed.rb +++ b/lib/pliny/middleware/request_store/seed.rb @@ -2,7 +2,7 @@ module Pliny::Middleware::RequestStore class Seed - def initialize(app, options={}) + def initialize(app, options = {}) @app = app @store = options[:store] || Pliny::RequestStore end diff --git a/lib/pliny/middleware/versioning.rb b/lib/pliny/middleware/versioning.rb index d2d9f729..bd37166d 100644 --- a/lib/pliny/middleware/versioning.rb +++ b/lib/pliny/middleware/versioning.rb @@ -4,7 +4,7 @@ module Pliny::Middleware class Versioning - def initialize(app, options={}) + def initialize(app, options = {}) @app = app @default = options[:default] || raise("missing=default") @app_name = options[:app_name] || raise("missing=app_name") From 017f53e60d91f201c8d92f18a6443f31f1f67d38 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:25:34 +0200 Subject: [PATCH 14/64] fix Layout/SpaceAroundOperators --- .rubocop_todo.yml | 10 ---------- lib/pliny/config_helpers.rb | 2 +- lib/pliny/middleware/metrics.rb | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d16b9699..88303cec 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,16 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals. -# SupportedStylesForExponentOperator: space, no_space -# SupportedStylesForRationalLiterals: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'lib/pliny/config_helpers.rb' - - 'lib/pliny/middleware/metrics.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index e6a8db15..d7fc04cf 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -26,7 +26,7 @@ def float end def bool - ->(v) { v.to_s=='true'} + ->(v) { v.to_s == 'true'} end def string diff --git a/lib/pliny/middleware/metrics.rb b/lib/pliny/middleware/metrics.rb index e31443f9..671b38d3 100644 --- a/lib/pliny/middleware/metrics.rb +++ b/lib/pliny/middleware/metrics.rb @@ -20,7 +20,7 @@ def call(env) elapsed = (Time.now - start).to_f Pliny::Metrics.measure("requests.latency", value: elapsed) - status_level = "#{status/100}xx" + status_level = "#{status / 100}xx" Pliny::Metrics.count("requests.status.#{status_level}") end From f1eba64819bbcd1b1884afa2a7f41547596f8b47 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:26:02 +0200 Subject: [PATCH 15/64] fix Layout/SpaceBeforeBlockBraces --- .rubocop_todo.yml | 9 --------- lib/pliny/config_helpers.rb | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 88303cec..8650b3b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,15 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - Exclude: - - 'lib/pliny/config_helpers.rb' - # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index d7fc04cf..a1a8a526 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -46,7 +46,7 @@ def symbol def array(method = nil) -> (v) do if v - v.split(",").map{|a| cast(a, method) } + v.split(",").map {|a| cast(a, method) } end end end From cbd1b68d18e11bd9a307704c2d6f97a8dcd55134 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:26:30 +0200 Subject: [PATCH 16/64] fix Layout/SpaceInLambdaLiteral --- .rubocop_todo.yml | 11 ----------- lib/pliny/config_helpers.rb | 2 +- lib/template/lib/routes.rb | 2 +- spec/log_spec.rb | 4 ++-- spec/middleware/canonical_log_line_spec.rb | 2 +- 5 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8650b3b3..12bd8224 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,17 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: require_no_space, require_space -Layout/SpaceInLambdaLiteral: - Exclude: - - 'lib/pliny/config_helpers.rb' - - 'lib/template/lib/routes.rb' - - 'spec/log_spec.rb' - - 'spec/middleware/canonical_log_line_spec.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index a1a8a526..72e333aa 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -44,7 +44,7 @@ def symbol # optional :notype, array # => ['a', 'b'] def array(method = nil) - -> (v) do + ->(v) do if v v.split(",").map {|a| cast(a, method) } end diff --git a/lib/template/lib/routes.rb b/lib/template/lib/routes.rb index 0bb345d3..4d59222f 100644 --- a/lib/template/lib/routes.rb +++ b/lib/template/lib/routes.rb @@ -8,7 +8,7 @@ use Pliny::Middleware::Metrics use Pliny::Middleware::Instruments use Pliny::Middleware::CanonicalLogLine, - emitter: -> (data) { + emitter: ->(data) { Pliny.log_with_default_context({ canonical_log_line: true }.merge(data)) } use Pliny::Middleware::RescueErrors, raise: Config.raise_errors? diff --git a/spec/log_spec.rb b/spec/log_spec.rb index 6d4d1181..d1a004d9 100644 --- a/spec/log_spec.rb +++ b/spec/log_spec.rb @@ -98,7 +98,7 @@ describe "scrubbing" do it "allows a Proc to be assigned as a log scrubber" do - Pliny.log_scrubber = -> (hash) { hash } + Pliny.log_scrubber = ->(hash) { hash } begin Pliny.log_scrubber = Object.new @@ -109,7 +109,7 @@ describe "when a scrubber is present" do before do - Pliny.log_scrubber = -> (hash) { + Pliny.log_scrubber = ->(hash) { Hash.new.tap do |h| hash.keys.each do |k| h[k] = "*SCRUBBED*" diff --git a/spec/middleware/canonical_log_line_spec.rb b/spec/middleware/canonical_log_line_spec.rb index c3e756f7..f4f8735f 100644 --- a/spec/middleware/canonical_log_line_spec.rb +++ b/spec/middleware/canonical_log_line_spec.rb @@ -9,7 +9,7 @@ def app use Pliny::Middleware::RequestID use Pliny::Middleware::CanonicalLogLine, - emitter: -> (data) { Pliny.log_without_context(data) } + emitter: ->(data) { Pliny.log_without_context(data) } use Pliny::Middleware::RescueErrors, raise: false From 254d3ad50afb3d85bc4b023a7d5ec7ea91cee603 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:27:50 +0200 Subject: [PATCH 17/64] fix Style/TrailingCommaInArguments --- .rubocop_todo.yml | 21 -------------------- lib/pliny/commands/generator/endpoint.rb | 6 +++--- lib/pliny/commands/generator/mediator.rb | 4 ++-- lib/pliny/commands/generator/model.rb | 6 +++--- lib/pliny/commands/generator/serializer.rb | 4 ++-- lib/pliny/log.rb | 14 ++++++------- lib/pliny/middleware/instruments.rb | 2 +- lib/template/config/initializers/database.rb | 2 +- lib/template/lib/tasks/spec.rake | 2 +- spec/canonical_log_line_helpers_spec.rb | 2 +- spec/commands/generator/endpoint_spec.rb | 2 +- spec/error_reporters/rollbar_spec.rb | 2 +- spec/errors_spec.rb | 2 +- spec/metrics_spec.rb | 16 +++++++-------- spec/middleware/instruments_spec.rb | 4 ++-- 15 files changed, 34 insertions(+), 55 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 12bd8224..741512df 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -347,27 +347,6 @@ Style/StringLiteralsInInterpolation: Exclude: - 'lib/pliny/db_support.rb' -# Offense count: 32 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Exclude: - - 'lib/pliny/commands/generator/endpoint.rb' - - 'lib/pliny/commands/generator/mediator.rb' - - 'lib/pliny/commands/generator/model.rb' - - 'lib/pliny/commands/generator/serializer.rb' - - 'lib/pliny/log.rb' - - 'lib/pliny/middleware/instruments.rb' - - 'lib/template/config/initializers/database.rb' - - 'lib/template/lib/tasks/spec.rake' - - 'spec/canonical_log_line_helpers_spec.rb' - - 'spec/commands/generator/endpoint_spec.rb' - - 'spec/error_reporters/rollbar_spec.rb' - - 'spec/errors_spec.rb' - - 'spec/metrics_spec.rb' - - 'spec/middleware/instruments_spec.rb' - # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleForMultiline. diff --git a/lib/pliny/commands/generator/endpoint.rb b/lib/pliny/commands/generator/endpoint.rb index 527f368f..cb507621 100644 --- a/lib/pliny/commands/generator/endpoint.rb +++ b/lib/pliny/commands/generator/endpoint.rb @@ -12,7 +12,7 @@ def create plural_class_name: plural_class_name, singular_class_name: singular_class_name, field_name: field_name, - url_path: url_path) + url_path: url_path,) display "created endpoint file #{endpoint}" display 'add the following to lib/routes.rb:' display " mount Endpoints::#{plural_class_name}" @@ -23,7 +23,7 @@ def create_test write_template('endpoint_test.erb', test, plural_class_name: plural_class_name, singular_class_name: singular_class_name, - url_path: url_path) + url_path: url_path,) display "created test #{test}" end @@ -34,7 +34,7 @@ def create_acceptance_test plural_class_name: plural_class_name, field_name: field_name, singular_class_name: singular_class_name, - url_path: url_path) + url_path: url_path,) display "created test #{test}" end diff --git a/lib/pliny/commands/generator/mediator.rb b/lib/pliny/commands/generator/mediator.rb index e8734c37..1d6dbf8d 100644 --- a/lib/pliny/commands/generator/mediator.rb +++ b/lib/pliny/commands/generator/mediator.rb @@ -8,14 +8,14 @@ class Mediator < Base def create mediator = "./lib/mediators/#{field_name}.rb" write_template('mediator.erb', mediator, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name,) display "created mediator file #{mediator}" end def create_test test = "./spec/mediators/#{field_name}_spec.rb" write_template('mediator_test.erb', test, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name,) display "created test #{test}" end end diff --git a/lib/pliny/commands/generator/model.rb b/lib/pliny/commands/generator/model.rb index 53fd5ed9..3086c6fb 100644 --- a/lib/pliny/commands/generator/model.rb +++ b/lib/pliny/commands/generator/model.rb @@ -9,7 +9,7 @@ def create model = "./lib/models/#{field_name}.rb" write_template('model.erb', model, singular_class_name: singular_class_name, - paranoid: options[:paranoid]) + paranoid: options[:paranoid],) display "created model file #{model}" end @@ -17,14 +17,14 @@ def create_migration migration = "./db/migrate/#{Time.now.to_i}_create_#{table_name}.rb" write_template('model_migration.erb', migration, table_name: table_name, - paranoid: options[:paranoid]) + paranoid: options[:paranoid],) display "created migration #{migration}" end def create_test test = "./spec/models/#{field_name}_spec.rb" write_template('model_test.erb', test, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name,) display "created test #{test}" end end diff --git a/lib/pliny/commands/generator/serializer.rb b/lib/pliny/commands/generator/serializer.rb index 08eaa71d..48b6da7b 100644 --- a/lib/pliny/commands/generator/serializer.rb +++ b/lib/pliny/commands/generator/serializer.rb @@ -8,14 +8,14 @@ class Serializer < Base def create serializer = "./lib/serializers/#{field_name}.rb" write_template('serializer.erb', serializer, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name,) display "created serializer file #{serializer}" end def create_test test = "./spec/serializers/#{field_name}_spec.rb" write_template('serializer_test.erb', test, - singular_class_name: singular_class_name) + singular_class_name: singular_class_name,) display "created test #{test}" end end diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index a7d2f6b4..67a58251 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -22,8 +22,8 @@ def log_exception(e, data = {}) e.backtrace.reverse.each do |backtrace| log_to_stream(stderr || $stderr, merge_log_contexts( exception_id: exception_id, - backtrace: backtrace - )) + backtrace: backtrace, + ),) end end @@ -33,7 +33,7 @@ def log_exception(e, data = {}) exception: true, class: e.class.name, message: e.message, - exception_id: exception_id + exception_id: exception_id, ) data[:status] = e.status if e.respond_to?(:status) @@ -115,13 +115,13 @@ def log_to_stream(stream, data, &block) begin res = yield log_to_stream(stream, data.merge( - at: "finish", elapsed: (Time.now - start).to_f - )) + at: "finish", elapsed: (Time.now - start).to_f, + ),) res rescue log_to_stream(stream, data.merge( - at: "exception", elapsed: (Time.now - start).to_f - )) + at: "exception", elapsed: (Time.now - start).to_f, + ),) raise $! end end diff --git a/lib/pliny/middleware/instruments.rb b/lib/pliny/middleware/instruments.rb index a0c1ce31..285abe96 100644 --- a/lib/pliny/middleware/instruments.rb +++ b/lib/pliny/middleware/instruments.rb @@ -28,7 +28,7 @@ def call(env) at: "finish", status: status, length: headers["Content-Length"], - elapsed: elapsed + elapsed: elapsed, )) [status, headers, response] diff --git a/lib/template/config/initializers/database.rb b/lib/template/config/initializers/database.rb index 49f9cee4..0b6d5fd1 100644 --- a/lib/template/config/initializers/database.rb +++ b/lib/template/config/initializers/database.rb @@ -9,4 +9,4 @@ DB = Sequel.connect(Config.database_url, max_connections: Config.db_pool, - after_connect: database_setup_proc) + after_connect: database_setup_proc,) diff --git a/lib/template/lib/tasks/spec.rake b/lib/template/lib/tasks/spec.rake index fa1035c1..890cdb67 100644 --- a/lib/template/lib/tasks/spec.rake +++ b/lib/template/lib/tasks/spec.rake @@ -7,7 +7,7 @@ task :spec do require "rspec/core" code = RSpec::Core::Runner.run( ["./spec"], - $stderr, $stdout + $stderr, $stdout, ) exit(code) unless code.zero? end diff --git a/spec/canonical_log_line_helpers_spec.rb b/spec/canonical_log_line_helpers_spec.rb index 12aac07a..5ae7140a 100644 --- a/spec/canonical_log_line_helpers_spec.rb +++ b/spec/canonical_log_line_helpers_spec.rb @@ -36,6 +36,6 @@ class TestCanonicalLogLine line.field_integer = 42 line.field_string = "foo" assert_equal({ field_float: 3.14, field_integer: 42, field_string: "foo" }, - line.to_h) + line.to_h,) end end diff --git a/spec/commands/generator/endpoint_spec.rb b/spec/commands/generator/endpoint_spec.rb index 0cdd98bf..6b8850b9 100644 --- a/spec/commands/generator/endpoint_spec.rb +++ b/spec/commands/generator/endpoint_spec.rb @@ -19,7 +19,7 @@ # render the stub endpoint template to a string template = subject.render_template("endpoint.erb", plural_class_name: "Artists", - url_path: "/artists") + url_path: "/artists",) # eval and assign it to rack_app so tests are pointing to it @rack_app = eval(template) diff --git a/spec/error_reporters/rollbar_spec.rb b/spec/error_reporters/rollbar_spec.rb index 64608ea1..ae2b5e52 100644 --- a/spec/error_reporters/rollbar_spec.rb +++ b/spec/error_reporters/rollbar_spec.rb @@ -31,7 +31,7 @@ notify expect(::Rollbar).to have_received(:scoped).once.with(hash_including( request: instance_of(Proc), - custom: { step: :foo } + custom: { step: :foo }, )) end diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index faf9432a..7f0d8da0 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -11,7 +11,7 @@ it "includes an HTTP error that will take generic parameters" do e = Pliny::Errors::HTTPStatusError.new( - "Custom HTTP error.", :custom_http_error, 499 + "Custom HTTP error.", :custom_http_error, 499, ) assert_equal "Custom HTTP error.", e.message assert_equal :custom_http_error, e.id diff --git a/spec/metrics_spec.rb b/spec/metrics_spec.rb index 18bb341d..9cb1641e 100644 --- a/spec/metrics_spec.rb +++ b/spec/metrics_spec.rb @@ -43,7 +43,7 @@ metrics.count(:foo, :bar) expect(test_backend).to have_received(:report_counts).once.with( "pliny.foo" => 1, - "pliny.bar" => 1 + "pliny.bar" => 1, ) end end @@ -61,7 +61,7 @@ it "measures a block's execution time with a single key" do metrics.measure(:foo) { } expect(test_backend).to have_received(:report_measures).once.with( - "pliny.foo" => 0 + "pliny.foo" => 0, ) end @@ -79,14 +79,14 @@ metrics.measure(:foo, :bar) { } expect(test_backend).to have_received(:report_measures).once.with( "pliny.foo" => 0, - "pliny.bar" => 0 + "pliny.bar" => 0, ) end it "measures a given value for a single key without a block" do metrics.measure(:baz, value: 3.14) expect(test_backend).to have_received(:report_measures).once.with( - "pliny.baz" => 3.14 + "pliny.baz" => 3.14, ) end @@ -94,14 +94,14 @@ metrics.measure(:qux, :corge, value: 42) { } expect(test_backend).to have_received(:report_measures).once.with( "pliny.qux" => 42, - "pliny.corge" => 42 + "pliny.corge" => 42, ) end it "measures a value of 0 when no key or block is provided" do metrics.measure(:waldo) expect(test_backend).to have_received(:report_measures).once.with( - "pliny.waldo" => 0 + "pliny.waldo" => 0, ) end @@ -109,7 +109,7 @@ metrics.measure("metric.name", "another.name", value: 3.14, foo: :bar) expect(test_backend).to have_received(:report_measures).once.with( "pliny.metric.name" => 3.14, - "pliny.another.name" => 3.14 + "pliny.another.name" => 3.14, ) end @@ -117,7 +117,7 @@ metrics.measure("metric.name", "another.name", { value: 3.14, foo: :bar }) expect(test_backend).to have_received(:report_measures).once.with( "pliny.metric.name" => 3.14, - "pliny.another.name" => 3.14 + "pliny.another.name" => 3.14, ) end end diff --git a/spec/middleware/instruments_spec.rb b/spec/middleware/instruments_spec.rb index d7eae94c..b0499b78 100644 --- a/spec/middleware/instruments_spec.rb +++ b/spec/middleware/instruments_spec.rb @@ -37,7 +37,7 @@ def app method: "GET", path: "/apps/123", route_signature: "/apps/:id", - status: 201 + status: 201, )) get "/apps/123" end @@ -45,7 +45,7 @@ def app it "respects Pliny error status codes" do expect(Pliny).to receive(:log) expect(Pliny).to receive(:log).with(hash_including( - status: 404 + status: 404, )) get "/error" end From 3a752f3be119abd35e68699a0942ca6f9f95e9f7 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:28:27 +0200 Subject: [PATCH 18/64] fix Style/StringLiterals --- .rubocop_todo.yml | 49 -------- Rakefile | 8 +- bin/pliny-generate | 2 +- bin/pliny-new | 2 +- bin/pliny-update | 2 +- lib/pliny/commands/creator.rb | 18 +-- lib/pliny/commands/generator.rb | 34 +++--- lib/pliny/commands/generator/base.rb | 18 +-- lib/pliny/commands/generator/endpoint.rb | 12 +- lib/pliny/commands/generator/mediator.rb | 6 +- lib/pliny/commands/generator/migration.rb | 4 +- lib/pliny/commands/generator/model.rb | 8 +- lib/pliny/commands/generator/schema.rb | 4 +- lib/pliny/commands/generator/serializer.rb | 6 +- lib/pliny/config_helpers.rb | 6 +- lib/pliny/error_reporters/rollbar.rb | 4 +- lib/pliny/errors.rb | 84 +++++++------- lib/pliny/helpers/encode.rb | 4 +- lib/pliny/helpers/serialize.rb | 4 +- lib/pliny/middleware/cors.rb | 12 +- lib/pliny/middleware/versioning.rb | 6 +- lib/pliny/rollbar_logger.rb | 8 +- lib/pliny/router.rb | 2 +- lib/pliny/tasks/schema.rake | 2 +- lib/pliny/utils.rb | 2 +- spec/commands/generator/base_spec.rb | 110 +++++++++--------- spec/commands/generator/endpoint_spec.rb | 16 +-- spec/commands/generator/mediator_spec.rb | 18 +-- spec/commands/generator/migration_spec.rb | 10 +- spec/commands/generator/model_spec.rb | 22 ++-- spec/commands/generator/schema_spec.rb | 54 ++++----- spec/commands/generator/serializer_spec.rb | 18 +-- spec/commands/generator_spec.rb | 124 ++++++++++----------- spec/config_helpers_spec.rb | 32 +++--- spec/db_support_spec.rb | 86 +++++++------- spec/integration_spec.rb | 10 +- spec/log_spec.rb | 2 +- spec/metrics/backends/logger_spec.rb | 8 +- spec/metrics_spec.rb | 4 +- spec/middleware/versioning_spec.rb | 34 +++--- spec/rollbar_logger_spec.rb | 18 +-- spec/router_spec.rb | 14 +-- spec/spec_helper.rb | 2 +- 43 files changed, 420 insertions(+), 469 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 741512df..a347ffea 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -290,55 +290,6 @@ Style/SlicingWithRange: - 'lib/pliny/tasks/db.rake' - 'spec/integration_spec.rb' -# Offense count: 477 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'Rakefile' - - 'bin/pliny-generate' - - 'bin/pliny-new' - - 'bin/pliny-update' - - 'lib/pliny/commands/creator.rb' - - 'lib/pliny/commands/generator.rb' - - 'lib/pliny/commands/generator/base.rb' - - 'lib/pliny/commands/generator/endpoint.rb' - - 'lib/pliny/commands/generator/mediator.rb' - - 'lib/pliny/commands/generator/migration.rb' - - 'lib/pliny/commands/generator/model.rb' - - 'lib/pliny/commands/generator/schema.rb' - - 'lib/pliny/commands/generator/serializer.rb' - - 'lib/pliny/config_helpers.rb' - - 'lib/pliny/error_reporters/rollbar.rb' - - 'lib/pliny/errors.rb' - - 'lib/pliny/helpers/encode.rb' - - 'lib/pliny/helpers/serialize.rb' - - 'lib/pliny/middleware/cors.rb' - - 'lib/pliny/middleware/versioning.rb' - - 'lib/pliny/rollbar_logger.rb' - - 'lib/pliny/router.rb' - - 'lib/pliny/tasks/schema.rake' - - 'lib/pliny/utils.rb' - - 'spec/commands/generator/base_spec.rb' - - 'spec/commands/generator/endpoint_spec.rb' - - 'spec/commands/generator/mediator_spec.rb' - - 'spec/commands/generator/migration_spec.rb' - - 'spec/commands/generator/model_spec.rb' - - 'spec/commands/generator/schema_spec.rb' - - 'spec/commands/generator/serializer_spec.rb' - - 'spec/commands/generator_spec.rb' - - 'spec/config_helpers_spec.rb' - - 'spec/db_support_spec.rb' - - 'spec/integration_spec.rb' - - 'spec/log_spec.rb' - - 'spec/metrics/backends/logger_spec.rb' - - 'spec/metrics_spec.rb' - - 'spec/middleware/versioning_spec.rb' - - 'spec/rollbar_logger_spec.rb' - - 'spec/router_spec.rb' - - 'spec/spec_helper.rb' - # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/Rakefile b/Rakefile index 55e51169..a7f54a3b 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,7 @@ $:.unshift File.expand_path("../lib", __FILE__) require "pliny/version" -require 'rspec/core/rake_task' +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task default: :spec @@ -46,9 +46,9 @@ task :release do sh "rm pliny-#{new_version}.gem" end -desc 'Open a irb/pry session preloaded with pliny' +desc "Open a irb/pry session preloaded with pliny" task :console do - require 'pry' - require 'pliny' + require "pry" + require "pliny" Pry.start end diff --git a/bin/pliny-generate b/bin/pliny-generate index b81e5eab..859e2349 100755 --- a/bin/pliny-generate +++ b/bin/pliny-generate @@ -1,5 +1,5 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require_relative '../lib/pliny/commands/generator' +require_relative "../lib/pliny/commands/generator" Pliny::Commands::Generator.start diff --git a/bin/pliny-new b/bin/pliny-new index addef6e7..8101226f 100755 --- a/bin/pliny-new +++ b/bin/pliny-new @@ -2,7 +2,7 @@ # frozen_string_literal: true require "optparse" -require_relative '../lib/pliny/commands/creator' +require_relative "../lib/pliny/commands/creator" OptionParser.new do |options| opts = {} diff --git a/bin/pliny-update b/bin/pliny-update index af730192..8516f2d1 100755 --- a/bin/pliny-update +++ b/bin/pliny-update @@ -2,6 +2,6 @@ # frozen_string_literal: true require "optparse" -require_relative '../lib/pliny/commands/updater' +require_relative "../lib/pliny/commands/updater" Pliny::Commands::Updater.run diff --git a/lib/pliny/commands/creator.rb b/lib/pliny/commands/creator.rb index eeb41b8c..57801497 100644 --- a/lib/pliny/commands/creator.rb +++ b/lib/pliny/commands/creator.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'fileutils' -require 'pathname' -require 'pliny/version' -require 'uri' -require 'erb' -require 'ostruct' +require "fileutils" +require "pathname" +require "pliny/version" +require "uri" +require "erb" +require "ostruct" module Pliny::Commands class Creator @@ -27,7 +27,7 @@ def run! FileUtils.copy_entry template_dir, app_dir FileUtils.rm_rf("#{app_dir}/.git") parse_erb_files - display 'Pliny app created. To start, run:' + display "Pliny app created. To start, run:" display "cd #{app_dir} && bin/setup" end @@ -35,7 +35,7 @@ def run! def parse_erb_files Dir.glob("#{app_dir}/{*,.*}.erb").each do |file| - static_file = file.gsub(/\.erb$/, '') + static_file = file.gsub(/\.erb$/, "") template = ERB.new(File.read(file)) context = OpenStruct.new(app_name: name) @@ -57,7 +57,7 @@ def name end def template_dir - File.expand_path('../../template', File.dirname(__FILE__)) + File.expand_path("../../template", File.dirname(__FILE__)) end def app_dir diff --git a/lib/pliny/commands/generator.rb b/lib/pliny/commands/generator.rb index ad6dc2c5..4a42340f 100644 --- a/lib/pliny/commands/generator.rb +++ b/lib/pliny/commands/generator.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'pliny/version' -require 'thor' +require "pliny/version" +require "thor" module Pliny::Commands class Generator < Thor - desc 'endpoint NAME', 'Generates an endpoint' + desc "endpoint NAME", "Generates an endpoint" method_option :scaffold, type: :boolean, default: false, hide: true def endpoint(name) - require_relative 'generator/endpoint' + require_relative "generator/endpoint" ep = Endpoint.new(name, options) ep.create @@ -16,27 +16,27 @@ def endpoint(name) ep.create_acceptance_test end - desc 'mediator NAME', 'Generates a mediator' + desc "mediator NAME", "Generates a mediator" def mediator(name) - require_relative 'generator/mediator' + require_relative "generator/mediator" md = Mediator.new(name, options) md.create md.create_test end - desc 'migration NAME', 'Generates a migration' + desc "migration NAME", "Generates a migration" def migration(name) - require_relative 'generator/migration' + require_relative "generator/migration" mg = Migration.new(name, options) mg.create end - desc 'model NAME', 'Generates a model' - method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model' + desc "model NAME", "Generates a model" + method_option :paranoid, type: :boolean, default: false, desc: "adds paranoid support to model" def model(name) - require_relative 'generator/model' + require_relative "generator/model" md = Model.new(name, options) md.create @@ -44,8 +44,8 @@ def model(name) md.create_test end - desc 'scaffold NAME', 'Generates a scaffold of endpoint, model, schema and serializer' - method_option :paranoid, type: :boolean, default: false, desc: 'adds paranoid support to model' + desc "scaffold NAME", "Generates a scaffold of endpoint, model, schema and serializer" + method_option :paranoid, type: :boolean, default: false, desc: "adds paranoid support to model" method_option :scaffold, type: :boolean, default: true, hide: true def scaffold(name) endpoint(name) @@ -54,18 +54,18 @@ def scaffold(name) serializer(name) end - desc 'schema NAME', 'Generates a schema' + desc "schema NAME", "Generates a schema" def schema(name) - require_relative 'generator/schema' + require_relative "generator/schema" sc = Schema.new(name, options) sc.create sc.rebuild end - desc 'serializer NAME', 'Generates a serializer' + desc "serializer NAME", "Generates a serializer" def serializer(name) - require_relative 'generator/serializer' + require_relative "generator/serializer" se = Serializer.new(name, options) se.create diff --git a/lib/pliny/commands/generator/base.rb b/lib/pliny/commands/generator/base.rb index de89cc21..06335e7f 100644 --- a/lib/pliny/commands/generator/base.rb +++ b/lib/pliny/commands/generator/base.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'active_support/inflector' -require 'ostruct' -require 'erb' -require 'fileutils' -require 'pliny' +require "active_support/inflector" +require "ostruct" +require "erb" +require "fileutils" +require "pliny" module Pliny::Commands class Generator @@ -34,7 +34,7 @@ def pluralized_file_name end def table_name - name.tableize.tr('/', '_') + name.tableize.tr("/", "_") end def display(msg) @@ -43,7 +43,7 @@ def display(msg) def render_template(template_file, vars = {}) template_path = File.dirname(__FILE__) + "/../../templates/#{template_file}" - template = ERB.new(File.read(template_path), trim_mode: '>') + template = ERB.new(File.read(template_path), trim_mode: ">") context = OpenStruct.new(vars) template.result(context.instance_eval { binding }) end @@ -56,7 +56,7 @@ def write_template(template_file, destination_path, vars = {}) def write_file(destination_path) FileUtils.mkdir_p(File.dirname(destination_path)) - File.open(destination_path, 'w') do |f| + File.open(destination_path, "w") do |f| f.puts yield end end @@ -64,7 +64,7 @@ def write_file(destination_path) private def normalize_name(name) - name.underscore.tr(' ', '_') + name.underscore.tr(" ", "_") end end end diff --git a/lib/pliny/commands/generator/endpoint.rb b/lib/pliny/commands/generator/endpoint.rb index cb507621..80247baf 100644 --- a/lib/pliny/commands/generator/endpoint.rb +++ b/lib/pliny/commands/generator/endpoint.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true -require_relative 'base' +require_relative "base" module Pliny::Commands class Generator class Endpoint < Base def create endpoint = "./lib/endpoints/#{pluralized_file_name}.rb" - template = options[:scaffold] ? 'endpoint_scaffold.erb' : 'endpoint.erb' + template = options[:scaffold] ? "endpoint_scaffold.erb" : "endpoint.erb" write_template(template, endpoint, plural_class_name: plural_class_name, singular_class_name: singular_class_name, field_name: field_name, url_path: url_path,) display "created endpoint file #{endpoint}" - display 'add the following to lib/routes.rb:' + display "add the following to lib/routes.rb:" display " mount Endpoints::#{plural_class_name}" end def create_test test = "./spec/endpoints/#{pluralized_file_name}_spec.rb" - write_template('endpoint_test.erb', test, + write_template("endpoint_test.erb", test, plural_class_name: plural_class_name, singular_class_name: singular_class_name, url_path: url_path,) @@ -29,7 +29,7 @@ def create_test def create_acceptance_test test = "./spec/acceptance/#{pluralized_file_name}_spec.rb" - template = options[:scaffold] ? 'endpoint_scaffold_acceptance_test.erb' : 'endpoint_acceptance_test.erb' + template = options[:scaffold] ? "endpoint_scaffold_acceptance_test.erb" : "endpoint_acceptance_test.erb" write_template(template, test, plural_class_name: plural_class_name, field_name: field_name, @@ -39,7 +39,7 @@ def create_acceptance_test end def url_path - '/' + name.pluralize.tr('_', '-') + "/" + name.pluralize.tr("_", "-") end end end diff --git a/lib/pliny/commands/generator/mediator.rb b/lib/pliny/commands/generator/mediator.rb index 1d6dbf8d..60304f5f 100644 --- a/lib/pliny/commands/generator/mediator.rb +++ b/lib/pliny/commands/generator/mediator.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require_relative 'base' +require_relative "base" module Pliny::Commands class Generator class Mediator < Base def create mediator = "./lib/mediators/#{field_name}.rb" - write_template('mediator.erb', mediator, + write_template("mediator.erb", mediator, singular_class_name: singular_class_name,) display "created mediator file #{mediator}" end def create_test test = "./spec/mediators/#{field_name}_spec.rb" - write_template('mediator_test.erb', test, + write_template("mediator_test.erb", test, singular_class_name: singular_class_name,) display "created test #{test}" end diff --git a/lib/pliny/commands/generator/migration.rb b/lib/pliny/commands/generator/migration.rb index bc3696c7..50e7d337 100644 --- a/lib/pliny/commands/generator/migration.rb +++ b/lib/pliny/commands/generator/migration.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require_relative 'base' +require_relative "base" module Pliny::Commands class Generator class Migration < Base def create migration = "./db/migrate/#{Time.now.to_i}_#{name}.rb" - write_template('migration.erb', migration) + write_template("migration.erb", migration) display "created migration #{migration}" end end diff --git a/lib/pliny/commands/generator/model.rb b/lib/pliny/commands/generator/model.rb index 3086c6fb..fc93c72c 100644 --- a/lib/pliny/commands/generator/model.rb +++ b/lib/pliny/commands/generator/model.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require_relative 'base' +require_relative "base" module Pliny::Commands class Generator class Model < Base def create model = "./lib/models/#{field_name}.rb" - write_template('model.erb', model, + write_template("model.erb", model, singular_class_name: singular_class_name, paranoid: options[:paranoid],) display "created model file #{model}" @@ -15,7 +15,7 @@ def create def create_migration migration = "./db/migrate/#{Time.now.to_i}_create_#{table_name}.rb" - write_template('model_migration.erb', migration, + write_template("model_migration.erb", migration, table_name: table_name, paranoid: options[:paranoid],) display "created migration #{migration}" @@ -23,7 +23,7 @@ def create_migration def create_test test = "./spec/models/#{field_name}_spec.rb" - write_template('model_test.erb', test, + write_template("model_test.erb", test, singular_class_name: singular_class_name,) display "created test #{test}" end diff --git a/lib/pliny/commands/generator/schema.rb b/lib/pliny/commands/generator/schema.rb index 4c8e2daa..62d31f49 100644 --- a/lib/pliny/commands/generator/schema.rb +++ b/lib/pliny/commands/generator/schema.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative 'base' -require 'prmd' +require_relative "base" +require "prmd" module Pliny::Commands class Generator diff --git a/lib/pliny/commands/generator/serializer.rb b/lib/pliny/commands/generator/serializer.rb index 48b6da7b..486bfcbe 100644 --- a/lib/pliny/commands/generator/serializer.rb +++ b/lib/pliny/commands/generator/serializer.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require_relative 'base' +require_relative "base" module Pliny::Commands class Generator class Serializer < Base def create serializer = "./lib/serializers/#{field_name}.rb" - write_template('serializer.erb', serializer, + write_template("serializer.erb", serializer, singular_class_name: singular_class_name,) display "created serializer file #{serializer}" end def create_test test = "./spec/serializers/#{field_name}_spec.rb" - write_template('serializer_test.erb', test, + write_template("serializer_test.erb", test, singular_class_name: singular_class_name,) display "created test #{test}" end diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index 72e333aa..1f2c6765 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -26,7 +26,7 @@ def float end def bool - ->(v) { v.to_s == 'true'} + ->(v) { v.to_s == "true"} end def string @@ -90,10 +90,10 @@ def env # PLINY_ENV is deprecated, but it might be still used by someone. def legacy_env - if ENV.key?('PLINY_ENV') + if ENV.key?("PLINY_ENV") warn "PLINY_ENV is deprecated in favour of APP_ENV, " \ "update .env file or application configuration." - ENV['PLINY_ENV'] + ENV["PLINY_ENV"] end end end diff --git a/lib/pliny/error_reporters/rollbar.rb b/lib/pliny/error_reporters/rollbar.rb index 8ac65653..be4c6792 100644 --- a/lib/pliny/error_reporters/rollbar.rb +++ b/lib/pliny/error_reporters/rollbar.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'rollbar/exception_reporter' -require 'rollbar/request_data_extractor' +require "rollbar/exception_reporter" +require "rollbar/request_data_extractor" module Pliny module ErrorReporters diff --git a/lib/pliny/errors.rb b/lib/pliny/errors.rb index 9905d60d..962ca084 100644 --- a/lib/pliny/errors.rb +++ b/lib/pliny/errors.rb @@ -23,7 +23,7 @@ class HTTPStatusError < Error def initialize(message = nil, id = nil, status = nil) meta = Pliny::Errors::META[self.class] message = message || meta[1] + "." - id = id || meta[1].downcase.tr(' ', '_').to_sym + id = id || meta[1].downcase.tr(" ", "_").to_sym @status = status || meta[0] super(message, id) end @@ -73,47 +73,47 @@ class GatewayTimeout < HTTPStatusError; end # 504 # Messages for nicer exceptions, from rfc2616 META = { - Continue => [100, 'Continue'], - SwitchingProtocols => [101, 'Switching protocols'], - OK => [200, 'OK'], - Created => [201, 'Created'], - Accepted => [202, 'Accepted'], - NonAuthoritativeInformation => [203, 'Non-authoritative information'], - NoContent => [204, 'No content'], - ResetContent => [205, 'Reset content'], - PartialContent => [206, 'Partial content'], - MultipleChoices => [300, 'Multiple choices'], - MovedPermanently => [301, 'Moved permanently'], - Found => [302, 'Found'], - SeeOther => [303, 'See other'], - NotModified => [304, 'Not modified'], - UseProxy => [305, 'Use proxy'], - TemporaryRedirect => [307, 'Temporary redirect'], - BadRequest => [400, 'Bad request'], - Unauthorized => [401, 'Unauthorized'], - PaymentRequired => [402, 'Payment required'], - Forbidden => [403, 'Forbidden'], - NotFound => [404, 'Not found'], - MethodNotAllowed => [405, 'Method not allowed'], - NotAcceptable => [406, 'Not acceptable'], - ProxyAuthenticationRequired => [407, 'Proxy authentication required'], - RequestTimeout => [408, 'Request timeout'], - Conflict => [409, 'Conflict'], - Gone => [410, 'Gone'], - LengthRequired => [411, 'Length required'], - PreconditionFailed => [412, 'Precondition failed'], - RequestEntityTooLarge => [413, 'Request entity too large'], - RequestURITooLong => [414, 'Request-URI too long'], - UnsupportedMediaType => [415, 'Unsupported media type'], - RequestedRangeNotSatisfiable => [416, 'Requested range not satisfiable'], - ExpectationFailed => [417, 'Expectation failed'], - UnprocessableEntity => [422, 'Unprocessable entity'], - TooManyRequests => [429, 'Too many requests'], - InternalServerError => [500, 'Internal server error'], - NotImplemented => [501, 'Not implemented'], - BadGateway => [502, 'Bad gateway'], - ServiceUnavailable => [503, 'Service unavailable'], - GatewayTimeout => [504, 'Gateway timeout'], + Continue => [100, "Continue"], + SwitchingProtocols => [101, "Switching protocols"], + OK => [200, "OK"], + Created => [201, "Created"], + Accepted => [202, "Accepted"], + NonAuthoritativeInformation => [203, "Non-authoritative information"], + NoContent => [204, "No content"], + ResetContent => [205, "Reset content"], + PartialContent => [206, "Partial content"], + MultipleChoices => [300, "Multiple choices"], + MovedPermanently => [301, "Moved permanently"], + Found => [302, "Found"], + SeeOther => [303, "See other"], + NotModified => [304, "Not modified"], + UseProxy => [305, "Use proxy"], + TemporaryRedirect => [307, "Temporary redirect"], + BadRequest => [400, "Bad request"], + Unauthorized => [401, "Unauthorized"], + PaymentRequired => [402, "Payment required"], + Forbidden => [403, "Forbidden"], + NotFound => [404, "Not found"], + MethodNotAllowed => [405, "Method not allowed"], + NotAcceptable => [406, "Not acceptable"], + ProxyAuthenticationRequired => [407, "Proxy authentication required"], + RequestTimeout => [408, "Request timeout"], + Conflict => [409, "Conflict"], + Gone => [410, "Gone"], + LengthRequired => [411, "Length required"], + PreconditionFailed => [412, "Precondition failed"], + RequestEntityTooLarge => [413, "Request entity too large"], + RequestURITooLong => [414, "Request-URI too long"], + UnsupportedMediaType => [415, "Unsupported media type"], + RequestedRangeNotSatisfiable => [416, "Requested range not satisfiable"], + ExpectationFailed => [417, "Expectation failed"], + UnprocessableEntity => [422, "Unprocessable entity"], + TooManyRequests => [429, "Too many requests"], + InternalServerError => [500, "Internal server error"], + NotImplemented => [501, "Not implemented"], + BadGateway => [502, "Bad gateway"], + ServiceUnavailable => [503, "Service unavailable"], + GatewayTimeout => [504, "Gateway timeout"], }.freeze end end diff --git a/lib/pliny/helpers/encode.rb b/lib/pliny/helpers/encode.rb index 7b2c9e99..a81908fc 100644 --- a/lib/pliny/helpers/encode.rb +++ b/lib/pliny/helpers/encode.rb @@ -3,8 +3,8 @@ module Pliny::Helpers module Encode def encode(object) - content_type :json, charset: 'utf-8' - if params[:pretty] == 'true' || Config.pretty_json + content_type :json, charset: "utf-8" + if params[:pretty] == "true" || Config.pretty_json JSON.pretty_generate(object) else JSON.generate(object) diff --git a/lib/pliny/helpers/serialize.rb b/lib/pliny/helpers/serialize.rb index 4afb6b0f..ee2e18dd 100644 --- a/lib/pliny/helpers/serialize.rb +++ b/lib/pliny/helpers/serialize.rb @@ -18,11 +18,11 @@ def serialize(data, structure = :default) eos end - env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1 + env["pliny.serializer_arity"] = data.respond_to?(:size) ? data.size : 1 start = Time.now serializer_class.new(structure).serialize(data).tap do - env['pliny.serializer_timing'] = (Time.now - start).to_f + env["pliny.serializer_timing"] = (Time.now - start).to_f end end end diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index b6fcbe04..bde822ac 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -45,12 +45,12 @@ def allow_headers def cors_headers(env) { - 'access-control-allow-origin' => env["HTTP_ORIGIN"], - 'access-control-allow-methods' => ALLOW_METHODS.join(', '), - 'access-control-allow-headers' => allow_headers.join(', '), - 'access-control-allow-credentials' => "true", - 'access-control-max-age' => "1728000", - 'access-control-expose-headers' => EXPOSE_HEADERS.join(', ') + "access-control-allow-origin" => env["HTTP_ORIGIN"], + "access-control-allow-methods" => ALLOW_METHODS.join(", "), + "access-control-allow-headers" => allow_headers.join(", "), + "access-control-allow-credentials" => "true", + "access-control-max-age" => "1728000", + "access-control-expose-headers" => EXPOSE_HEADERS.join(", ") } end end diff --git a/lib/pliny/middleware/versioning.rb b/lib/pliny/middleware/versioning.rb index bd37166d..a00ff4c7 100644 --- a/lib/pliny/middleware/versioning.rb +++ b/lib/pliny/middleware/versioning.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'http_accept' +require "http_accept" module Pliny::Middleware class Versioning @@ -24,7 +24,7 @@ def detect_api_version(env) version = nil media_types.map! do |media_type| if accept_headers.include?(media_type.format) - unless media_type.params['version'] + unless media_type.params["version"] error = { id: :bad_version, message: <<~eos } Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`. eos @@ -43,7 +43,7 @@ def detect_api_version(env) end media_type.to_s end - env['HTTP_ACCEPT'] = media_types.join(', ') + env["HTTP_ACCEPT"] = media_types.join(", ") version ||= @default set_api_version(env, version) diff --git a/lib/pliny/rollbar_logger.rb b/lib/pliny/rollbar_logger.rb index 1d4ea804..f6cb208a 100644 --- a/lib/pliny/rollbar_logger.rb +++ b/lib/pliny/rollbar_logger.rb @@ -3,19 +3,19 @@ module Pliny class RollbarLogger def debug(message) - log('debug', message) + log("debug", message) end def info(message) - log('info', message) + log("info", message) end def warn(message) - log('warn', message) + log("warn", message) end def error(message) - log('error', message) + log("error", message) end def log(level, message) diff --git a/lib/pliny/router.rb b/lib/pliny/router.rb index 73b2540c..233964f6 100644 --- a/lib/pliny/router.rb +++ b/lib/pliny/router.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'sinatra/router' +require "sinatra/router" module Pliny class Router < Sinatra::Router diff --git a/lib/pliny/tasks/schema.rake b/lib/pliny/tasks/schema.rake index 615bae3c..e20af339 100644 --- a/lib/pliny/tasks/schema.rake +++ b/lib/pliny/tasks/schema.rake @@ -2,6 +2,6 @@ desc "Rebuild schema.json" task :schema do - require 'pliny/commands/generator/schema' + require "pliny/commands/generator/schema" Pliny::Commands::Generator::Schema.new(nil).rebuild end diff --git a/lib/pliny/utils.rb b/lib/pliny/utils.rb index 79298806..4115a356 100644 --- a/lib/pliny/utils.rb +++ b/lib/pliny/utils.rb @@ -5,7 +5,7 @@ module Utils def self.parse_env(file) env = {} File.open(file).each do |line| - line = line.gsub(/#.*$/, '').strip + line = line.gsub(/#.*$/, "").strip next if line.empty? var, value = line.split("=", 2) value.gsub!(/^['"](.*)['"]$/, '\1') diff --git a/spec/commands/generator/base_spec.rb b/spec/commands/generator/base_spec.rb index fb1a4d09..689dd791 100644 --- a/spec/commands/generator/base_spec.rb +++ b/spec/commands/generator/base_spec.rb @@ -1,121 +1,121 @@ # frozen_string_literal: true -require 'pliny/commands/generator' -require 'pliny/commands/generator/base' -require 'spec_helper' +require "pliny/commands/generator" +require "pliny/commands/generator/base" +require "spec_helper" describe Pliny::Commands::Generator::Base do def generator(name, options = {}, stream = StringIO.new) Pliny::Commands::Generator::Base.new(name, options, stream) end - describe '#name' do - it 'generates a normalized name given differents argument formats' do + describe "#name" do + it "generates a normalized name given differents argument formats" do [ - 'resource history', - 'resource-history', - 'resource_history', - 'ResourceHistory' + "resource history", + "resource-history", + "resource_history", + "ResourceHistory" ].each do |argument| actual = generator(argument).name - assert_equal 'resource_history', actual + assert_equal "resource_history", actual end end end - describe '#singular_class_name' do - it 'builds a class name for an endpoint' do - actual = generator('resource_histories').singular_class_name - assert_equal 'ResourceHistory', actual + describe "#singular_class_name" do + it "builds a class name for an endpoint" do + actual = generator("resource_histories").singular_class_name + assert_equal "ResourceHistory", actual end end - describe '#plural_class_name' do - it 'builds a class name for a model' do - actual = generator('resource_histories').plural_class_name - assert_equal 'ResourceHistories', actual + describe "#plural_class_name" do + it "builds a class name for a model" do + actual = generator("resource_histories").plural_class_name + assert_equal "ResourceHistories", actual end end - describe '#field_name' do - it 'uses the singular form' do - actual = generator('resource_histories').field_name - assert_equal 'resource_history', actual + describe "#field_name" do + it "uses the singular form" do + actual = generator("resource_histories").field_name + assert_equal "resource_history", actual end end - describe '#pluralized_file_name' do - it 'uses the plural form' do - actual = generator('resource_history').pluralized_file_name - assert_equal 'resource_histories', actual + describe "#pluralized_file_name" do + it "uses the plural form" do + actual = generator("resource_history").pluralized_file_name + assert_equal "resource_histories", actual end - describe 'when name with slashs' do - it 'handles slashs as directory' do - actual = generator('resource/history').pluralized_file_name - assert_equal 'resource/histories', actual + describe "when name with slashs" do + it "handles slashs as directory" do + actual = generator("resource/history").pluralized_file_name + assert_equal "resource/histories", actual end end end - describe '#table_name' do - it 'uses the plural form' do - actual = generator('resource_history').table_name - assert_equal 'resource_histories', actual + describe "#table_name" do + it "uses the plural form" do + actual = generator("resource_history").table_name + assert_equal "resource_histories", actual end - describe 'when name with slashs' do - it 'handles slashs as underscores' do - actual = generator('resource/history').table_name - assert_equal 'resource_histories', actual + describe "when name with slashs" do + it "handles slashs as underscores" do + actual = generator("resource/history").table_name + assert_equal "resource_histories", actual end end end - describe '#display' do - it 'puts given message into stream' do + describe "#display" do + it "puts given message into stream" do stream = StringIO.new - message = 'Hello world' - generator('resource_history', {}, stream).display(message) + message = "Hello world" + generator("resource_history", {}, stream).display(message) assert_includes stream.string, message end end - describe '#render_template' do - it 'renders template into a string' do - template = generator('resource_history').render_template('endpoint.erb') + describe "#render_template" do + it "renders template into a string" do + template = generator("resource_history").render_template("endpoint.erb") assert_match /module Endpoints/, template end end - describe '#write_template' do - let(:destination_path) { File.join(Dir.mktmpdir, 'endpoint.rb') } + describe "#write_template" do + let(:destination_path) { File.join(Dir.mktmpdir, "endpoint.rb") } before do - generator('resource_history').write_template('endpoint.erb', destination_path) + generator("resource_history").write_template("endpoint.erb", destination_path) end - it 'renders given template into a file by given path' do + it "renders given template into a file by given path" do assert File.exist?(destination_path) assert_match /module Endpoints/, File.read(destination_path) end end - describe '#write_file' do - let(:destination_path) { File.join(Dir.mktmpdir, 'foo.txt') } + describe "#write_file" do + let(:destination_path) { File.join(Dir.mktmpdir, "foo.txt") } before do - generator('resource_history').write_file(destination_path) do - 'Hello world' + generator("resource_history").write_file(destination_path) do + "Hello world" end end - it 'creates a file by given path' do + it "creates a file by given path" do assert File.exist?(destination_path) end - it 'writes given content into a file' do + it "writes given content into a file" do assert_match /Hello world/, File.read(destination_path) end end diff --git a/spec/commands/generator/endpoint_spec.rb b/spec/commands/generator/endpoint_spec.rb index 6b8850b9..317874b1 100644 --- a/spec/commands/generator/endpoint_spec.rb +++ b/spec/commands/generator/endpoint_spec.rb @@ -1,20 +1,20 @@ # frozen_string_literal: true -require 'pliny/commands/generator' -require 'pliny/commands/generator/endpoint' -require 'spec_helper' +require "pliny/commands/generator" +require "pliny/commands/generator/endpoint" +require "spec_helper" describe Pliny::Commands::Generator::Endpoint do subject { Pliny::Commands::Generator::Endpoint.new(endpoint_name, {}, StringIO.new) } - let(:endpoint_name) { 'resource_history' } + let(:endpoint_name) { "resource_history" } - describe '#url_path' do - it 'builds a URL path' do - assert_equal '/resource-histories', subject.url_path + describe "#url_path" do + it "builds a URL path" do + assert_equal "/resource-histories", subject.url_path end end - describe 'template' do + describe "template" do before do # render the stub endpoint template to a string template = subject.render_template("endpoint.erb", diff --git a/spec/commands/generator/mediator_spec.rb b/spec/commands/generator/mediator_spec.rb index 8a721feb..cb9d1a66 100644 --- a/spec/commands/generator/mediator_spec.rb +++ b/spec/commands/generator/mediator_spec.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true -require 'pliny/commands/generator/mediator' -require 'spec_helper' +require "pliny/commands/generator/mediator" +require "spec_helper" describe Pliny::Commands::Generator::Mediator do - subject { described_class.new('creator', {}, StringIO.new) } + subject { described_class.new("creator", {}, StringIO.new) } around do |example| Dir.chdir(Dir.mktmpdir, &example) end - describe '#create' do - it 'creates a mediator file' do + describe "#create" do + it "creates a mediator file" do subject.create - assert File.exist?('lib/mediators/creator.rb') + assert File.exist?("lib/mediators/creator.rb") end end - describe '#create_test' do - it 'creates a mediator test file' do + describe "#create_test" do + it "creates a mediator test file" do subject.create_test - assert File.exist?('spec/mediators/creator_spec.rb') + assert File.exist?("spec/mediators/creator_spec.rb") end end end diff --git a/spec/commands/generator/migration_spec.rb b/spec/commands/generator/migration_spec.rb index 4a12a8b2..4479aa37 100644 --- a/spec/commands/generator/migration_spec.rb +++ b/spec/commands/generator/migration_spec.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'pliny/commands/generator/migration' -require 'spec_helper' +require "pliny/commands/generator/migration" +require "spec_helper" describe Pliny::Commands::Generator::Migration do - subject { described_class.new('create_artists', {}, StringIO.new) } + subject { described_class.new("create_artists", {}, StringIO.new) } around do |example| Dir.chdir(Dir.mktmpdir, &example) end - describe '#create' do - it 'creates a migration file' do + describe "#create" do + it "creates a migration file" do subject.create assert_equal 1, Dir.glob("db/migrate/*_create_artists.rb").size end diff --git a/spec/commands/generator/model_spec.rb b/spec/commands/generator/model_spec.rb index 6f7ede2e..c6225625 100644 --- a/spec/commands/generator/model_spec.rb +++ b/spec/commands/generator/model_spec.rb @@ -1,33 +1,33 @@ # frozen_string_literal: true -require 'pliny/commands/generator/model' -require 'spec_helper' +require "pliny/commands/generator/model" +require "spec_helper" describe Pliny::Commands::Generator::Model do - subject { described_class.new('artist', {}, StringIO.new) } + subject { described_class.new("artist", {}, StringIO.new) } around do |example| Dir.chdir(Dir.mktmpdir, &example) end - describe '#create' do - it 'creates a model file' do + describe "#create" do + it "creates a model file" do subject.create - assert File.exist?('lib/models/artist.rb') + assert File.exist?("lib/models/artist.rb") end end - describe '#create_migration' do - it 'creates a migration file' do + describe "#create_migration" do + it "creates a migration file" do subject.create_migration assert_equal 1, Dir.glob("db/migrate/*_create_artists.rb").size end end - describe '#create_test' do - it 'creates a model test file' do + describe "#create_test" do + it "creates a model test file" do subject.create_test - assert File.exist?('spec/models/artist_spec.rb') + assert File.exist?("spec/models/artist_spec.rb") end end end diff --git a/spec/commands/generator/schema_spec.rb b/spec/commands/generator/schema_spec.rb index c24f2af8..1b77b251 100644 --- a/spec/commands/generator/schema_spec.rb +++ b/spec/commands/generator/schema_spec.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'pliny/commands/creator' -require 'pliny/commands/generator' -require 'pliny/commands/generator/schema' -require 'spec_helper' +require "pliny/commands/creator" +require "pliny/commands/generator" +require "pliny/commands/generator/schema" +require "spec_helper" describe Pliny::Commands::Generator::Schema do let(:stream) { StringIO.new } - subject { Pliny::Commands::Generator::Schema.new('artist', {}, stream) } + subject { Pliny::Commands::Generator::Schema.new("artist", {}, stream) } around do |example| Dir.mktmpdir do |dir| @@ -18,65 +18,65 @@ end end - describe '#create' do - context 'with new layout' do + describe "#create" do + context "with new layout" do before do subject.create end - it 'creates a schema' do - assert File.exist?('schema/schemata/artist.yaml') + it "creates a schema" do + assert File.exist?("schema/schemata/artist.yaml") end end - context 'with legacy layout' do + context "with legacy layout" do before do - FileUtils.mkdir_p('./docs/schema/schemata') - FileUtils.cp('./schema/meta.json', './docs/schema') + FileUtils.mkdir_p("./docs/schema/schemata") + FileUtils.cp("./schema/meta.json", "./docs/schema") subject.create end - it 'creates a legacy schema' do - assert File.exist?('docs/schema/schemata/artist.yaml') + it "creates a legacy schema" do + assert File.exist?("docs/schema/schemata/artist.yaml") end - it 'warns' do + it "warns" do assert_match(/WARNING/m, stream.string) end end end - describe '#rebuild' do - context 'with nil as the name argument (as used in schema.rake)' do - it 'rebuilds the schema with prmd' do + describe "#rebuild" do + context "with nil as the name argument (as used in schema.rake)" do + it "rebuilds the schema with prmd" do assert_output(/rebuilt/) do Pliny::Commands::Generator::Schema.new(nil).rebuild end end end - context 'with new layout' do + context "with new layout" do before do subject.rebuild end - it 'rebuilds schema.json' do - assert File.exist?('./schema/schema.json') + it "rebuilds schema.json" do + assert File.exist?("./schema/schema.json") end end - context 'with legacy layout' do + context "with legacy layout" do before do - FileUtils.mkdir_p('./docs/schema/schemata') - FileUtils.cp('./schema/meta.json', './docs/schema') + FileUtils.mkdir_p("./docs/schema/schemata") + FileUtils.cp("./schema/meta.json", "./docs/schema") subject.rebuild end - it 'rebuilds legacy schema.json' do - assert File.exist?('docs/schema.json') + it "rebuilds legacy schema.json" do + assert File.exist?("docs/schema.json") end - it 'warns' do + it "warns" do assert_match(/WARNING/m, stream.string) end end diff --git a/spec/commands/generator/serializer_spec.rb b/spec/commands/generator/serializer_spec.rb index ffc5d95b..c07db59f 100644 --- a/spec/commands/generator/serializer_spec.rb +++ b/spec/commands/generator/serializer_spec.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true -require 'pliny/commands/generator/serializer' -require 'spec_helper' +require "pliny/commands/generator/serializer" +require "spec_helper" describe Pliny::Commands::Generator::Serializer do - subject { described_class.new('artist', {}, StringIO.new) } + subject { described_class.new("artist", {}, StringIO.new) } around do |example| Dir.chdir(Dir.mktmpdir, &example) end - describe '#create' do - it 'creates a serializer file' do + describe "#create" do + it "creates a serializer file" do subject.create - assert File.exist?('lib/serializers/artist.rb') + assert File.exist?("lib/serializers/artist.rb") end end - describe '#create_test' do - it 'creates a serializer test file' do + describe "#create_test" do + it "creates a serializer test file" do subject.create_test - assert File.exist?('spec/serializers/artist_spec.rb') + assert File.exist?("spec/serializers/artist_spec.rb") end end end diff --git a/spec/commands/generator_spec.rb b/spec/commands/generator_spec.rb index 52803694..0e2803df 100644 --- a/spec/commands/generator_spec.rb +++ b/spec/commands/generator_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'pliny/commands/creator' -require 'pliny/commands/generator' -require 'pliny/commands/generator/base' -require 'spec_helper' +require "pliny/commands/creator" +require "pliny/commands/generator" +require "pliny/commands/generator/base" +require "spec_helper" describe Pliny::Commands::Generator do subject { Pliny::Commands::Generator.new } @@ -27,139 +27,139 @@ Timecop.return end - describe '#endpoint' do + describe "#endpoint" do before do - subject.endpoint('artists') + subject.endpoint("artists") end - it 'creates a new endpoint module' do - assert File.exist?('lib/endpoints/artists.rb') + it "creates a new endpoint module" do + assert File.exist?("lib/endpoints/artists.rb") end - it 'creates an endpoint test' do - assert File.exist?('spec/endpoints/artists_spec.rb') + it "creates an endpoint test" do + assert File.exist?("spec/endpoints/artists_spec.rb") end - it 'creates an endpoint acceptance test' do - assert File.exist?('spec/acceptance/artists_spec.rb') + it "creates an endpoint acceptance test" do + assert File.exist?("spec/acceptance/artists_spec.rb") end end - describe '#mediator' do + describe "#mediator" do before do - subject.mediator('artists/creator') + subject.mediator("artists/creator") end - it 'creates a new mediator module' do - assert File.exist?('lib/mediators/artists/creator.rb') + it "creates a new mediator module" do + assert File.exist?("lib/mediators/artists/creator.rb") end - it 'creates a test' do - assert File.exist?('spec/mediators/artists/creator_spec.rb') + it "creates a test" do + assert File.exist?("spec/mediators/artists/creator_spec.rb") end end - describe '#model' do - describe 'simple model' do + describe "#model" do + describe "simple model" do before do - subject.model('artist') + subject.model("artist") end - it 'creates a migration' do + it "creates a migration" do assert File.exist?("db/migrate/#{@t.to_i}_create_artists.rb") end - it 'creates the actual model' do - assert File.exist?('lib/models/artist.rb') + it "creates the actual model" do + assert File.exist?("lib/models/artist.rb") end - it 'creates a test' do - assert File.exist?('spec/models/artist_spec.rb') + it "creates a test" do + assert File.exist?("spec/models/artist_spec.rb") end end - describe 'model in nested class' do + describe "model in nested class" do before do - subject.model('administration/user') + subject.model("administration/user") end - it 'creates a migration' do + it "creates a migration" do assert File.exist?("db/migrate/#{@t.to_i}_create_administration_users.rb") end - it 'creates the actual model' do - assert File.exist?('lib/models/administration/user.rb') + it "creates the actual model" do + assert File.exist?("lib/models/administration/user.rb") end - it 'creates a test' do - assert File.exist?('spec/models/administration/user_spec.rb') + it "creates a test" do + assert File.exist?("spec/models/administration/user_spec.rb") end end end - describe '#scaffold' do + describe "#scaffold" do before do - subject.scaffold('artist') + subject.scaffold("artist") end - it 'creates a new endpoint module' do - assert File.exist?('lib/endpoints/artists.rb') + it "creates a new endpoint module" do + assert File.exist?("lib/endpoints/artists.rb") end - it 'creates an endpoint test' do - assert File.exist?('spec/endpoints/artists_spec.rb') + it "creates an endpoint test" do + assert File.exist?("spec/endpoints/artists_spec.rb") end - it 'creates an endpoint acceptance test' do - assert File.exist?('spec/acceptance/artists_spec.rb') + it "creates an endpoint acceptance test" do + assert File.exist?("spec/acceptance/artists_spec.rb") end - it 'creates a migration' do + it "creates a migration" do assert File.exist?("db/migrate/#{@t.to_i}_create_artists.rb") end - it 'creates the actual model' do - assert File.exist?('lib/models/artist.rb') + it "creates the actual model" do + assert File.exist?("lib/models/artist.rb") end - it 'creates a test' do - assert File.exist?('spec/models/artist_spec.rb') + it "creates a test" do + assert File.exist?("spec/models/artist_spec.rb") end - it 'creates a schema' do - assert File.exist?('schema/schemata/artist.yaml') + it "creates a schema" do + assert File.exist?("schema/schemata/artist.yaml") end - it 'creates a new serializer module' do - assert File.exist?('lib/serializers/artist.rb') + it "creates a new serializer module" do + assert File.exist?("lib/serializers/artist.rb") end - it 'creates a test' do - assert File.exist?('spec/serializers/artist_spec.rb') + it "creates a test" do + assert File.exist?("spec/serializers/artist_spec.rb") end end - describe '#schema' do + describe "#schema" do before do - subject.schema('artist') + subject.schema("artist") end - it 'creates a schema' do - assert File.exist?('schema/schemata/artist.yaml') + it "creates a schema" do + assert File.exist?("schema/schemata/artist.yaml") end end - describe '#serializer' do + describe "#serializer" do before do - subject.serializer('artist') + subject.serializer("artist") end - it 'creates a new serializer module' do - assert File.exist?('lib/serializers/artist.rb') + it "creates a new serializer module" do + assert File.exist?("lib/serializers/artist.rb") end - it 'creates a test' do - assert File.exist?('spec/serializers/artist_spec.rb') + it "creates a test" do + assert File.exist?("spec/serializers/artist_spec.rb") end end end diff --git a/spec/config_helpers_spec.rb b/spec/config_helpers_spec.rb index 1408b9e8..9ad59f85 100644 --- a/spec/config_helpers_spec.rb +++ b/spec/config_helpers_spec.rb @@ -8,7 +8,7 @@ it "is development if app_env is development" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'development', string + override :app_env, "development", string end assert_equal "development", config.rack_env @@ -17,7 +17,7 @@ it "is development if app_env is test" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'test', string + override :app_env, "test", string end assert_equal "development", config.rack_env @@ -26,7 +26,7 @@ it "is deployment if app_env is production" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'production', string + override :app_env, "production", string end assert_equal "deployment", config.rack_env @@ -35,7 +35,7 @@ it "is deployment if app_env is nil" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, '', string + override :app_env, "", string end assert_equal "deployment", config.rack_env @@ -44,7 +44,7 @@ it "is deployment if app_env is another value" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'staging', string + override :app_env, "staging", string end assert_equal "deployment", config.rack_env @@ -52,18 +52,18 @@ context "when legacy PLINY_ENV is still defined" do before do - ENV['ORIGINAL_PLINY_ENV'] = ENV['PLINY_ENV'] - ENV['PLINY_ENV'] = 'staging' + ENV["ORIGINAL_PLINY_ENV"] = ENV["PLINY_ENV"] + ENV["PLINY_ENV"] = "staging" end after do - ENV['PLINY_ENV'] = ENV.delete('ORIGINAL_PLINY_ENV') + ENV["PLINY_ENV"] = ENV.delete("ORIGINAL_PLINY_ENV") end it "uses PLINY_ENV value instead of APP_ENV" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'development', string + override :app_env, "development", string end assert_equal "deployment", config.rack_env @@ -72,7 +72,7 @@ it "displays deprecation warning" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'development', string + override :app_env, "development", string end io = StringIO.new @@ -89,7 +89,7 @@ it "displays deprecation warning if pliny_env is used" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'development', string + override :app_env, "development", string end io = StringIO.new @@ -103,7 +103,7 @@ it "returns app_env value" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'foo', string + override :app_env, "foo", string end assert_equal "foo", config.pliny_env @@ -111,18 +111,18 @@ context "when legacy PLINY_ENV is still defined" do before do - ENV['ORIGINAL_PLINY_ENV'] = ENV['PLINY_ENV'] - ENV['PLINY_ENV'] = 'staging' + ENV["ORIGINAL_PLINY_ENV"] = ENV["PLINY_ENV"] + ENV["PLINY_ENV"] = "staging" end after do - ENV['PLINY_ENV'] = ENV.delete('ORIGINAL_PLINY_ENV') + ENV["PLINY_ENV"] = ENV.delete("ORIGINAL_PLINY_ENV") end it "returns PLINY_ENV value" do config = Class.new do extend Pliny::CastingConfigHelpers - override :app_env, 'development', string + override :app_env, "development", string end assert_equal "staging", config.pliny_env diff --git a/spec/db_support_spec.rb b/spec/db_support_spec.rb index 5827c4db..7594ff0d 100644 --- a/spec/db_support_spec.rb +++ b/spec/db_support_spec.rb @@ -178,8 +178,8 @@ end end - describe 'MigrationStatusPresenter' do - let(:filename) { '1630551344_latest_change.rb' } + describe "MigrationStatusPresenter" do + let(:filename) { "1630551344_latest_change.rb" } let(:up_migration) { described_class::MigrationStatus.new(filename: "00#{filename}") } let(:down_migration) { described_class::MigrationStatus.new(filename: "0#{filename}") } let(:file_missing_migration) { described_class::MigrationStatus.new(filename: "000#{filename}") } @@ -195,79 +195,79 @@ file_missing_migration.present_on_disk = false end - describe '#barrier_row' do - it 'pads to the longest_migration name' do - expectation = '+--------------+--------------------------------+' + describe "#barrier_row" do + it "pads to the longest_migration name" do + expectation = "+--------------+--------------------------------+" assert_equal expectation, presenter.barrier_row end end - describe '#header_row' do - it 'pads to the longest migration name' do - expectation = '| STATUS | MIGRATION |' + describe "#header_row" do + it "pads to the longest migration name" do + expectation = "| STATUS | MIGRATION |" assert_equal expectation, presenter.header_row end end - describe '#header' do - let(:barrier) { '+--------------+--------------------------------+' } - let(:header) { '| STATUS | MIGRATION |' } + describe "#header" do + let(:barrier) { "+--------------+--------------------------------+" } + let(:header) { "| STATUS | MIGRATION |" } - it 'wraps the title in barriers' do + it "wraps the title in barriers" do assert_equal [barrier, header, barrier], presenter.header end end - describe '#footer' do - let(:barrier) { '+--------------+--------------------------------+' } + describe "#footer" do + let(:barrier) { "+--------------+--------------------------------+" } - it 'just a barrier' do + it "just a barrier" do assert_equal [barrier], presenter.footer end end - describe '#status_row' do - context 'an up migration' do - it 'shows the correct details' do - expectation = '| UP | 001630551344_latest_change.rb |' + describe "#status_row" do + context "an up migration" do + it "shows the correct details" do + expectation = "| UP | 001630551344_latest_change.rb |" assert_equal expectation, presenter.status_row(up_migration) end end - context 'a down migration' do - it 'shows the correct details' do - expectation = '| DOWN | 01630551344_latest_change.rb |' + context "a down migration" do + it "shows the correct details" do + expectation = "| DOWN | 01630551344_latest_change.rb |" assert_equal expectation, presenter.status_row(down_migration) end end - context 'a file missing migration' do - it 'shows the correct details' do - expectation = '| FILE MISSING | 0001630551344_latest_change.rb |' + context "a file missing migration" do + it "shows the correct details" do + expectation = "| FILE MISSING | 0001630551344_latest_change.rb |" assert_equal expectation, presenter.status_row(file_missing_migration) end end end - describe '#statuses' do - let(:up_expectation) { '| UP | 001630551344_latest_change.rb |' } - let(:down_expectation) { '| DOWN | 01630551344_latest_change.rb |' } - let(:file_missing_expectation) { '| FILE MISSING | 0001630551344_latest_change.rb |' } + describe "#statuses" do + let(:up_expectation) { "| UP | 001630551344_latest_change.rb |" } + let(:down_expectation) { "| DOWN | 01630551344_latest_change.rb |" } + let(:file_missing_expectation) { "| FILE MISSING | 0001630551344_latest_change.rb |" } - it 'returns strings' do + it "returns strings" do assert_equal [up_expectation, down_expectation, file_missing_expectation], presenter.statuses end end - describe '#rows' do - let(:barrier) { '+--------------+--------------------------------+' } - let(:header) { '| STATUS | MIGRATION |' } - let(:up_expectation) { '| UP | 001630551344_latest_change.rb |' } - let(:down_expectation) { '| DOWN | 01630551344_latest_change.rb |' } - let(:file_missing_expectation) { '| FILE MISSING | 0001630551344_latest_change.rb |' } - let(:footer) { '+--------------+--------------------------------+' } + describe "#rows" do + let(:barrier) { "+--------------+--------------------------------+" } + let(:header) { "| STATUS | MIGRATION |" } + let(:up_expectation) { "| UP | 001630551344_latest_change.rb |" } + let(:down_expectation) { "| DOWN | 01630551344_latest_change.rb |" } + let(:file_missing_expectation) { "| FILE MISSING | 0001630551344_latest_change.rb |" } + let(:footer) { "+--------------+--------------------------------+" } - it 'is the table as an array' do + it "is the table as an array" do expectation = [ barrier, header, @@ -282,8 +282,8 @@ end end - describe '#to_s' do - it 'is the table as a string' do + describe "#to_s" do + it "is the table as a string" do expectation = <<~OUTPUT.chomp +--------------+--------------------------------+ | STATUS | MIGRATION | @@ -299,8 +299,8 @@ end end - describe '#status' do - let(:filename) { '1630551344_latest_change.rb' } + describe "#status" do + let(:filename) { "1630551344_latest_change.rb" } let(:up_migration) { "00#{filename}" } let(:down_migration) { "0#{filename}" } let(:file_missing_migration) { "000#{filename}" } @@ -341,7 +341,7 @@ end end - it 'returns a table string' do + it "returns a table string" do expectation = <<~OUTPUT.chomp +--------------+--------------------------------+ | STATUS | MIGRATION | diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 1818bf96..1b8d7dee 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -81,7 +81,7 @@ it "returns a migration in the DOWN state when not migrated" do bash "pliny-generate model artist" - migration_file = Dir.glob('db/migrate/*').first + migration_file = Dir.glob("db/migrate/*").first stdout, stderr = bash_with_output("rake db:migrate:status") @@ -91,7 +91,7 @@ it "returns a migration in the UP state when not migrated" do bash "pliny-generate model artist" - migration_file = Dir.glob('db/migrate/*').first + migration_file = Dir.glob("db/migrate/*").first bash "rake db:migrate" stdout, stderr = bash_with_output("rake db:migrate:status") @@ -102,7 +102,7 @@ it "returns a migration in the FILE MISSING state when the file is missing" do bash "pliny-generate model artist" - migration_file = Dir.glob('db/migrate/*').first + migration_file = Dir.glob("db/migrate/*").first bash "rake db:migrate" FileUtils.rm_f(migration_file) @@ -115,7 +115,7 @@ end def bash_with_output(cmd) - bin = File.expand_path('../bin', File.dirname(__FILE__)) + bin = File.expand_path("../bin", File.dirname(__FILE__)) path = "#{bin}:#{ENV["PATH"]}" env = { "PATH" => path } stdout, stderr, status = Open3.capture3(env, cmd) @@ -128,7 +128,7 @@ def bash_with_output(cmd) end def bash(cmd) - bin = File.expand_path('../bin', File.dirname(__FILE__)) + bin = File.expand_path("../bin", File.dirname(__FILE__)) path = "#{bin}:#{ENV["PATH"]}" env = { "PATH" => path } unless system(env, "#{cmd} > /dev/null") diff --git a/spec/log_spec.rb b/spec/log_spec.rb index d1a004d9..070e5fd8 100644 --- a/spec/log_spec.rb +++ b/spec/log_spec.rb @@ -68,7 +68,7 @@ it "local context does not overwrite default context" do Pliny.default_context = { app: "pliny" } expect(@io).to receive(:print).with("app=not_pliny foo=bar\n") - Pliny.log(app: 'not_pliny', foo: "bar") + Pliny.log(app: "not_pliny", foo: "bar") assert Pliny.default_context[:app] == "pliny" end diff --git a/spec/metrics/backends/logger_spec.rb b/spec/metrics/backends/logger_spec.rb index 35250cd1..c898cabc 100644 --- a/spec/metrics/backends/logger_spec.rb +++ b/spec/metrics/backends/logger_spec.rb @@ -20,12 +20,12 @@ context "#count" do it "logs a single key with a value" do - backend.report_counts('app.foo' => 1) + backend.report_counts("app.foo" => 1) expect(io).to have_received(:print).with("count#app.foo=1\n") end it "logs multiple keys with values" do - backend.report_counts('app.foo' => 1, 'app.bar' => 2) + backend.report_counts("app.foo" => 1, "app.bar" => 2) expect(io).to have_received(:print).with( "count#app.foo=1 count#app.bar=2\n", ) @@ -34,12 +34,12 @@ context "#measure" do it "logs a single key with a value" do - backend.report_measures('pliny.foo' => 0.001) + backend.report_measures("pliny.foo" => 0.001) expect(io).to have_received(:print).with("measure#pliny.foo=0.001\n") end it "logs multiple keys with values" do - backend.report_measures('pliny.foo' => 0.3, 'pliny.bar' => 0.5) + backend.report_measures("pliny.foo" => 0.3, "pliny.bar" => 0.5) expect(io).to have_received(:print).with( "measure#pliny.foo=0.300 measure#pliny.bar=0.500\n", ) diff --git a/spec/metrics_spec.rb b/spec/metrics_spec.rb index 9cb1641e..0e5b9ca3 100644 --- a/spec/metrics_spec.rb +++ b/spec/metrics_spec.rb @@ -10,7 +10,7 @@ end before do - allow(Config).to receive(:app_name).and_return('pliny') + allow(Config).to receive(:app_name).and_return("pliny") end around do |example| @@ -71,7 +71,7 @@ end expect(test_backend).to have_received(:report_measures) do |opts| - assert(60 <= opts['pliny.foo'] && opts['pliny.foo'] <= 61) + assert(60 <= opts["pliny.foo"] && opts["pliny.foo"] <= 61) end end diff --git a/spec/middleware/versioning_spec.rb b/spec/middleware/versioning_spec.rb index 4962f6b1..68701f9d 100644 --- a/spec/middleware/versioning_spec.rb +++ b/spec/middleware/versioning_spec.rb @@ -12,7 +12,7 @@ def app Rack::Builder.new do use Rack::Lint - use Pliny::Middleware::Versioning, default: '2', app_name: 'pliny' + use Pliny::Middleware::Versioning, default: "2", app_name: "pliny" run Sinatra.new { get "/" do JSON.generate env @@ -22,14 +22,14 @@ def app end it "produces default version on application/json" do - get '/', {}, {'HTTP_ACCEPT' => 'application/json'} + get "/", {}, {"HTTP_ACCEPT" => "application/json"} json = JSON.parse(last_response.body) - assert_equal 'application/json', json['HTTP_ACCEPT'] - assert_equal '2', json['HTTP_X_API_VERSION'] + assert_equal "application/json", json["HTTP_ACCEPT"] + assert_equal "2", json["HTTP_X_API_VERSION"] end it "errors without a version specified on application/vnd.pliny+json" do - get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json'} + get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json"} error = { id: :bad_version, message: <<~eos } Please specify a version along with the MIME type. For example, `Accept: application/vnd.pliny+json; version=1`. eos @@ -39,31 +39,31 @@ def app end it "ignores a wrong app name" do - get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.chuck_norris+json'} + get "/", {}, {"HTTP_ACCEPT" => "application/vnd.chuck_norris+json"} json = JSON.parse(last_response.body) - assert_equal 'application/vnd.chuck_norris+json', json['HTTP_ACCEPT'] - assert_equal '2', json['HTTP_X_API_VERSION'] + assert_equal "application/vnd.chuck_norris+json", json["HTTP_ACCEPT"] + assert_equal "2", json["HTTP_X_API_VERSION"] end it "produces a version on application/vnd.pliny+json; version=3" do - get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=3'} + get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=3"} json = JSON.parse(last_response.body) - assert_equal 'application/json', json['HTTP_ACCEPT'] - assert_equal '3', json['HTTP_X_API_VERSION'] + assert_equal "application/json", json["HTTP_ACCEPT"] + assert_equal "3", json["HTTP_X_API_VERSION"] end # this behavior is pretty sketchy, but a pretty extreme edge case it "handles multiple MIME types" do - get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=3; q=0.5, text/xml'} + get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=3; q=0.5, text/xml"} json = JSON.parse(last_response.body) - assert_equal 'text/xml, application/json; q=0.5', json['HTTP_ACCEPT'] - assert_equal '3', json['HTTP_X_API_VERSION'] + assert_equal "text/xml, application/json; q=0.5", json["HTTP_ACCEPT"] + assert_equal "3", json["HTTP_X_API_VERSION"] end it "produces the priority version on multiple types" do - get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=4; q=0.5, application/vnd.pliny+json; version=3'} + get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=4; q=0.5, application/vnd.pliny+json; version=3"} json = JSON.parse(last_response.body) - assert_equal 'application/json, application/json; q=0.5', json['HTTP_ACCEPT'] - assert_equal '3', json['HTTP_X_API_VERSION'] + assert_equal "application/json, application/json; q=0.5", json["HTTP_ACCEPT"] + assert_equal "3", json["HTTP_X_API_VERSION"] end end diff --git a/spec/rollbar_logger_spec.rb b/spec/rollbar_logger_spec.rb index 069ad3ef..0094f612 100644 --- a/spec/rollbar_logger_spec.rb +++ b/spec/rollbar_logger_spec.rb @@ -5,39 +5,39 @@ describe Pliny::RollbarLogger do subject(:logger) { Pliny::RollbarLogger.new } - let(:message) { 'hello world' } + let(:message) { "hello world" } let(:log_context) { { rollbar: true, level: level, message: message } } before do expect(Pliny).to receive(:log).with(log_context) end - context '#debug' do - let(:level) { 'debug' } + context "#debug" do + let(:level) { "debug" } it "proxies the debug log level" do logger.debug(message) end end - context '#info' do - let(:level) { 'info' } + context "#info" do + let(:level) { "info" } it "proxies the info log level" do logger.info(message) end end - context '#warn' do - let(:level) { 'warn' } + context "#warn" do + let(:level) { "warn" } it "proxies the warn log level" do logger.warn(message) end end - context '#error' do - let(:level) { 'error' } + context "#error" do + let(:level) { "error" } it "proxies the error log level" do logger.error(message) diff --git a/spec/router_spec.rb b/spec/router_spec.rb index b6dd7749..89e1f41b 100644 --- a/spec/router_spec.rb +++ b/spec/router_spec.rb @@ -7,12 +7,12 @@ def app Rack::Builder.new do use Rack::Lint - use Pliny::Middleware::Versioning, default: '2', app_name: 'pliny' + use Pliny::Middleware::Versioning, default: "2", app_name: "pliny" use Pliny::Router do - version '3' do + version "3" do mount Sinatra.new { - get '/' do + get "/" do "API V3" end } @@ -28,13 +28,13 @@ def app end it "should not run on any api" do - get '/' - assert_equal 'No API', last_response.body + get "/" + assert_equal "No API", last_response.body end it "should run on API V3" do - get '/', {}, {'HTTP_ACCEPT' => 'application/vnd.pliny+json; version=3'} - assert_equal 'API V3', last_response.body + get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=3"} + assert_equal "API V3", last_response.body end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 564d0b36..b2595c09 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,7 +37,7 @@ # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 - config.order = 'random' + config.order = "random" # the rack app to be tested with rack-test: def app From 8f68130d77a0e00e5e64a6c42c26683cd1411f64 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:28:57 +0200 Subject: [PATCH 19/64] fix Layout/SpaceInsideArrayLiteralBrackets --- .rubocop_todo.yml | 9 --------- lib/pliny/metrics/backends/logger.rb | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a347ffea..d2798a2b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,15 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBrackets: space, no_space -Layout/SpaceInsideArrayLiteralBrackets: - Exclude: - - 'lib/pliny/metrics/backends/logger.rb' - # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. diff --git a/lib/pliny/metrics/backends/logger.rb b/lib/pliny/metrics/backends/logger.rb index c0d054d1..995ea93d 100644 --- a/lib/pliny/metrics/backends/logger.rb +++ b/lib/pliny/metrics/backends/logger.rb @@ -15,7 +15,7 @@ def self.report_measures(measures) private def self.add_prefix(type, metrics) - metrics.map { |k, v| [ "#{type}##{k}", v ] }.to_h + metrics.map { |k, v| ["#{type}##{k}", v] }.to_h end end end From 99cef239700260737827a546d8a2801cde41b718 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:31:23 +0200 Subject: [PATCH 20/64] fix Layout/SpaceInsideBlockBraces --- .rubocop_todo.yml | 10 ---------- lib/pliny/config_helpers.rb | 4 ++-- spec/metrics_spec.rb | 6 +++--- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d2798a2b..8cbb1932 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,16 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/pliny/config_helpers.rb' - - 'spec/metrics_spec.rb' - # Offense count: 39 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index 1f2c6765..bb846e12 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -26,7 +26,7 @@ def float end def bool - ->(v) { v.to_s == "true"} + ->(v) { v.to_s == "true" } end def string @@ -46,7 +46,7 @@ def symbol def array(method = nil) ->(v) do if v - v.split(",").map {|a| cast(a, method) } + v.split(",").map { |a| cast(a, method) } end end end diff --git a/spec/metrics_spec.rb b/spec/metrics_spec.rb index 0e5b9ca3..cc05d778 100644 --- a/spec/metrics_spec.rb +++ b/spec/metrics_spec.rb @@ -59,7 +59,7 @@ end it "measures a block's execution time with a single key" do - metrics.measure(:foo) { } + metrics.measure(:foo) {} expect(test_backend).to have_received(:report_measures).once.with( "pliny.foo" => 0, ) @@ -76,7 +76,7 @@ end it "measures a block's execution time with multiple keys" do - metrics.measure(:foo, :bar) { } + metrics.measure(:foo, :bar) {} expect(test_backend).to have_received(:report_measures).once.with( "pliny.foo" => 0, "pliny.bar" => 0, @@ -91,7 +91,7 @@ end it "measures a given value for multiple keys with a block" do - metrics.measure(:qux, :corge, value: 42) { } + metrics.measure(:qux, :corge, value: 42) {} expect(test_backend).to have_received(:report_measures).once.with( "pliny.qux" => 42, "pliny.corge" => 42, From fbcb43b9118814e0d4654d8c8d93fdd2a49b20f1 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:31:44 +0200 Subject: [PATCH 21/64] fix Layout/SpaceInsideHashLiteralBraces --- .rubocop_todo.yml | 12 ------------ spec/error_reporters/rollbar_spec.rb | 4 ++-- spec/helpers/params_spec.rb | 12 ++++++------ spec/middleware/versioning_spec.rb | 12 ++++++------ spec/router_spec.rb | 2 +- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8cbb1932..a93625b9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,18 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 39 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'spec/error_reporters/rollbar_spec.rb' - - 'spec/helpers/params_spec.rb' - - 'spec/middleware/versioning_spec.rb' - - 'spec/router_spec.rb' - # Offense count: 9 # This cop supports safe autocorrection (--autocorrect). Layout/SpaceInsidePercentLiteralDelimiters: diff --git a/spec/error_reporters/rollbar_spec.rb b/spec/error_reporters/rollbar_spec.rb index ae2b5e52..8b94eb0d 100644 --- a/spec/error_reporters/rollbar_spec.rb +++ b/spec/error_reporters/rollbar_spec.rb @@ -41,7 +41,7 @@ id: SecureRandom.uuid, email: "foo@bar.com", username: "foo" - }} + } } end it "adds person to the rollbar notification" do @@ -68,7 +68,7 @@ it "reports to Rollbar without request data in the scope" do notify - expect(Rollbar).to have_received(:scoped).once.with({ custom: {step: :foo} }) + expect(Rollbar).to have_received(:scoped).once.with({ custom: { step: :foo } }) end it "delegates to #report_exception_to_rollbar" do diff --git a/spec/helpers/params_spec.rb b/spec/helpers/params_spec.rb index 72ac79b8..709331cf 100644 --- a/spec/helpers/params_spec.rb +++ b/spec/helpers/params_spec.rb @@ -13,33 +13,33 @@ def app end it "loads json params" do - post "/", {hello: "world"}.to_json, {"CONTENT_TYPE" => "application/json"} + post "/", { hello: "world" }.to_json, { "CONTENT_TYPE" => "application/json" } assert_equal "{\"hello\":\"world\"}", last_response.body end it "loads json array of params" do - post "/", [{hello: "world"}, {goodbye: "moon"}].to_json, {"CONTENT_TYPE" => "application/json"} + post "/", [{ hello: "world" }, { goodbye: "moon" }].to_json, { "CONTENT_TYPE" => "application/json" } assert_equal "[{\"hello\":\"world\"},{\"goodbye\":\"moon\"}]", last_response.body end it "loads json array of arrays of params" do - post "/", [[{hello: "world"}], [{goodbye: "moon"}]].to_json, {"CONTENT_TYPE" => "application/json"} + post "/", [[{ hello: "world" }], [{ goodbye: "moon" }]].to_json, { "CONTENT_TYPE" => "application/json" } assert_equal "[[{\"hello\":\"world\"}],[{\"goodbye\":\"moon\"}]]", last_response.body end it "loads form data params" do - post "/", {hello: "world"} + post "/", { hello: "world" } assert_equal "{\"hello\":\"world\"}", last_response.body end it "loads from an unknown content type" do - post "/", "world", {"CONTENT_TYPE" => "application/xml"} + post "/", "world", { "CONTENT_TYPE" => "application/xml" } assert_equal "{}", last_response.body end it "should throw bad request when receiving invalid json via post" do err = assert_raises(Pliny::Errors::BadRequest) do - post "/", "{\"foo\"}", {"CONTENT_TYPE" => "application/json"} + post "/", "{\"foo\"}", { "CONTENT_TYPE" => "application/json" } end assert_match /expected ':' after object key at line 1 column 7/, err.message diff --git a/spec/middleware/versioning_spec.rb b/spec/middleware/versioning_spec.rb index 68701f9d..f0f36552 100644 --- a/spec/middleware/versioning_spec.rb +++ b/spec/middleware/versioning_spec.rb @@ -22,14 +22,14 @@ def app end it "produces default version on application/json" do - get "/", {}, {"HTTP_ACCEPT" => "application/json"} + get "/", {}, { "HTTP_ACCEPT" => "application/json" } json = JSON.parse(last_response.body) assert_equal "application/json", json["HTTP_ACCEPT"] assert_equal "2", json["HTTP_X_API_VERSION"] end it "errors without a version specified on application/vnd.pliny+json" do - get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json"} + get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json" } error = { id: :bad_version, message: <<~eos } Please specify a version along with the MIME type. For example, `Accept: application/vnd.pliny+json; version=1`. eos @@ -39,14 +39,14 @@ def app end it "ignores a wrong app name" do - get "/", {}, {"HTTP_ACCEPT" => "application/vnd.chuck_norris+json"} + get "/", {}, { "HTTP_ACCEPT" => "application/vnd.chuck_norris+json" } json = JSON.parse(last_response.body) assert_equal "application/vnd.chuck_norris+json", json["HTTP_ACCEPT"] assert_equal "2", json["HTTP_X_API_VERSION"] end it "produces a version on application/vnd.pliny+json; version=3" do - get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=3"} + get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json; version=3" } json = JSON.parse(last_response.body) assert_equal "application/json", json["HTTP_ACCEPT"] assert_equal "3", json["HTTP_X_API_VERSION"] @@ -54,14 +54,14 @@ def app # this behavior is pretty sketchy, but a pretty extreme edge case it "handles multiple MIME types" do - get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=3; q=0.5, text/xml"} + get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json; version=3; q=0.5, text/xml" } json = JSON.parse(last_response.body) assert_equal "text/xml, application/json; q=0.5", json["HTTP_ACCEPT"] assert_equal "3", json["HTTP_X_API_VERSION"] end it "produces the priority version on multiple types" do - get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=4; q=0.5, application/vnd.pliny+json; version=3"} + get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json; version=4; q=0.5, application/vnd.pliny+json; version=3" } json = JSON.parse(last_response.body) assert_equal "application/json, application/json; q=0.5", json["HTTP_ACCEPT"] assert_equal "3", json["HTTP_X_API_VERSION"] diff --git a/spec/router_spec.rb b/spec/router_spec.rb index 89e1f41b..8030cf45 100644 --- a/spec/router_spec.rb +++ b/spec/router_spec.rb @@ -33,7 +33,7 @@ def app end it "should run on API V3" do - get "/", {}, {"HTTP_ACCEPT" => "application/vnd.pliny+json; version=3"} + get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json; version=3" } assert_equal "API V3", last_response.body end end From d8a5e7a6341be5611ef191d7e264c921329fd4dd Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:32:10 +0200 Subject: [PATCH 22/64] fix Layout/SpaceInsidePercentLiteralDelimiters --- .rubocop_todo.yml | 7 ------- lib/pliny/middleware/cors.rb | 6 +++--- pliny.gemspec | 4 ++-- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a93625b9..6987c101 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,13 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 9 -# This cop supports safe autocorrection (--autocorrect). -Layout/SpaceInsidePercentLiteralDelimiters: - Exclude: - - 'lib/pliny/middleware/cors.rb' - - 'pliny.gemspec' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowInHeredoc. diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index bde822ac..be62bee1 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -3,11 +3,11 @@ module Pliny::Middleware class CORS ALLOW_METHODS = - %w( GET POST PUT PATCH DELETE OPTIONS ).freeze + %w(GET POST PUT PATCH DELETE OPTIONS).freeze ALLOW_HEADERS = - %w( Content-Type Accept Authorization Cache-Control If-None-Match If-Modified-Since Origin).freeze + %w(Content-Type Accept Authorization Cache-Control If-None-Match If-Modified-Since Origin).freeze EXPOSE_HEADERS = - %w( Cache-Control Content-Language Content-Type Expires Last-Modified Pragma ).freeze + %w(Cache-Control Content-Language Content-Type Expires Last-Modified Pragma).freeze @@additional_headers = [] diff --git a/pliny.gemspec b/pliny.gemspec index 223ead2e..e2a9b45f 100644 --- a/pliny.gemspec +++ b/pliny.gemspec @@ -14,8 +14,8 @@ Gem::Specification.new do |gem| gem.description = "Pliny is a set of base classes and helpers to help developers write excellent APIs in Sinatra" gem.license = "MIT" - gem.executables = %x{ git ls-files }.split("\n").select { |d| d =~ /^bin\// }.map { |d| d.gsub(/^bin\//, "") } - gem.files = %x{ git ls-files }.split("\n").select { |d| d =~ %r{^(License|README|bin/|data/|ext/|lib/|spec/|test/)} } + gem.executables = %x{git ls-files}.split("\n").select { |d| d =~ /^bin\// }.map { |d| d.gsub(/^bin\//, "") } + gem.files = %x{git ls-files}.split("\n").select { |d| d =~ %r{^(License|README|bin/|data/|ext/|lib/|spec/|test/)} } gem.required_ruby_version = ">= 3.2" From 808ca800a1a8c46f18f3ad03dfaf27fa06fff3c9 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:32:28 +0200 Subject: [PATCH 23/64] fix Layout/TrailingWhitespace --- .rubocop_todo.yml | 7 ------- spec/commands/generator/base_spec.rb | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6987c101..1adf7f38 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,13 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'spec/commands/generator/base_spec.rb' - # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). Lint/AmbiguousRegexpLiteral: diff --git a/spec/commands/generator/base_spec.rb b/spec/commands/generator/base_spec.rb index 689dd791..d88dc24b 100644 --- a/spec/commands/generator/base_spec.rb +++ b/spec/commands/generator/base_spec.rb @@ -101,7 +101,7 @@ def generator(name, options = {}, stream = StringIO.new) assert_match /module Endpoints/, File.read(destination_path) end end - + describe "#write_file" do let(:destination_path) { File.join(Dir.mktmpdir, "foo.txt") } From c2279f7f59074c4802deb8cdfb7dc241aaa456fa Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:32:57 +0200 Subject: [PATCH 24/64] fix Lint/AmbiguousRegexpLiteral --- .rubocop_todo.yml | 7 ------- spec/commands/generator/base_spec.rb | 6 +++--- spec/helpers/params_spec.rb | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1adf7f38..d946f875 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,13 +13,6 @@ Layout/LeadingEmptyLines: - 'lib/template/Rakefile' - 'lib/template/lib/tasks/spec.rake' -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Lint/AmbiguousRegexpLiteral: - Exclude: - - 'spec/commands/generator/base_spec.rb' - - 'spec/helpers/params_spec.rb' - # Offense count: 6 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSafeAssignment. diff --git a/spec/commands/generator/base_spec.rb b/spec/commands/generator/base_spec.rb index d88dc24b..b43cddcc 100644 --- a/spec/commands/generator/base_spec.rb +++ b/spec/commands/generator/base_spec.rb @@ -85,7 +85,7 @@ def generator(name, options = {}, stream = StringIO.new) describe "#render_template" do it "renders template into a string" do template = generator("resource_history").render_template("endpoint.erb") - assert_match /module Endpoints/, template + assert_match(/module Endpoints/, template) end end @@ -98,7 +98,7 @@ def generator(name, options = {}, stream = StringIO.new) it "renders given template into a file by given path" do assert File.exist?(destination_path) - assert_match /module Endpoints/, File.read(destination_path) + assert_match(/module Endpoints/, File.read(destination_path)) end end @@ -116,7 +116,7 @@ def generator(name, options = {}, stream = StringIO.new) end it "writes given content into a file" do - assert_match /Hello world/, File.read(destination_path) + assert_match(/Hello world/, File.read(destination_path)) end end end diff --git a/spec/helpers/params_spec.rb b/spec/helpers/params_spec.rb index 709331cf..763fb025 100644 --- a/spec/helpers/params_spec.rb +++ b/spec/helpers/params_spec.rb @@ -42,6 +42,6 @@ def app post "/", "{\"foo\"}", { "CONTENT_TYPE" => "application/json" } end - assert_match /expected ':' after object key at line 1 column 7/, err.message + assert_match(/expected ':' after object key at line 1 column 7/, err.message) end end From d3dae0064bee358790b7223169bb97af622f4ef3 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:44:39 +0200 Subject: [PATCH 25/64] fix Lint/UselessAssignment --- .rubocop_todo.yml | 6 ------ spec/integration_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d946f875..992272d2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -49,12 +49,6 @@ Lint/RescueException: Exclude: - 'lib/pliny/error_reporters/rollbar.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Lint/UselessAssignment: - Exclude: - - 'spec/integration_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: CheckForMethodsWithNoSideEffects. diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 1b8d7dee..b73b4fb2 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -83,7 +83,7 @@ bash "pliny-generate model artist" migration_file = Dir.glob("db/migrate/*").first - stdout, stderr = bash_with_output("rake db:migrate:status") + stdout, _ = bash_with_output("rake db:migrate:status") statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] assert statuses[migration_file.split("/").last] == "DOWN" @@ -94,7 +94,7 @@ migration_file = Dir.glob("db/migrate/*").first bash "rake db:migrate" - stdout, stderr = bash_with_output("rake db:migrate:status") + stdout, _ = bash_with_output("rake db:migrate:status") statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] assert statuses[migration_file.split("/").last] == "UP" @@ -107,7 +107,7 @@ FileUtils.rm_f(migration_file) - stdout, stderr = bash_with_output("rake db:migrate:status") + stdout, _ = bash_with_output("rake db:migrate:status") statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^[ ]+|[ ]+$)/, "") }.select(&:present?).reverse }] assert statuses[migration_file.split("/").last] == "FILE MISSING" From d3082a1655a6fee81232e1fdea931a83abd3f361 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:46:02 +0200 Subject: [PATCH 26/64] fix Naming/HeredocDelimiterCase --- .rubocop_todo.yml | 10 ---------- lib/pliny/helpers/serialize.rb | 4 ++-- lib/pliny/middleware/versioning.rb | 4 ++-- spec/middleware/versioning_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 992272d2..a9b50d93 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -56,16 +56,6 @@ Lint/Void: Exclude: - 'lib/pliny/log.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: lowercase, uppercase -Naming/HeredocDelimiterCase: - Exclude: - - 'lib/pliny/helpers/serialize.rb' - - 'lib/pliny/middleware/versioning.rb' - - 'spec/middleware/versioning_spec.rb' - # Offense count: 1 Security/Eval: Exclude: diff --git a/lib/pliny/helpers/serialize.rb b/lib/pliny/helpers/serialize.rb index ee2e18dd..62dbc206 100644 --- a/lib/pliny/helpers/serialize.rb +++ b/lib/pliny/helpers/serialize.rb @@ -12,10 +12,10 @@ def serialize(data, structure = :default) serializer_class = settings.serializer_class if serializer_class.nil? - raise <<~eos.strip + raise <<~EOS.strip No serializer has been specified for this endpoint. Please specify one with `serializer Serializers::ModelName` in the endpoint. - eos + EOS end env["pliny.serializer_arity"] = data.respond_to?(:size) ? data.size : 1 diff --git a/lib/pliny/middleware/versioning.rb b/lib/pliny/middleware/versioning.rb index a00ff4c7..510a8f49 100644 --- a/lib/pliny/middleware/versioning.rb +++ b/lib/pliny/middleware/versioning.rb @@ -25,9 +25,9 @@ def detect_api_version(env) media_types.map! do |media_type| if accept_headers.include?(media_type.format) unless media_type.params["version"] - error = { id: :bad_version, message: <<~eos } + error = { id: :bad_version, message: <<~EOS } Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`. - eos + EOS return [400, { "content-type" => "application/json; charset=utf-8" }, [JSON.generate(error)]] end diff --git a/spec/middleware/versioning_spec.rb b/spec/middleware/versioning_spec.rb index f0f36552..26db30f3 100644 --- a/spec/middleware/versioning_spec.rb +++ b/spec/middleware/versioning_spec.rb @@ -30,9 +30,9 @@ def app it "errors without a version specified on application/vnd.pliny+json" do get "/", {}, { "HTTP_ACCEPT" => "application/vnd.pliny+json" } - error = { id: :bad_version, message: <<~eos } + error = { id: :bad_version, message: <<~EOS } Please specify a version along with the MIME type. For example, `Accept: application/vnd.pliny+json; version=1`. - eos + EOS assert_equal 400, last_response.status assert_equal JSON.generate(error), last_response.body From cc794d5eb2f934860a9928ad17104a9673c1879d Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:46:30 +0200 Subject: [PATCH 27/64] fix Style/Alias --- .rubocop_todo.yml | 8 -------- lib/pliny/utils.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a9b50d93..cebdbb46 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,14 +61,6 @@ Security/Eval: Exclude: - 'spec/commands/generator/endpoint_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: prefer_alias, prefer_alias_method -Style/Alias: - Exclude: - - 'lib/pliny/utils.rb' - # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/utils.rb b/lib/pliny/utils.rb index 4115a356..cea4244c 100644 --- a/lib/pliny/utils.rb +++ b/lib/pliny/utils.rb @@ -29,7 +29,7 @@ def self.require_glob(path) end class << self - alias :require_relative_glob :require_glob + alias_method :require_relative_glob, :require_glob end end end From f69e30b41a2223686232ad0d1d051713618db6d8 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:46:47 +0200 Subject: [PATCH 28/64] fix Style/ClassCheck --- .rubocop_todo.yml | 8 -------- lib/pliny/config_helpers.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cebdbb46..c0981493 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,14 +61,6 @@ Security/Eval: Exclude: - 'spec/commands/generator/endpoint_spec.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: is_a?, kind_of? -Style/ClassCheck: - Exclude: - - 'lib/pliny/config_helpers.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, AllowInnerBackticks. diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index bb846e12..b859c0be 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -78,7 +78,7 @@ def cast(value, method) def create(name, value) instance_variable_set(:"@#{name}", value) instance_eval "def #{name}; @#{name} end", __FILE__, __LINE__ - if value.kind_of?(TrueClass) || value.kind_of?(FalseClass) || value.kind_of?(NilClass) + if value.is_a?(TrueClass) || value.is_a?(FalseClass) || value.is_a?(NilClass) instance_eval "def #{name}?; !!@#{name} end", __FILE__, __LINE__ end end From 8e6ca616d4b4cdd702e169f5a1fa27f9c7b05aa9 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:47:07 +0200 Subject: [PATCH 29/64] fix Style/CommandLiteral --- .rubocop_todo.yml | 8 -------- pliny.gemspec | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c0981493..30f945b5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,14 +61,6 @@ Security/Eval: Exclude: - 'spec/commands/generator/endpoint_spec.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowInnerBackticks. -# SupportedStyles: backticks, percent_x, mixed -Style/CommandLiteral: - Exclude: - - 'pliny.gemspec' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/ComparableBetween: diff --git a/pliny.gemspec b/pliny.gemspec index e2a9b45f..662618c5 100644 --- a/pliny.gemspec +++ b/pliny.gemspec @@ -14,8 +14,8 @@ Gem::Specification.new do |gem| gem.description = "Pliny is a set of base classes and helpers to help developers write excellent APIs in Sinatra" gem.license = "MIT" - gem.executables = %x{git ls-files}.split("\n").select { |d| d =~ /^bin\// }.map { |d| d.gsub(/^bin\//, "") } - gem.files = %x{git ls-files}.split("\n").select { |d| d =~ %r{^(License|README|bin/|data/|ext/|lib/|spec/|test/)} } + gem.executables = `git ls-files`.split("\n").select { |d| d =~ /^bin\// }.map { |d| d.gsub(/^bin\//, "") } + gem.files = `git ls-files`.split("\n").select { |d| d =~ %r{^(License|README|bin/|data/|ext/|lib/|spec/|test/)} } gem.required_ruby_version = ">= 3.2" From 348b9e1220a711ebf39d9d9794c482b00c774e46 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:47:28 +0200 Subject: [PATCH 30/64] fix Style/EmptyLiteral --- .rubocop_todo.yml | 7 ------- spec/commands/generator/endpoint_spec.rb | 8 ++++---- spec/log_spec.rb | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 30f945b5..d1e8d730 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -67,13 +67,6 @@ Style/ComparableBetween: Exclude: - 'spec/metrics_spec.rb' -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -Style/EmptyLiteral: - Exclude: - - 'spec/commands/generator/endpoint_spec.rb' - - 'spec/log_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/spec/commands/generator/endpoint_spec.rb b/spec/commands/generator/endpoint_spec.rb index 317874b1..c28c4b44 100644 --- a/spec/commands/generator/endpoint_spec.rb +++ b/spec/commands/generator/endpoint_spec.rb @@ -34,25 +34,25 @@ it "defines a stub POST /" do post "/artists" assert_equal 201, last_response.status - assert_equal Hash.new, JSON.parse(last_response.body) + assert_equal({}, JSON.parse(last_response.body)) end it "defines a stub GET /:id" do get "/artists/123" assert_equal 200, last_response.status - assert_equal Hash.new, JSON.parse(last_response.body) + assert_equal({}, JSON.parse(last_response.body)) end it "defines a stub PATCH /:id" do patch "/artists/123" assert_equal 200, last_response.status - assert_equal Hash.new, JSON.parse(last_response.body) + assert_equal({}, JSON.parse(last_response.body)) end it "defines a stub DELETE /:id" do delete "/artists/123" assert_equal 200, last_response.status - assert_equal Hash.new, JSON.parse(last_response.body) + assert_equal({}, JSON.parse(last_response.body)) end end end diff --git a/spec/log_spec.rb b/spec/log_spec.rb index 070e5fd8..1c705be8 100644 --- a/spec/log_spec.rb +++ b/spec/log_spec.rb @@ -110,7 +110,7 @@ describe "when a scrubber is present" do before do Pliny.log_scrubber = ->(hash) { - Hash.new.tap do |h| + {}.tap do |h| hash.keys.each do |k| h[k] = "*SCRUBBED*" end From 1a0b3879ebc061ef013122b1aee408fe15ffdff9 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:47:46 +0200 Subject: [PATCH 31/64] fix Style/RedundantRegexpEscape --- .rubocop_todo.yml | 6 ------ lib/pliny/commands/updater.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d1e8d730..08566a29 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -146,12 +146,6 @@ Style/RedundantRegexpCharacterClass: Exclude: - 'spec/integration_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpEscape: - Exclude: - - 'lib/pliny/commands/updater.rb' - # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMultipleReturnValues. diff --git a/lib/pliny/commands/updater.rb b/lib/pliny/commands/updater.rb index b7b49e27..2eaaae2a 100644 --- a/lib/pliny/commands/updater.rb +++ b/lib/pliny/commands/updater.rb @@ -52,7 +52,7 @@ def ensure_repo_available def get_current_version File.read("./Gemfile.lock").split("\n").each do |line| - next unless pliny_version = line.match(/pliny \(([\d+\.]+)\)/) + next unless pliny_version = line.match(/pliny \(([\d+.]+)\)/) return Gem::Version.new(pliny_version[1]) end end From a0cff6d848b0bf98547b0ecbf2cefad2418ba8dc Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:48:03 +0200 Subject: [PATCH 32/64] fix Style/RedundantReturn --- .rubocop_todo.yml | 8 -------- lib/pliny/db_support.rb | 6 +++--- spec/integration_spec.rb | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 08566a29..bbb53c52 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -146,14 +146,6 @@ Style/RedundantRegexpCharacterClass: Exclude: - 'spec/integration_spec.rb' -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/pliny/db_support.rb' - - 'spec/integration_spec.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index 9ba1d5be..9ae18e7d 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -17,9 +17,9 @@ def self.setup?(database_url) @db = Sequel.connect(database_url) @db.test_connection @db.disconnect - return true + true rescue Sequel::DatabaseConnectionError - return false + false end def self.run(url, sequel_log_io = StringIO.new) @@ -41,7 +41,7 @@ def initialize(url, sequel_logger) def exists?(name) res = db.fetch("SELECT 1 FROM pg_database WHERE datname = ?", name) - return res.count > 0 + res.count > 0 end def create(name) diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index b73b4fb2..c626dd04 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -124,7 +124,7 @@ def bash_with_output(cmd) raise "Failed to run #{cmd}, error was #{stderr}" end - return stdout, stderr + [stdout, stderr] end def bash(cmd) From e3877d8e25dab89cc013054082e7d54472212a1e Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:48:31 +0200 Subject: [PATCH 33/64] fix Style/UnlessElse --- .rubocop_todo.yml | 6 ------ lib/pliny/log.rb | 10 +++++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bbb53c52..512e7d57 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -218,12 +218,6 @@ Style/TrivialAccessors: Exclude: - 'spec/middleware/rescue_errors_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/UnlessElse: - Exclude: - - 'lib/pliny/log.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index 67a58251..3b075143 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -104,11 +104,7 @@ def log_context end def log_to_stream(stream, data, &block) - unless block - data = log_scrubber.call(data) if log_scrubber - str = unparse(data) - stream.print(str + "\n") - else + if block data = data.dup start = Time.now log_to_stream(stream, data.merge(at: "start")) @@ -124,6 +120,10 @@ def log_to_stream(stream, data, &block) ),) raise $! end + else + data = log_scrubber.call(data) if log_scrubber + str = unparse(data) + stream.print(str + "\n") end end From 66dde24863039a321ff2c9f67c857274fcccbcdb Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:48:48 +0200 Subject: [PATCH 34/64] fix Style/TrivialAccessors --- .rubocop_todo.yml | 8 -------- spec/middleware/rescue_errors_spec.rb | 4 +--- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 512e7d57..8cdd727b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -210,14 +210,6 @@ Style/TrailingCommaInHashLiteral: - 'spec/error_reporters/rollbar_spec.rb' - 'spec/request_store_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods. -# AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym -Style/TrivialAccessors: - Exclude: - - 'spec/middleware/rescue_errors_spec.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/spec/middleware/rescue_errors_spec.rb b/spec/middleware/rescue_errors_spec.rb index e703acf3..3e07f9d0 100644 --- a/spec/middleware/rescue_errors_spec.rb +++ b/spec/middleware/rescue_errors_spec.rb @@ -15,9 +15,7 @@ def call(env) end end - def app - @app - end + attr_reader :app it "intercepts Pliny errors and renders" do @app = new_rack_app From 6fefae6bb340d16cadf76f072d53b83693a25eb2 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:49:32 +0200 Subject: [PATCH 35/64] fix Style/TrailingCommaInHashLiteral --- .rubocop_todo.yml | 13 ------------- lib/pliny/db_support.rb | 2 +- lib/pliny/middleware/cors.rb | 2 +- lib/pliny/middleware/instruments.rb | 2 +- lib/pliny/request_store.rb | 2 +- spec/error_reporters/rollbar_spec.rb | 2 +- spec/request_store_spec.rb | 2 +- 7 files changed, 6 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8cdd727b..ed30dac7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -197,19 +197,6 @@ Style/TrailingCommaInArrayLiteral: - 'spec/commands/generator/base_spec.rb' - 'spec/db_support_spec.rb' -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, diff_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'lib/pliny/db_support.rb' - - 'lib/pliny/middleware/cors.rb' - - 'lib/pliny/middleware/instruments.rb' - - 'lib/pliny/request_store.rb' - - 'spec/error_reporters/rollbar_spec.rb' - - 'spec/request_store_spec.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index 9ae18e7d..66293779 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -100,7 +100,7 @@ class MigrationStatusPresenter STATUS_MAP = { up: UP, down: DOWN, - file_missing: FILE_MISSING + file_missing: FILE_MISSING, }.freeze STATUS_OPTIONS = [ diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index be62bee1..221b2db1 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -50,7 +50,7 @@ def cors_headers(env) "access-control-allow-headers" => allow_headers.join(", "), "access-control-allow-credentials" => "true", "access-control-max-age" => "1728000", - "access-control-expose-headers" => EXPOSE_HEADERS.join(", ") + "access-control-expose-headers" => EXPOSE_HEADERS.join(", "), } end end diff --git a/lib/pliny/middleware/instruments.rb b/lib/pliny/middleware/instruments.rb index 285abe96..16606e58 100644 --- a/lib/pliny/middleware/instruments.rb +++ b/lib/pliny/middleware/instruments.rb @@ -12,7 +12,7 @@ def call(env) data = { instrumentation: true, method: env["REQUEST_METHOD"], - path: env["PATH_INFO"] + path: env["PATH_INFO"], } Pliny.log(data.merge(at: "start")) diff --git a/lib/pliny/request_store.rb b/lib/pliny/request_store.rb index 899901e8..33d680c1 100644 --- a/lib/pliny/request_store.rb +++ b/lib/pliny/request_store.rb @@ -13,7 +13,7 @@ def self.seed(env) # a global context that evolves over the lifetime of the request, and is # used to tag all log messages that it produces store[:log_context] = { - request_id: store[:request_id] + request_id: store[:request_id], } end diff --git a/spec/error_reporters/rollbar_spec.rb b/spec/error_reporters/rollbar_spec.rb index 8b94eb0d..98043a8f 100644 --- a/spec/error_reporters/rollbar_spec.rb +++ b/spec/error_reporters/rollbar_spec.rb @@ -40,7 +40,7 @@ { "rollbar.person_data" => { id: SecureRandom.uuid, email: "foo@bar.com", - username: "foo" + username: "foo", } } end diff --git a/spec/request_store_spec.rb b/spec/request_store_spec.rb index 989eb52e..64769412 100644 --- a/spec/request_store_spec.rb +++ b/spec/request_store_spec.rb @@ -5,7 +5,7 @@ describe Pliny::RequestStore do before do @env = { - "REQUEST_IDS" => ["abc", "def"] + "REQUEST_IDS" => ["abc", "def"], } end From b5782b4a4c5dbd1e7a29353768650bdfbb580ace Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:49:49 +0200 Subject: [PATCH 36/64] fix Style/TrailingCommaInArrayLiteral --- .rubocop_todo.yml | 12 ------------ lib/pliny/db_support.rb | 6 +++--- lib/pliny/middleware/versioning.rb | 2 +- lib/template/bin/console | 2 +- spec/commands/generator/base_spec.rb | 2 +- spec/db_support_spec.rb | 2 +- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ed30dac7..3d56d307 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -185,18 +185,6 @@ Style/StringLiteralsInInterpolation: Exclude: - 'lib/pliny/db_support.rb' -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, diff_comma, no_comma -Style/TrailingCommaInArrayLiteral: - Exclude: - - 'lib/pliny/db_support.rb' - - 'lib/pliny/middleware/versioning.rb' - - 'lib/template/bin/console' - - 'spec/commands/generator/base_spec.rb' - - 'spec/db_support_spec.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index 66293779..dd1a305f 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -106,7 +106,7 @@ class MigrationStatusPresenter STATUS_OPTIONS = [ UP, DOWN, - FILE_MISSING + FILE_MISSING, ].freeze attr_reader :migration_statuses @@ -127,7 +127,7 @@ def header [ barrier_row, header_row, - barrier_row + barrier_row, ] end @@ -139,7 +139,7 @@ def statuses def footer [ - barrier_row + barrier_row, ] end diff --git a/lib/pliny/middleware/versioning.rb b/lib/pliny/middleware/versioning.rb index 510a8f49..0d20f009 100644 --- a/lib/pliny/middleware/versioning.rb +++ b/lib/pliny/middleware/versioning.rb @@ -29,7 +29,7 @@ def detect_api_version(env) Please specify a version along with the MIME type. For example, `Accept: application/vnd.#{@app_name}+json; version=1`. EOS return [400, { "content-type" => "application/json; charset=utf-8" }, - [JSON.generate(error)]] + [JSON.generate(error)],] end unless version diff --git a/lib/template/bin/console b/lib/template/bin/console index 6c6eaf65..515a246a 100755 --- a/lib/template/bin/console +++ b/lib/template/bin/console @@ -16,7 +16,7 @@ Pry.prompt = [ proc do |target_self, nest_level, pry| basic_prompt(target_self, nest_level, pry) + "* " - end + end, ] Pry.start diff --git a/spec/commands/generator/base_spec.rb b/spec/commands/generator/base_spec.rb index b43cddcc..90aab400 100644 --- a/spec/commands/generator/base_spec.rb +++ b/spec/commands/generator/base_spec.rb @@ -15,7 +15,7 @@ def generator(name, options = {}, stream = StringIO.new) "resource history", "resource-history", "resource_history", - "ResourceHistory" + "ResourceHistory", ].each do |argument| actual = generator(argument).name assert_equal "resource_history", actual diff --git a/spec/db_support_spec.rb b/spec/db_support_spec.rb index 7594ff0d..0a3a0809 100644 --- a/spec/db_support_spec.rb +++ b/spec/db_support_spec.rb @@ -275,7 +275,7 @@ up_expectation, down_expectation, file_missing_expectation, - footer + footer, ] assert_equal expectation, presenter.rows From 389dd95854bb1f990205fa853e33f1d56727606e Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:50:06 +0200 Subject: [PATCH 37/64] fix Style/StringLiteralsInInterpolation --- .rubocop_todo.yml | 8 -------- lib/pliny/db_support.rb | 6 +++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3d56d307..6d6cfda4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -177,14 +177,6 @@ Style/SlicingWithRange: - 'lib/pliny/tasks/db.rake' - 'spec/integration_spec.rb' -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiteralsInInterpolation: - Exclude: - - 'lib/pliny/db_support.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index dd1a305f..1c41918a 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -144,15 +144,15 @@ def footer end def barrier_row - "+#{'-' * (longest_status + PADDING)}+#{'-' * (longest_migration_name + PADDING)}+" + "+#{"-" * (longest_status + PADDING)}+#{"-" * (longest_migration_name + PADDING)}+" end def header_row - "|#{'STATUS'.center(longest_status + PADDING)}|#{'MIGRATION'.center(longest_migration_name + PADDING)}|" + "|#{"STATUS".center(longest_status + PADDING)}|#{"MIGRATION".center(longest_migration_name + PADDING)}|" end def status_row(migration_status) - "|#{STATUS_MAP[migration_status.status].center(longest_status + PADDING)}|#{' ' * (PADDING / 2)}#{migration_status.filename.ljust(longest_migration_name)}#{' ' * (PADDING / 2)}|" + "|#{STATUS_MAP[migration_status.status].center(longest_status + PADDING)}|#{" " * (PADDING / 2)}#{migration_status.filename.ljust(longest_migration_name)}#{" " * (PADDING / 2)}|" end private From 04b277f641dcdb3b1ff42c488002a31ef80cdbad Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:50:24 +0200 Subject: [PATCH 38/64] fix Style/SingleLineMethods --- .rubocop_todo.yml | 7 ------- spec/helpers/serialize_spec.rb | 3 ++- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6d6cfda4..c153d5d3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -163,13 +163,6 @@ Style/SelfAssignment: Exclude: - 'lib/pliny/errors.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowIfMethodIsEmpty. -Style/SingleLineMethods: - Exclude: - - 'spec/helpers/serialize_spec.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Style/SlicingWithRange: diff --git a/spec/helpers/serialize_spec.rb b/spec/helpers/serialize_spec.rb index feb0d0dd..059aa57c 100644 --- a/spec/helpers/serialize_spec.rb +++ b/spec/helpers/serialize_spec.rb @@ -23,7 +23,8 @@ def app context "with a serializer" do class Serializer - def initialize(opts); end + def initialize(opts) + end def serialize(data) data From a4254ff76833f7cde4f6c73586fac4d5ee0225a5 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:50:46 +0200 Subject: [PATCH 39/64] fix Style/SelfAssignment --- .rubocop_todo.yml | 6 ------ lib/pliny/errors.rb | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c153d5d3..95a78e19 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -157,12 +157,6 @@ Style/SafeNavigation: - 'lib/pliny/log.rb' - 'lib/pliny/request_store.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/SelfAssignment: - Exclude: - - 'lib/pliny/errors.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Style/SlicingWithRange: diff --git a/lib/pliny/errors.rb b/lib/pliny/errors.rb index 962ca084..bf049ddc 100644 --- a/lib/pliny/errors.rb +++ b/lib/pliny/errors.rb @@ -22,8 +22,8 @@ class HTTPStatusError < Error def initialize(message = nil, id = nil, status = nil) meta = Pliny::Errors::META[self.class] - message = message || meta[1] + "." - id = id || meta[1].downcase.tr(" ", "_").to_sym + message ||= meta[1] + "." + id ||= meta[1].downcase.tr(" ", "_").to_sym @status = status || meta[0] super(message, id) end From 794be059e2423627391f0e7100b77367fc007107 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:51:04 +0200 Subject: [PATCH 40/64] fix Style/RedundantRegexpCharacterClass --- .rubocop_todo.yml | 6 ------ spec/integration_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 95a78e19..9f99663c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -140,12 +140,6 @@ Style/RedundantRegexpArgument: Exclude: - 'lib/pliny/log.rb' -# Offense count: 8 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpCharacterClass: - Exclude: - - 'spec/integration_spec.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index c626dd04..2a0f7bb7 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -85,7 +85,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] + statuses = Hash[stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] assert statuses[migration_file.split("/").last] == "DOWN" end @@ -96,7 +96,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] + statuses = Hash[stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] assert statuses[migration_file.split("/").last] == "UP" end @@ -109,7 +109,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = Hash[stdout.to_s.split(/\+[-]+\+[-]+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^[ ]+|[ ]+$)/, "") }.select(&:present?).reverse }] + statuses = Hash[stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^ +| +$)/, "") }.select(&:present?).reverse }] assert statuses[migration_file.split("/").last] == "FILE MISSING" end end From 99249ba23e3fcbce6b1791680a6ad751e1e44443 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:51:18 +0200 Subject: [PATCH 41/64] fix Style/RedundantRegexpArgument --- .rubocop_todo.yml | 6 ------ lib/pliny/log.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9f99663c..16551e53 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -134,12 +134,6 @@ Style/RedundantInterpolation: Exclude: - 'lib/pliny/log.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpArgument: - Exclude: - - 'lib/pliny/log.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index 3b075143..a42bf600 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -137,7 +137,7 @@ def quote_string(v) elsif !v.include?("'") %{'#{v}'} else - %{"#{v.gsub(/"/, '\\"')}"} + %{"#{v.gsub('"', '\\"')}"} end end From e5e08b30e255baed00c9424f184d4d8d3f7d1cc8 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:51:35 +0200 Subject: [PATCH 42/64] fix Style/RedundantBegin --- .rubocop_todo.yml | 6 ------ lib/pliny/error_reporters.rb | 8 +++----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 16551e53..4151736d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -122,12 +122,6 @@ Style/PercentLiteralDelimiters: - 'lib/template/lib/initializer.rb' - 'pliny.gemspec' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantBegin: - Exclude: - - 'lib/pliny/error_reporters.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: diff --git a/lib/pliny/error_reporters.rb b/lib/pliny/error_reporters.rb index a7a35013..159b2176 100644 --- a/lib/pliny/error_reporters.rb +++ b/lib/pliny/error_reporters.rb @@ -11,11 +11,9 @@ def notify(exception, context: {}, rack_env: {}) Pliny.log_exception(exception) error_reporters.each do |reporter| - begin - reporter.new.notify(exception, context: context, rack_env: rack_env) - rescue - Pliny.log_exception($!) - end + reporter.new.notify(exception, context: context, rack_env: rack_env) + rescue + Pliny.log_exception($!) end end end From d34ee8cc9c7210f89ed090887c269de377edcc92 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:51:57 +0200 Subject: [PATCH 43/64] fix Style/PercentLiteralDelimiters --- .rubocop_todo.yml | 12 ------------ lib/pliny/db_support.rb | 2 +- lib/pliny/log.rb | 6 +++--- lib/pliny/middleware/cors.rb | 6 +++--- lib/pliny/middleware/request_id.rb | 2 +- lib/template/lib/initializer.rb | 8 ++++---- 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4151736d..93186560 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -110,18 +110,6 @@ Style/OrAssignment: Exclude: - 'lib/pliny/middleware/versioning.rb' -# Offense count: 12 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'lib/pliny/db_support.rb' - - 'lib/pliny/log.rb' - - 'lib/pliny/middleware/cors.rb' - - 'lib/pliny/middleware/request_id.rb' - - 'lib/template/lib/initializer.rb' - - 'pliny.gemspec' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index 1c41918a..5944bae5 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -45,7 +45,7 @@ def exists?(name) end def create(name) - db.run(%{CREATE DATABASE "#{name}"}) + db.run(%(CREATE DATABASE "#{name}")) end def migrate(target = nil) diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index a42bf600..ddf84992 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -133,11 +133,11 @@ def replace_newlines(v) def quote_string(v) if !v.include?('"') - %{"#{v}"} + %("#{v}") elsif !v.include?("'") - %{'#{v}'} + %('#{v}') else - %{"#{v.gsub('"', '\\"')}"} + %("#{v.gsub('"', '\\"')}") end end diff --git a/lib/pliny/middleware/cors.rb b/lib/pliny/middleware/cors.rb index 221b2db1..ca13e69a 100644 --- a/lib/pliny/middleware/cors.rb +++ b/lib/pliny/middleware/cors.rb @@ -3,11 +3,11 @@ module Pliny::Middleware class CORS ALLOW_METHODS = - %w(GET POST PUT PATCH DELETE OPTIONS).freeze + %w[GET POST PUT PATCH DELETE OPTIONS].freeze ALLOW_HEADERS = - %w(Content-Type Accept Authorization Cache-Control If-None-Match If-Modified-Since Origin).freeze + %w[Content-Type Accept Authorization Cache-Control If-None-Match If-Modified-Since Origin].freeze EXPOSE_HEADERS = - %w(Cache-Control Content-Language Content-Type Expires Last-Modified Pragma).freeze + %w[Cache-Control Content-Language Content-Type Expires Last-Modified Pragma].freeze @@additional_headers = [] diff --git a/lib/pliny/middleware/request_id.rb b/lib/pliny/middleware/request_id.rb index e9660fba..b3f1e69e 100644 --- a/lib/pliny/middleware/request_id.rb +++ b/lib/pliny/middleware/request_id.rb @@ -49,7 +49,7 @@ def raw_request_ids(env) # field as to whether it should be prefixed with `X-` or not. API went # with no prefix, but Hermes went with one. Support both formats on # input. - %w(HTTP_REQUEST_ID HTTP_X_REQUEST_ID).inject([]) do |request_ids, key| + %w[HTTP_REQUEST_ID HTTP_X_REQUEST_ID].inject([]) do |request_ids, key| if ids = env[key] request_ids += ids.split(",") end diff --git a/lib/template/lib/initializer.rb b/lib/template/lib/initializer.rb index a782148e..e8e580b8 100644 --- a/lib/template/lib/initializer.rb +++ b/lib/template/lib/initializer.rb @@ -13,7 +13,7 @@ def self.require_config end def self.require_lib - require! %w( + require! %w[ lib/serializers/base lib/serializers/**/* lib/endpoints/base @@ -21,13 +21,13 @@ def self.require_lib lib/mediators/base lib/mediators/**/* lib/routes - ) + ] end def self.require_models - require! %w( + require! %w[ lib/models/**/* - ) + ] end def self.require_initializers From 712ef4b528d7d9fe2fdc3ca58b8c6b0528c27fe1 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:53:26 +0200 Subject: [PATCH 44/64] fix Style/OrAssignment --- .rubocop_todo.yml | 6 ------ lib/pliny/middleware/versioning.rb | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 93186560..1336dcd8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -104,12 +104,6 @@ Style/NilComparison: Exclude: - 'lib/pliny/log.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/OrAssignment: - Exclude: - - 'lib/pliny/middleware/versioning.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: diff --git a/lib/pliny/middleware/versioning.rb b/lib/pliny/middleware/versioning.rb index 0d20f009..7001f488 100644 --- a/lib/pliny/middleware/versioning.rb +++ b/lib/pliny/middleware/versioning.rb @@ -32,9 +32,7 @@ def detect_api_version(env) [JSON.generate(error)],] end - unless version - version = media_type.params["version"] - end + version ||= media_type.params["version"] # replace the MIME with a simplified version for easier # parsing down the stack From 171937530f8ad89464918fbd27341ecce9036a0c Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:53:44 +0200 Subject: [PATCH 45/64] fix Style/NilComparison --- .rubocop_todo.yml | 8 -------- lib/pliny/log.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1336dcd8..4db7c563 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -96,14 +96,6 @@ Style/IfInsideElse: Exclude: - 'lib/pliny/db_support.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: predicate, comparison -Style/NilComparison: - Exclude: - - 'lib/pliny/log.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index ddf84992..4a118e22 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -148,7 +148,7 @@ def unparse(attrs) def unparse_pair(k, v) v = v.call if v.is_a?(Proc) - if v == nil + if v.nil? nil elsif v == true k From f14af005b955e0dfb1f6ef3e958cb2d444fc3af5 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:54:04 +0200 Subject: [PATCH 46/64] fix Style/IfInsideElse --- .rubocop_todo.yml | 7 ------- lib/pliny/db_support.rb | 8 +++----- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4db7c563..a1420d81 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -89,13 +89,6 @@ Style/HashConversion: - 'lib/pliny/metrics.rb' - 'spec/integration_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowIfModifier. -Style/IfInsideElse: - Exclude: - - 'lib/pliny/db_support.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: diff --git a/lib/pliny/db_support.rb b/lib/pliny/db_support.rb index 5944bae5..4530a38e 100644 --- a/lib/pliny/db_support.rb +++ b/lib/pliny/db_support.rb @@ -81,12 +81,10 @@ def status else :down end + elsif present_in_database + :file_missing else - if present_in_database - :file_missing - else - raise "error" # FIXME: better message - end + raise "error" # FIXME: better message end end end From 0b2e868bfaa69a0a753a75a6fe6154101e36bd2e Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:54:22 +0200 Subject: [PATCH 47/64] fix Style/FileWrite --- .rubocop_todo.yml | 6 ------ lib/pliny/commands/creator.rb | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a1420d81..2115f4f2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -75,12 +75,6 @@ Style/EmptyMethod: Exclude: - 'spec/helpers/serialize_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Style/FileWrite: - Exclude: - - 'lib/pliny/commands/creator.rb' - # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSplatArgument. diff --git a/lib/pliny/commands/creator.rb b/lib/pliny/commands/creator.rb index 57801497..d2ef5f02 100644 --- a/lib/pliny/commands/creator.rb +++ b/lib/pliny/commands/creator.rb @@ -41,9 +41,7 @@ def parse_erb_files context = OpenStruct.new(app_name: name) content = template.result(context.instance_eval { binding }) - File.open(static_file, "w") do |f| - f.write content - end + File.write(static_file, content) FileUtils.rm(file) end end From d44c72d2d65debe5a4f27e2d9df2b007f5990f5d Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:55:05 +0200 Subject: [PATCH 48/64] fix Style/EmptyMethod --- .rubocop_todo.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2115f4f2..5cb5a30a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -67,14 +67,6 @@ Style/ComparableBetween: Exclude: - 'spec/metrics_spec.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'spec/helpers/serialize_spec.rb' - # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSplatArgument. From 0e18f7fd83244d9406c222003247f6eefcba32e5 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:55:34 +0200 Subject: [PATCH 49/64] fix Layout/LeadingEmptyLines --- .rubocop_todo.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5cb5a30a..a6c3cfe4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Layout/LeadingEmptyLines: - Exclude: - - 'lib/template/Rakefile' - - 'lib/template/lib/tasks/spec.rake' - # Offense count: 6 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSafeAssignment. From c800b397af824f5d2d3d053de46bc6a1c809085a Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 14:56:05 +0200 Subject: [PATCH 50/64] fix Lint/Void --- .rubocop_todo.yml | 7 ------- lib/pliny/log.rb | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a6c3cfe4..bc1d68d9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -42,13 +42,6 @@ Lint/RescueException: Exclude: - 'lib/pliny/error_reporters/rollbar.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: CheckForMethodsWithNoSideEffects. -Lint/Void: - Exclude: - - 'lib/pliny/log.rb' - # Offense count: 1 Security/Eval: Exclude: diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index 4a118e22..0c4fc761 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -44,10 +44,9 @@ def log_exception(e, data = {}) def context(data, &block) old = local_context self.local_context = old.merge(data) - res = block.call + block.call ensure self.local_context = old - res end def default_context=(default_context) From bbe5649c2dfa8ee4b210adbaa460371a2c0dbd15 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 15:38:05 +0200 Subject: [PATCH 51/64] fix Lint/AssignmentInCondition --- .rubocop_todo.yml | 10 ---------- lib/pliny/commands/updater.rb | 2 +- lib/pliny/middleware/canonical_log_line.rb | 6 +++--- lib/pliny/middleware/instruments.rb | 2 +- lib/pliny/middleware/request_id.rb | 2 +- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bc1d68d9..aa8e207f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,16 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 6 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Exclude: - - 'lib/pliny/commands/updater.rb' - - 'lib/pliny/middleware/canonical_log_line.rb' - - 'lib/pliny/middleware/instruments.rb' - - 'lib/pliny/middleware/request_id.rb' - # Offense count: 4 # Configuration parameters: AllowedMethods. # AllowedMethods: enums diff --git a/lib/pliny/commands/updater.rb b/lib/pliny/commands/updater.rb index 2eaaae2a..4bd78135 100644 --- a/lib/pliny/commands/updater.rb +++ b/lib/pliny/commands/updater.rb @@ -52,7 +52,7 @@ def ensure_repo_available def get_current_version File.read("./Gemfile.lock").split("\n").each do |line| - next unless pliny_version = line.match(/pliny \(([\d+.]+)\)/) + next unless (pliny_version = line.match(/pliny \(([\d+.]+)\)/)) return Gem::Version.new(pliny_version[1]) end end diff --git a/lib/pliny/middleware/canonical_log_line.rb b/lib/pliny/middleware/canonical_log_line.rb index e2aaaca1..4598e407 100644 --- a/lib/pliny/middleware/canonical_log_line.rb +++ b/lib/pliny/middleware/canonical_log_line.rb @@ -77,7 +77,7 @@ def call(env) # error # - if error = env["pliny.error"] + if (error = env["pliny.error"]) line.error_class = error.class.name line.error_message = error.message if error.is_a?(Pliny::Errors::Error) @@ -95,7 +95,7 @@ def call(env) line.request_method = request.request_method line.request_path = request.path_info line.request_user_agent = request.user_agent - if route = env["sinatra.route"] + if (route = env["sinatra.route"]) line.request_route_signature = route.split(" ").last end @@ -103,7 +103,7 @@ def call(env) # response # - if length = headers["Content-Length"] + if (length = headers["Content-Length"]) line.response_length = length.to_i end line.response_status = status diff --git a/lib/pliny/middleware/instruments.rb b/lib/pliny/middleware/instruments.rb index 16606e58..f9e095b3 100644 --- a/lib/pliny/middleware/instruments.rb +++ b/lib/pliny/middleware/instruments.rb @@ -19,7 +19,7 @@ def call(env) status, headers, response = @app.call(env) - if route = env["sinatra.route"] + if (route = env["sinatra.route"]) data.merge!(route_signature: route.split(" ").last) end diff --git a/lib/pliny/middleware/request_id.rb b/lib/pliny/middleware/request_id.rb index b3f1e69e..e4692da7 100644 --- a/lib/pliny/middleware/request_id.rb +++ b/lib/pliny/middleware/request_id.rb @@ -50,7 +50,7 @@ def raw_request_ids(env) # with no prefix, but Hermes went with one. Support both formats on # input. %w[HTTP_REQUEST_ID HTTP_X_REQUEST_ID].inject([]) do |request_ids, key| - if ids = env[key] + if (ids = env[key]) request_ids += ids.split(",") end request_ids From 74d52a91a8ee2c7e0eaea441d37c4dfbfbf858a8 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 15:41:25 +0200 Subject: [PATCH 52/64] fix Lint/ConstantDefinitionInBlock --- .rubocop_todo.yml | 10 ---------- spec/canonical_log_line_helpers_spec.rb | 14 +++++++------- spec/helpers/serialize_spec.rb | 18 +++++++++--------- spec/helpers/zulu_time_spec.rb | 8 ++++---- spec/middleware/rescue_errors_spec.rb | 20 ++++++++++---------- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index aa8e207f..7d94a500 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,16 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 4 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'spec/canonical_log_line_helpers_spec.rb' - - 'spec/helpers/serialize_spec.rb' - - 'spec/helpers/zulu_time_spec.rb' - - 'spec/middleware/rescue_errors_spec.rb' - # Offense count: 1 Lint/IneffectiveAccessModifier: Exclude: diff --git a/spec/canonical_log_line_helpers_spec.rb b/spec/canonical_log_line_helpers_spec.rb index 5ae7140a..94702266 100644 --- a/spec/canonical_log_line_helpers_spec.rb +++ b/spec/canonical_log_line_helpers_spec.rb @@ -2,15 +2,15 @@ require "spec_helper" -describe Pliny::CanonicalLogLineHelpers do - class TestCanonicalLogLine - include Pliny::CanonicalLogLineHelpers +class TestCanonicalLogLine + include Pliny::CanonicalLogLineHelpers - log_field :field_float, Float - log_field :field_integer, Integer - log_field :field_string, String - end + log_field :field_float, Float + log_field :field_integer, Integer + log_field :field_string, String +end +describe Pliny::CanonicalLogLineHelpers do it "allows a field to be set" do line = TestCanonicalLogLine.new line.field_string = "foo" diff --git a/spec/helpers/serialize_spec.rb b/spec/helpers/serialize_spec.rb index 059aa57c..f3dcf08b 100644 --- a/spec/helpers/serialize_spec.rb +++ b/spec/helpers/serialize_spec.rb @@ -2,6 +2,15 @@ require "spec_helper" +class Serializer + def initialize(opts) + end + + def serialize(data) + data + end +end + describe Pliny::Helpers::Serialize do context "without a serializer" do def app @@ -22,15 +31,6 @@ def app end context "with a serializer" do - class Serializer - def initialize(opts) - end - - def serialize(data) - data - end - end - def app Sinatra.new do register Pliny::Helpers::Serialize diff --git a/spec/helpers/zulu_time_spec.rb b/spec/helpers/zulu_time_spec.rb index 132fcda8..d35ade68 100644 --- a/spec/helpers/zulu_time_spec.rb +++ b/spec/helpers/zulu_time_spec.rb @@ -2,12 +2,12 @@ require "spec_helper" +class ZuluTimeTest + extend Pliny::Helpers::ZuluTime +end + describe Pliny::Helpers::ZuluTime do context "zulu_time" do - class ZuluTimeTest - extend Pliny::Helpers::ZuluTime - end - it "it formats Time instances" do formatted = ZuluTimeTest.zulu_time(Time.parse("2017-11-28T21:49:52.123+00:00")) assert_equal "2017-11-28T21:49:52Z", formatted diff --git a/spec/middleware/rescue_errors_spec.rb b/spec/middleware/rescue_errors_spec.rb index 3e07f9d0..c0906c1f 100644 --- a/spec/middleware/rescue_errors_spec.rb +++ b/spec/middleware/rescue_errors_spec.rb @@ -2,18 +2,18 @@ require "spec_helper" -describe Pliny::Middleware::RescueErrors do - include Rack::Test::Methods - - class BadMiddleware - def call(env) - if env["PATH_INFO"] == "/api-error" - raise Pliny::Errors::ServiceUnavailable - else - raise "Omg!" - end +class BadMiddleware + def call(env) + if env["PATH_INFO"] == "/api-error" + raise Pliny::Errors::ServiceUnavailable + else + raise "Omg!" end end +end + +describe Pliny::Middleware::RescueErrors do + include Rack::Test::Methods attr_reader :app From 52834e91407c8bcd80bdeb415d3d584d258fc684 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 15:42:42 +0200 Subject: [PATCH 53/64] fix Lint/IneffectiveAccessModifier --- .rubocop_todo.yml | 5 ----- lib/pliny/metrics/backends/logger.rb | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7d94a500..7f48e6e2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,11 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/IneffectiveAccessModifier: - Exclude: - - 'lib/pliny/metrics/backends/logger.rb' - # Offense count: 1 # Configuration parameters: MaximumRangeSize. Lint/MissingCopEnableDirective: diff --git a/lib/pliny/metrics/backends/logger.rb b/lib/pliny/metrics/backends/logger.rb index 995ea93d..c141be37 100644 --- a/lib/pliny/metrics/backends/logger.rb +++ b/lib/pliny/metrics/backends/logger.rb @@ -12,11 +12,11 @@ def self.report_measures(measures) Pliny.log(add_prefix(:measure, measures)) end - private - def self.add_prefix(type, metrics) metrics.map { |k, v| ["#{type}##{k}", v] }.to_h end + + private_class_method :add_prefix end end end From 1549de8061cf0cf5c11df07af7ab1fa857eab4b7 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 15:43:25 +0200 Subject: [PATCH 54/64] fix Lint/MissingCopEnableDirective --- .rubocop_todo.yml | 6 ------ lib/template/bin/run | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7f48e6e2..153cdaa9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Configuration parameters: MaximumRangeSize. -Lint/MissingCopEnableDirective: - Exclude: - - 'lib/template/bin/run' - # Offense count: 1 Lint/RescueException: Exclude: diff --git a/lib/template/bin/run b/lib/template/bin/run index 58398090..638bd462 100755 --- a/lib/template/bin/run +++ b/lib/template/bin/run @@ -6,3 +6,5 @@ require_relative "../lib/application" eval ARGV.join(" ") + +# rubocop:enable Security/Eval From a8534eb7b664a9329ae78f64713efc717e5ef8cf Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 16:03:08 +0200 Subject: [PATCH 55/64] fix Lint/RescueException --- .rubocop_todo.yml | 5 ----- lib/pliny/error_reporters/rollbar.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 153cdaa9..2430de90 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,11 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/RescueException: - Exclude: - - 'lib/pliny/error_reporters/rollbar.rb' - # Offense count: 1 Security/Eval: Exclude: diff --git a/lib/pliny/error_reporters/rollbar.rb b/lib/pliny/error_reporters/rollbar.rb index be4c6792..10d83b29 100644 --- a/lib/pliny/error_reporters/rollbar.rb +++ b/lib/pliny/error_reporters/rollbar.rb @@ -26,7 +26,7 @@ def fetch_scope(context:, rack_env:) scope[:person] = proc { extract_person_data_from_controller(rack_env) } end scope - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException report_exception_to_rollbar(rack_env, e) raise end From e6c0b5d39959bfee4d166ac29a975b6a4ebdbba0 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 16:04:22 +0200 Subject: [PATCH 56/64] disable Security/Eval --- .rubocop_todo.yml | 5 ----- spec/commands/generator/endpoint_spec.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2430de90..c1d27f65 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,11 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Security/Eval: - Exclude: - - 'spec/commands/generator/endpoint_spec.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/ComparableBetween: diff --git a/spec/commands/generator/endpoint_spec.rb b/spec/commands/generator/endpoint_spec.rb index c28c4b44..7accc51e 100644 --- a/spec/commands/generator/endpoint_spec.rb +++ b/spec/commands/generator/endpoint_spec.rb @@ -22,7 +22,7 @@ url_path: "/artists",) # eval and assign it to rack_app so tests are pointing to it - @rack_app = eval(template) + @rack_app = eval(template) # rubocop:disable Security/Eval end it "defines a stub GET /" do From cfaf137c4be9f110c080e1e7a8246d4676fd3092 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 16:27:47 +0200 Subject: [PATCH 57/64] fix Style/ComparableBetween --- .rubocop_todo.yml | 6 ------ spec/metrics_spec.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c1d27f65..91d287b9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/ComparableBetween: - Exclude: - - 'spec/metrics_spec.rb' - # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSplatArgument. diff --git a/spec/metrics_spec.rb b/spec/metrics_spec.rb index cc05d778..3d4c617e 100644 --- a/spec/metrics_spec.rb +++ b/spec/metrics_spec.rb @@ -71,7 +71,7 @@ end expect(test_backend).to have_received(:report_measures) do |opts| - assert(60 <= opts["pliny.foo"] && opts["pliny.foo"] <= 61) + assert(opts["pliny.foo"].between?(60, 61)) end end From f321ae88f2308737e2757086280021350366e2ec Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 18:10:24 +0200 Subject: [PATCH 58/64] fix Style/HashConversion --- .rubocop_todo.yml | 8 -------- lib/pliny/metrics.rb | 4 ++-- spec/integration_spec.rb | 6 +++--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 91d287b9..4c5a428c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 5 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowSplatArgument. -Style/HashConversion: - Exclude: - - 'lib/pliny/metrics.rb' - - 'spec/integration_spec.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: diff --git a/lib/pliny/metrics.rb b/lib/pliny/metrics.rb index 5957565b..56ec8935 100644 --- a/lib/pliny/metrics.rb +++ b/lib/pliny/metrics.rb @@ -9,7 +9,7 @@ module Metrics @backends = [Backends::Logger] def count(*names, value: 1) - counts = Hash[names.map { |n| ["#{Config.app_name}.#{n}", value] }] + counts = names.map { |n| ["#{Config.app_name}.#{n}", value] }.to_h backends.each do |backend| report_and_catch { backend.report_counts(counts) } @@ -34,7 +34,7 @@ def measure(*inputs, &block) 0 end - measures = Hash[inputs.map { |n| ["#{Config.app_name}.#{n}", measurement] }] + measures = inputs.map { |n| ["#{Config.app_name}.#{n}", measurement] }.to_h backends.each do |backend| report_and_catch { backend.report_measures(measures) } diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 2a0f7bb7..e17ad02e 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -85,7 +85,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = Hash[stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] + statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h assert statuses[migration_file.split("/").last] == "DOWN" end @@ -96,7 +96,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = Hash[stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }] + statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h assert statuses[migration_file.split("/").last] == "UP" end @@ -109,7 +109,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = Hash[stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^ +| +$)/, "") }.select(&:present?).reverse }] + statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^ +| +$)/, "") }.select(&:present?).reverse }.to_h assert statuses[migration_file.split("/").last] == "FILE MISSING" end end From 838a54fb82e9eb0dd87ca80fdf0bdf1c3cc0c747 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 18:10:54 +0200 Subject: [PATCH 59/64] fix Style/RedundantInterpolation --- .rubocop_todo.yml | 6 ------ lib/pliny/log.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4c5a428c..8d3478df 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/RedundantInterpolation: - Exclude: - - 'lib/pliny/log.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index 0c4fc761..5ee8e7bb 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -156,7 +156,7 @@ def unparse_pair(k, v) elsif v.is_a?(Time) "#{k}=#{v.iso8601}" else - v = "#{v}" + v = v.to_s v = replace_newlines(v) v = quote_string(v) if v =~ /\s/ From e2a3c5420b032a4214a9818404f07cd67d98a8b7 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 18:11:48 +0200 Subject: [PATCH 60/64] fix Style/SafeNavigation --- .rubocop_todo.yml | 11 ----------- lib/pliny/config_helpers.rb | 4 +--- lib/pliny/helpers/zulu_time.rb | 2 +- lib/pliny/log.rb | 12 +++++------- lib/pliny/request_store.rb | 2 +- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8d3478df..d0205ab3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,17 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 4 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. -# AllowedMethods: present?, blank?, presence, try, try! -Style/SafeNavigation: - Exclude: - - 'lib/pliny/config_helpers.rb' - - 'lib/pliny/helpers/zulu_time.rb' - - 'lib/pliny/log.rb' - - 'lib/pliny/request_store.rb' - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Style/SlicingWithRange: diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index b859c0be..ed2453cc 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -45,9 +45,7 @@ def symbol # => ['a', 'b'] def array(method = nil) ->(v) do - if v - v.split(",").map { |a| cast(a, method) } - end + v&.split(",")&.map { |a| cast(a, method) } end end diff --git a/lib/pliny/helpers/zulu_time.rb b/lib/pliny/helpers/zulu_time.rb index 3431d73a..f804881d 100644 --- a/lib/pliny/helpers/zulu_time.rb +++ b/lib/pliny/helpers/zulu_time.rb @@ -3,7 +3,7 @@ module Pliny::Helpers module ZuluTime def zulu_time(time) - time ? time.getutc.strftime("%Y-%m-%dT%H:%M:%SZ") : nil + time&.getutc&.strftime("%Y-%m-%dT%H:%M:%SZ") end end end diff --git a/lib/pliny/log.rb b/lib/pliny/log.rb index 5ee8e7bb..41d21a0e 100644 --- a/lib/pliny/log.rb +++ b/lib/pliny/log.rb @@ -18,13 +18,11 @@ def log_exception(e, data = {}) exception_id = e.object_id # Log backtrace in reverse order for easier digestion. - if e.backtrace - e.backtrace.reverse.each do |backtrace| - log_to_stream(stderr || $stderr, merge_log_contexts( - exception_id: exception_id, - backtrace: backtrace, - ),) - end + e.backtrace&.reverse&.each do |backtrace| + log_to_stream(stderr || $stderr, merge_log_contexts( + exception_id: exception_id, + backtrace: backtrace, + ),) end # then log the exception message last so that it's as close to the end of diff --git a/lib/pliny/request_store.rb b/lib/pliny/request_store.rb index 33d680c1..aaf4d5f3 100644 --- a/lib/pliny/request_store.rb +++ b/lib/pliny/request_store.rb @@ -8,7 +8,7 @@ def self.clear! def self.seed(env) store[:request_id] = - env["REQUEST_IDS"] ? env["REQUEST_IDS"].join(",") : nil + env["REQUEST_IDS"]&.join(",") # a global context that evolves over the lifetime of the request, and is # used to tag all log messages that it produces From bda4029591f7bc0bbff8677f05781e7b397d53d4 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 18:13:09 +0200 Subject: [PATCH 61/64] fix Style/SlicingWithRange --- .rubocop_todo.yml | 7 ------- lib/pliny/tasks/db.rake | 2 +- spec/integration_spec.rb | 6 +++--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d0205ab3..f2d7fc3c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 4 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/SlicingWithRange: - Exclude: - - 'lib/pliny/tasks/db.rake' - - 'spec/integration_spec.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/lib/pliny/tasks/db.rake b/lib/pliny/tasks/db.rake index ed8428c0..677e67ed 100644 --- a/lib/pliny/tasks/db.rake +++ b/lib/pliny/tasks/db.rake @@ -167,7 +167,7 @@ begin end def name_from_uri(uri) - URI.parse(uri).path[1..-1] + URI.parse(uri).path[1..] end end rescue LoadError diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index e17ad02e..bec98721 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -85,7 +85,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h + statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h assert statuses[migration_file.split("/").last] == "DOWN" end @@ -96,7 +96,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h + statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.tr(" ", "") }.select(&:present?).reverse }.to_h assert statuses[migration_file.split("/").last] == "UP" end @@ -109,7 +109,7 @@ stdout, _ = bash_with_output("rake db:migrate:status") - statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..-1].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^ +| +$)/, "") }.select(&:present?).reverse }.to_h + statuses = stdout.to_s.split(/\+-+\+-+\+/)[2..].map { |s| s.tr("\n", "") }.select(&:present?).map { |s| s.split("|").map { |s| s.gsub(/(^ +| +$)/, "") }.select(&:present?).reverse }.to_h assert statuses[migration_file.split("/").last] == "FILE MISSING" end end From 198d7fa34cd48cbe85e9f6103aeb97379bf8cc53 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 18:14:10 +0200 Subject: [PATCH 62/64] fix Style/YodaCondition --- .rubocop_todo.yml | 9 --------- spec/middleware/metrics_spec.rb | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f2d7fc3c..65ceecd3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,12 +5,3 @@ # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only -Style/YodaCondition: - Exclude: - - 'spec/metrics_spec.rb' - - 'spec/middleware/metrics_spec.rb' diff --git a/spec/middleware/metrics_spec.rb b/spec/middleware/metrics_spec.rb index f4cde43e..3f0bc800 100644 --- a/spec/middleware/metrics_spec.rb +++ b/spec/middleware/metrics_spec.rb @@ -59,7 +59,7 @@ def app it "measures the request latency" do expect(Pliny::Metrics).to receive(:measure) do |key, opts| assert_equal(key, "requests.latency") - assert(4 < opts[:value] && opts[:value] < 6) + assert(opts[:value] > 4 && opts[:value] < 6) end get "/hello" From d861db24fd801ba1bc53d7c851e3c80a6163f329 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Mon, 8 Sep 2025 18:55:24 +0200 Subject: [PATCH 63/64] remove .rubocop_todo.yml --- .rubocop.yml | 1 - .rubocop_todo.yml | 7 ------- 2 files changed, 8 deletions(-) delete mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index f77cd3d9..e73a5de6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,6 @@ inherit_from: - .rubocop_standardrb.yml - .rubocop_standardrb_overrides.yml - - .rubocop_todo.yml AllCops: NewCops: disable diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 65ceecd3..00000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,7 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config --no-exclude-limit --no-auto-gen-timestamp` -# using RuboCop version 1.80.2. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. From a6a4d58c2a3d7e81da5f581899f7e89a90016a49 Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Tue, 9 Sep 2025 13:14:44 +0200 Subject: [PATCH 64/64] Update spec/middleware/metrics_spec.rb Co-authored-by: Troels Thomsen <19824+tt@users.noreply.github.com> --- spec/middleware/metrics_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/middleware/metrics_spec.rb b/spec/middleware/metrics_spec.rb index 3f0bc800..e142a73b 100644 --- a/spec/middleware/metrics_spec.rb +++ b/spec/middleware/metrics_spec.rb @@ -59,7 +59,7 @@ def app it "measures the request latency" do expect(Pliny::Metrics).to receive(:measure) do |key, opts| assert_equal(key, "requests.latency") - assert(opts[:value] > 4 && opts[:value] < 6) + assert_in_delta(5, opts[:value], 1) end get "/hello"