lib/goodcheck/config_loader.rb in goodcheck-2.7.0 vs lib/goodcheck/config_loader.rb in goodcheck-3.0.0

- old
+ new

@@ -101,28 +101,31 @@ pattern: array_or(pattern), message: string, justification: optional(array_or(string)), glob: optional(glob), pass: optional(array_or(string)), - fail: optional(array_or(string)) + fail: optional(array_or(string)), + severity: optional(string) ) let :negative_rule, object( id: string, not: object(pattern: array_or(pattern)), message: string, justification: optional(array_or(string)), glob: optional(glob), pass: optional(array_or(string)), - fail: optional(array_or(string)) + fail: optional(array_or(string)), + severity: optional(string) ) let :nopattern_rule, object( id: string, message: string, justification: optional(array_or(string)), - glob: glob + glob: glob, + severity: optional(string) ) let :positive_trigger, object( pattern: array_or(pattern), glob: optional(glob), @@ -161,11 +164,12 @@ let :triggered_rule, object( id: string, message: string, justification: optional(array_or(string)), - trigger: array_or(trigger) + trigger: array_or(trigger), + severity: optional(string) ) let :rule, enum(positive_rule, negative_rule, nopattern_rule, @@ -185,18 +189,21 @@ end }) let :rules, array(rule) - let :import_target, string - let :imports, array(import_target) - let :exclude, array_or(string) + let :severity, object( + allow: optional(array(string)), + required: boolean? + ) let :config, object( rules: optional(rules), - import: optional(imports), - exclude: optional(exclude) + import: optional(array(string)), + exclude: optional(array_or(string)), + exclude_binary: boolean?, + severity: optional(severity) ) end attr_reader :path attr_reader :content @@ -222,26 +229,31 @@ Array(content[:import]).each do |import| load_import rules, import end - exclude_paths = Array(content[:exclude]) - - Config.new(rules: rules, exclude_paths: exclude_paths) + Config.new( + rules: rules, + exclude_paths: Array(content[:exclude]), + exclude_binary: content[:exclude_binary], + severity: content[:severity] + ) end def load_rules(rules, array) array.each do |hash| rules << load_rule(hash) + rescue RegexpError => exn + raise InvalidPattern, "Invalid pattern of the `#{hash.fetch(:id)}` rule in `#{path}`: #{exn.message}" end end def load_import(rules, import) Goodcheck.logger.info "Importing rules from #{import}" - import_loader.load(import) do |content| - json = JSON.parse(JSON.dump(YAML.load(content, filename: import)), symbolize_names: true) + import_loader.load(import) do |content, filename| + json = JSON.parse(JSON.dump(YAML.safe_load(content, filename: filename)), symbolize_names: true) Schema.rules.coerce json load_rules(rules, json) end end @@ -251,11 +263,12 @@ id = hash[:id] triggers = retrieve_triggers(hash) justifications = array(hash[:justification]) message = hash[:message].chomp + severity = hash[:severity] - Rule.new(id: id, message: message, justifications: justifications, triggers: triggers) + Rule.new(id: id, message: message, justifications: justifications, triggers: triggers, severity: severity) end def retrieve_triggers(hash) if hash.key?(:trigger) array(hash[:trigger]).map do |trigger|