From 6a10ea8127763d59468030b46a411d60617a71f7 Mon Sep 17 00:00:00 2001 From: Anton Maminov Date: Fri, 17 Feb 2023 07:18:37 +0200 Subject: [PATCH] bump ameba to 1.4.0 and fix warnings (#654) --- .ameba.yml | 19 +++++++++++++++---- shard.yml | 2 +- spec/config_spec.cr | 2 +- src/kemal.cr | 2 +- src/kemal/config.cr | 6 +++--- src/kemal/init_handler.cr | 2 +- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index 9cc083d..d7b2b9a 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -1,13 +1,24 @@ # This configuration file was generated by `ameba --gen-config` -# on 2019-08-25 09:29:24 UTC using Ameba version 0.10.0. +# on 2023-01-30 12:35:15 UTC using Ameba version 1.4.0. # The point is for the user to remove these configuration records # one by one as the reported problems are removed from the code base. -# Problems found: 7 +# Problems found: 2 # Run `ameba --only Lint/UselessAssign` for details Lint/UselessAssign: Description: Disallows useless variable assignments - Enabled: true - Severity: Warning Excluded: - spec/view_spec.cr + Enabled: true + Severity: Warning + +# Problems found: 6 +# Run `ameba --only Lint/NotNil` for details +Lint/NotNil: + Description: Identifies usage of `not_nil!` calls + Excluded: + - src/kemal/param_parser.cr + - src/kemal/static_file_handler.cr + - src/kemal/config.cr + Enabled: true + Severity: Warning diff --git a/shard.yml b/shard.yml index 3b9014d..f8b9a77 100644 --- a/shard.yml +++ b/shard.yml @@ -15,7 +15,7 @@ dependencies: development_dependencies: ameba: github: crystal-ameba/ameba - version: ~> 1.0 + version: ~> 1.4.0 crystal: ">= 0.36.0" diff --git a/spec/config_spec.cr b/spec/config_spec.cr index daa6849..a7fc35c 100644 --- a/spec/config_spec.cr +++ b/spec/config_spec.cr @@ -16,7 +16,7 @@ describe "Config" do end it "sets default powered_by_header to true" do - Kemal::Config.new.powered_by_header.should be_true + Kemal::Config.new.powered_by_header?.should be_true end it "sets host binding" do diff --git a/src/kemal.cr b/src/kemal.cr index 9222fe6..5d43f15 100644 --- a/src/kemal.cr +++ b/src/kemal.cr @@ -27,7 +27,7 @@ module Kemal # # To use custom command line arguments, set args to nil # - def self.run(port : Int32? = nil, args = ARGV, trap_signal : Bool = true, &block) + def self.run(port : Int32? = nil, args = ARGV, trap_signal : Bool = true, &) Kemal::CLI.new args config = Kemal.config config.setup diff --git a/src/kemal/config.cr b/src/kemal/config.cr index 23372dd..3716960 100644 --- a/src/kemal/config.cr +++ b/src/kemal/config.cr @@ -20,11 +20,11 @@ module Kemal @ssl : OpenSSL::SSL::Context::Server? {% end %} - property host_binding, ssl, port, env, public_folder, logging, running + property app_name, host_binding, ssl, port, env, public_folder, logging, running property always_rescue, server : HTTP::Server?, extra_options, shutdown_message property serve_static : (Bool | Hash(String, Bool)) property static_headers : (HTTP::Server::Response, String, File::Info -> Void)? - property powered_by_header : Bool = true, app_name + property? powered_by_header : Bool = true def initialize @app_name = "Kemal" @@ -159,7 +159,7 @@ module Kemal end end - def self.config + def self.config(&) yield Config::INSTANCE end diff --git a/src/kemal/init_handler.cr b/src/kemal/init_handler.cr index 881325b..318576a 100644 --- a/src/kemal/init_handler.cr +++ b/src/kemal/init_handler.cr @@ -7,7 +7,7 @@ module Kemal INSTANCE = new def call(context : HTTP::Server::Context) - context.response.headers.add "X-Powered-By", "Kemal" if Kemal.config.powered_by_header + context.response.headers.add "X-Powered-By", "Kemal" if Kemal.config.powered_by_header? context.response.content_type = "text/html" unless context.response.headers.has_key?("Content-Type") call_next context end