class Ameba::Config
- Ameba::Config
- Reference
- Object
Overview
A configuration entry for Ameba::Runner
.
Config can be loaded from configuration YAML file and adjusted.
config = Config.load
config.formatter = my_formatter
By default config loads .ameba.yml
file located in a current
working directory.
If it cannot be found until reaching the root directory, then it will be searched for in the user’s global config locations, which consists of a dotfile or a config file inside the XDG Base Directory specification.
~/.ameba.yml
$XDG_CONFIG_HOME/ameba/config.yml
(expands to~/.config/ameba/config.yml
if$XDG_CONFIG_HOME
is not set)
If both files exist, the dotfile will be selected.
As an example, if Ameba is invoked from inside /path/to/project/lib/utils
,
then it will use the config as specified inside the first of the following files:
/path/to/project/lib/utils/.ameba.yml
/path/to/project/lib/.ameba.yml
/path/to/project/.ameba.yml
/path/to/.ameba.yml
/path/.ameba.yml
/.ameba.yml
~/.ameba.yml
~/.config/ameba/config.yml
Included Modules
Defined in:
ameba/config.crConstant 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_GLOBS =
["**/*.cr", "!lib"] of ::String
-
DEFAULT_PATH =
Path[Dir.current] / FILENAME
-
DEFAULT_PATHS =
{Path["~"] / FILENAME, Path[XDG_CONFIG_HOME] / "ameba/config.yml"}
-
FILENAME =
".ameba.yml"
-
XDG_CONFIG_HOME =
ENV.fetch("XDG_CONFIG_HOME", "~/.config")
Class Method Summary
- .formatter_names
-
.load(path = nil, colors = true, skip_reading_config = false)
Loads YAML configuration file by
path
.
Instance Method Summary
-
#autocorrect=(autocorrect : Bool)
Returns
true
if correctable issues should be autocorrected. -
#autocorrect? : Bool
Returns
true
if correctable issues should be autocorrected. -
#excluded : Array(String)
Represents a list of paths to exclude from globs.
-
#excluded=(excluded : Array(String))
Represents a list of paths to exclude from globs.
-
#formatter : Formatter::BaseFormatter
Returns a formatter to be used while inspecting files.
-
#formatter=(name : String | Symbol)
Sets formatter by name.
-
#formatter=(formatter : Formatter::BaseFormatter)
Returns a formatter to be used while inspecting files.
-
#globs : Array(String)
Returns a list of paths (with wildcards) to files.
-
#globs=(globs : Array(String))
Returns a list of paths (with wildcards) to files.
- #rules : Array(Rule::Base)
- #severity : Ameba::Severity
- #severity=(severity : Ameba::Severity)
-
#sources
Returns a list of sources matching globs and excluded sections.
-
#stdin_filename : String | Nil
Returns a filename if reading source file from STDIN.
-
#stdin_filename=(stdin_filename : String | Nil)
Returns a filename if reading source file from STDIN.
-
#update_rule(name, enabled = true, excluded = nil)
Updates rule properties.
-
#update_rules(names, enabled = true, excluded = nil)
Updates rules properties.
-
#version : SemanticVersion | Nil
Returns an ameba version to be used by
Ameba::Runner
. -
#version=(version : SemanticVersion | Nil)
Returns an ameba version to be used by
Ameba::Runner
. -
#version=(version : String)
Sets version from string.
Instance methods inherited from module Ameba::GlobUtils
expand(globs)
expand,
find_files_by_globs(globs)
find_files_by_globs
Class Method Detail
Loads YAML configuration file by path
.
config = Ameba::Config.load
Instance Method Detail
Represents a list of paths to exclude from globs. Can have wildcards.
config = Ameba::Config.load
config.excluded = ["spec", "src/server/*.cr"]
Represents a list of paths to exclude from globs. Can have wildcards.
config = Ameba::Config.load
config.excluded = ["spec", "src/server/*.cr"]
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
Sets formatter by name.
config = Ameba::Config.load
config.formatter = :progress
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
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 = ["**/*.cr"]
config.globs
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 = ["**/*.cr"]
config.globs
Returns a list of sources matching globs and excluded sections.
config = Ameba::Config.load
config.sources # => list of default sources
config.globs = ["**/*.cr"]
config.excluded = ["spec"]
config.sources # => list of sources pointing to files found by the wildcards
Returns a filename if reading source file from STDIN.
Updates rule properties.
config = Ameba::Config.load
config.update_rule "MyRuleName", enabled: false
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
Returns an ameba version to be used by Ameba::Runner
.
Sets version from string.
config = Ameba::Config.load
config.version = "1.6.0"