feat: allow to set standards version in config file (#69)

* feat: allow to set standards version in config file

* add documentation
This commit is contained in:
Robert Kaussow 2021-02-01 20:27:00 +01:00 committed by GitHub
parent b1dd83cea6
commit 53444a4a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -43,6 +43,13 @@ class Candidate(object):
def _get_version(self): def _get_version(self):
path = self.path path = self.path
version = None 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 not self.binary:
if isinstance(self, RoleFile): if isinstance(self, RoleFile):
@ -54,11 +61,10 @@ class Candidate(object):
break break
parentdir = os.path.dirname(parentdir) 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: with codecs.open(path, mode="rb", encoding="utf-8") as f:
for line in f: for line in f:
match = version_re.match(line) match = version_file_re.match(line)
if match: if match:
version = match.group(1) version = match.group(1)

View File

@ -121,7 +121,8 @@ class Settings(object):
"filter": [], "filter": [],
"exclude_filter": [], "exclude_filter": [],
"ignore_dotfiles": True, "ignore_dotfiles": True,
"exclude_files": [] "exclude_files": [],
"version": ""
}, },
"logging": { "logging": {
"level": "WARNING", "level": "WARNING",

View File

@ -13,6 +13,7 @@ ansible:
# Modules which are bundled with the role and placed in a './library' # 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. # directory will be auto-detected and don't need to be added to this list.
custom_modules: [] custom_modules: []
# Settings for variable formatting rule (ANSIBLE0004) # Settings for variable formatting rule (ANSIBLE0004)
double-braces: double-braces:
max-spaces-inside: 1 max-spaces-inside: 1
@ -24,12 +25,16 @@ ansible:
logging: logging:
# You can enable JSON logging if a parsable output is required # You can enable JSON logging if a parsable output is required
json: False json: False
# Possible options debug | info | warning | error | critical # Possible options debug | info | warning | error | critical
level: "warning" level: "warning"
# Global settings for all defined rules # Global settings for all defined rules
rules: rules:
# list of files to exclude # Disable build-in rules if required
buildin: True
# List of files to exclude
exclude_files: [] exclude_files: []
# Examples: # Examples:
# - molecule/ # - molecule/
@ -45,8 +50,13 @@ rules:
# All dotfiles (including hidden folders) are excluded by default. # All dotfiles (including hidden folders) are excluded by default.
# You can disable this setting and handle dotfiles by yourself with `exclude_files`. # You can disable this setting and handle dotfiles by yourself with `exclude_files`.
ignore_dotfiles: True 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. # Block to control included yamllint rules.
# See https://yamllint.readthedocs.io/en/stable/rules.html # See https://yamllint.readthedocs.io/en/stable/rules.html