Skip to content

Handle empty configuration as no configuration #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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