-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also detect yamllint rule violations when this is found as installed. This will allow us to remove a set of rules that overlapped with general YAML syntax ones. Fixes: #953
- Loading branch information
Showing
19 changed files
with
134 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
rules: | ||
document-start: disable | ||
indentation: | ||
level: error | ||
indent-sequences: consistent | ||
# ignore added because this file includes on-purpose errors | ||
ignore: | | ||
examples/example.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import logging | ||
import os | ||
import sys | ||
from typing import TYPE_CHECKING, List | ||
|
||
from ansiblelint.rules import AnsibleLintRule | ||
|
||
if TYPE_CHECKING: | ||
from ansiblelint.errors import MatchError | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
# yamllint is a soft-dependency (not installed by default) | ||
try: | ||
from yamllint.config import YamlLintConfig | ||
from yamllint.linter import run as run_yamllint | ||
except ImportError: | ||
pass | ||
|
||
|
||
YAMLLINT_CONFIG = """ | ||
extends: default | ||
rules: | ||
document-start: disable | ||
line-length: disable | ||
""" | ||
|
||
|
||
class YamllintRule(AnsibleLintRule): | ||
id = 'yamllint' | ||
shortdesc = 'Reported by yamllint' | ||
description = 'Rule violations reported by YamlLint when this is available.' | ||
severity = 'VERY_LOW' | ||
tags = ['formatting', 'experimental'] | ||
version_added = 'v5.0.0' | ||
config = None | ||
if "yamllint.config" in sys.modules: | ||
config = YamlLintConfig(content=YAMLLINT_CONFIG) | ||
# if we detect local yamllint config we use it but raise a warning | ||
# as this is likely to get out of sync with our internal config. | ||
for file in ['.yamllint', '.yamllint.yaml', '.yamllint.yml']: | ||
if os.path.isfile(file): | ||
_logger.warning( | ||
"Loading custom %s config file, this extends our " | ||
"internal yamllint config.", | ||
file) | ||
config_override = YamlLintConfig(file=file) | ||
config_override.extend(config) | ||
break | ||
_logger.debug("Effective yamllint rules used: %s", config.rules) | ||
|
||
def __init__(self): | ||
"""Construct a rule instance.""" | ||
# customize id by adding the one reported by yamllint | ||
self.id = self.__class__.id | ||
|
||
def matchyaml(self, file, text: str) -> List["MatchError"]: | ||
"""Return matches found for a specific YAML text.""" | ||
matches = [] | ||
if YamllintRule.config: | ||
for p in run_yamllint(text, YamllintRule.config): | ||
matches.append( | ||
self.create_matcherror( | ||
message=p.desc, | ||
linenumber=p.line, | ||
details="", | ||
filename=file['path'], | ||
id=p.rule)) | ||
return matches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.