diff --git a/ansiblelater/candidate.py b/ansiblelater/candidate.py index cbbcbf6..78adebf 100644 --- a/ansiblelater/candidate.py +++ b/ansiblelater/candidate.py @@ -43,6 +43,13 @@ class Candidate(object): def _get_version(self): path = self.path version = None + config_version = self.config["rules"]["version"].strip() + + if config_version: + version_config_re = re.compile(r"([\d.]+)") + match = version_config_re.match(config_version) + if match: + version = match.group(1) if not self.binary: if isinstance(self, RoleFile): @@ -54,11 +61,10 @@ class Candidate(object): break parentdir = os.path.dirname(parentdir) - version_re = re.compile(r"^# Standards:\s*([\d.]+)") - + version_file_re = re.compile(r"^# Standards:\s*([\d.]+)") with codecs.open(path, mode="rb", encoding="utf-8") as f: for line in f: - match = version_re.match(line) + match = version_file_re.match(line) if match: version = match.group(1) diff --git a/ansiblelater/settings.py b/ansiblelater/settings.py index 1d7cba6..fcf57f7 100644 --- a/ansiblelater/settings.py +++ b/ansiblelater/settings.py @@ -121,7 +121,8 @@ class Settings(object): "filter": [], "exclude_filter": [], "ignore_dotfiles": True, - "exclude_files": [] + "exclude_files": [], + "version": "" }, "logging": { "level": "WARNING", diff --git a/docs/content/configuration/defaults.md b/docs/content/configuration/defaults.md index 198d077..6897254 100644 --- a/docs/content/configuration/defaults.md +++ b/docs/content/configuration/defaults.md @@ -13,6 +13,7 @@ ansible: # Modules which are bundled with the role and placed in a './library' # directory will be auto-detected and don't need to be added to this list. custom_modules: [] + # Settings for variable formatting rule (ANSIBLE0004) double-braces: max-spaces-inside: 1 @@ -24,12 +25,16 @@ ansible: logging: # You can enable JSON logging if a parsable output is required json: False + # Possible options debug | info | warning | error | critical level: "warning" # Global settings for all defined rules rules: - # list of files to exclude + # Disable build-in rules if required + buildin: True + + # List of files to exclude exclude_files: [] # Examples: # - molecule/ @@ -45,8 +50,13 @@ rules: # All dotfiles (including hidden folders) are excluded by default. # You can disable this setting and handle dotfiles by yourself with `exclude_files`. ignore_dotfiles: True - # Path to the folder containing your custom standards file - standards: ansiblelater/data + + # List of directories to load standard rules from (defaults to build-in) + standards: [] + + # Standard version to use. Standard version set in a roles meta file + # or playbook will takes precedence. + version: # Block to control included yamllint rules. # See https://yamllint.readthedocs.io/en/stable/rules.html