Skip to content

Commit

Permalink
Merge pull request #492 from miry/empty-config-load
Browse files Browse the repository at this point in the history
Handle empty configuration as no configuration
  • Loading branch information
veelenga authored Nov 17, 2024
2 parents 13ba303 + 6f6c101 commit 0e8ead1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/ameba/config_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ module Ameba
config.globs.should eq Config::DEFAULT_GLOBS
end

it "loads default globs when config is empty" do
yml = YAML.parse <<-CONFIG
# Empty config with comment
CONFIG
config = Config.new(yml)
config.globs.should eq Config::DEFAULT_GLOBS
end

it "initializes globs as string" do
yml = YAML.parse <<-CONFIG
---
Expand Down
3 changes: 3 additions & 0 deletions src/ameba/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class Ameba::Config
#
# `Config.load` uses this constructor to instantiate new config by YAML file.
protected def initialize(config : YAML::Any)
if config.raw.nil?
config = YAML.parse("{}")
end
@rules = Rule.rules.map &.new(config).as(Rule::Base)
@rule_groups = @rules.group_by &.group
@excluded = load_array_section(config, "Excluded")
Expand Down

0 comments on commit 0e8ead1

Please sign in to comment.