class Ameba::Config

Overview

A configuration entry for Ameba::Runner.

Config can be loaded from configuration YAML file and adjusted.

config = Ameba::Config.load
config.formatter = my_formatter

Included Modules

Extended Modules

Defined in:

ameba/config.cr
ameba/config/loader.cr
ameba/config/rule_config.cr

Constant Summary

AVAILABLE_FORMATTERS = { progress: Formatter::DotFormatter, todo: Formatter::TODOFormatter, flycheck: Formatter::FlycheckFormatter, silent: Formatter::BaseFormatter, disabled: Formatter::DisabledFormatter, json: Formatter::JSONFormatter, "github-actions": Formatter::GitHubActionsFormatter, }
DEFAULT_EXCLUDED = Set {"lib"}
DEFAULT_GLOBS = Set {"**/*.{cr,ecr}"}

Class Method Summary

Instance Method Summary

Instance methods inherited from module Ameba::GlobUtils

expand(globs, root = Dir.current) expand, find_files_by_globs(globs, root = Dir.current) find_files_by_globs

Class Method Detail

def self.formatter_names(separator = '|') #

Returns available formatter names joined by separator.


Instance Method Detail

def autocorrect=(autocorrect : Bool) #

Returns true if correctable issues should be autocorrected.


def autocorrect? : Bool #

Returns true if correctable issues should be autocorrected.


def excluded : Set(String) #

Represents a list of paths to exclude from globs. Can have wildcards.

config = Ameba::Config.load
config.excluded = Set{"spec", "src/server/*.cr"}

def excluded=(excluded : Set(String)) #

Represents a list of paths to exclude from globs. Can have wildcards.

config = Ameba::Config.load
config.excluded = Set{"spec", "src/server/*.cr"}

def files #

Returns a list of files matching globs and excluded sections.

config = Ameba::Config.load
config.files # => list of default files
config.globs = Set{"**/*.cr", "**/*.ecr"}
config.excluded = Set{"spec"}
config.files # => list of files found by the wildcards

def formatter : Formatter::BaseFormatter #

Returns a formatter to be used while inspecting files. If formatter is not set, it will return default formatter.

config = Ameba::Config.load
config.formatter = custom_formatter
config.formatter

def formatter=(name : String | Symbol) #

Sets formatter by name.

config = Ameba::Config.load
config.formatter = :progress

def formatter=(formatter : Formatter::BaseFormatter) #

Returns a formatter to be used while inspecting files. If formatter is not set, it will return default formatter.

config = Ameba::Config.load
config.formatter = custom_formatter
config.formatter

def globs : Set(String) #

Returns a list of paths (with wildcards) to files. Represents a list of sources to be inspected. If globs are not set, it will return default list of files.

config = Ameba::Config.load
config.globs = Set{"**/*.cr"}
config.globs

def globs=(globs : Set(String)) #

Returns a list of paths (with wildcards) to files. Represents a list of sources to be inspected. If globs are not set, it will return default list of files.

config = Ameba::Config.load
config.globs = Set{"**/*.cr"}
config.globs

def root : Path #

Returns a root directory to be used by Ameba::Runner.


def root=(root : Path) #

Returns a root directory to be used by Ameba::Runner.


def rules : Array(Rule::Base) #

Returns an array of configured rules.


def severity : Severity #

Returns minimum reported severity.


def severity=(severity : Severity) #

Returns minimum reported severity.


def sources #

Returns a list of sources matching globs and excluded sections.

config = Ameba::Config.load
config.sources # => list of default sources
config.globs = Set{"**/*.cr", "**/*.ecr"}
config.excluded = Set{"spec"}
config.sources # => list of sources pointing to files found by the wildcards

def stdin_filename : String | Nil #

Returns a filename if reading source file from STDIN.


def stdin_filename=(stdin_filename : String | Nil) #

Returns a filename if reading source file from STDIN.


def update_rule(name, *, enabled, excluded = nil) #

Updates rule properties.

config = Ameba::Config.load
config.update_rule "MyRuleName", enabled: false

def update_rules(names : Enumerable(String), *, enabled, excluded = nil) #

Updates rules properties.

config = Ameba::Config.load
config.update_rules %w[Rule1 Rule2], enabled: true

also it allows to update groups of rules:

config.update_rules %w[Group1 Group2], enabled: true

def version : SemanticVersion | Nil #

Returns an ameba version to be used by Ameba::Runner.


def version=(version : SemanticVersion | Nil) #

Returns an ameba version to be used by Ameba::Runner.


def version=(version : String) #

Sets version from string.

config = Ameba::Config.load
config.version = "1.6.0"