Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate warnings about deprecated tags #2293

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/ansiblelint/skip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import logging
from functools import lru_cache
from itertools import product
from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional, Sequence
from typing import TYPE_CHECKING, Any, Dict, Generator, List, Optional, Sequence, Set

# Module 'ruamel.yaml' does not explicitly export attribute 'YAML'; implicit reexport disabled
from ruamel.yaml import YAML
Expand All @@ -35,7 +35,7 @@
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject

_logger = logging.getLogger(__name__)

_found_deprecated_tags: Set[str] = set()

# playbook: Sequence currently expects only instances of one of the two
# classes below but we should consider avoiding this chimera.
Expand All @@ -46,15 +46,18 @@
def get_rule_skips_from_line(line: str) -> List[str]:
"""Return list of rule ids skipped via comment on the line of yaml."""
_before_noqa, _noqa_marker, noqa_text = line.partition("# noqa")

result = []
for v in noqa_text.lstrip(" :").split():
if v in RENAMED_TAGS:
tag = RENAMED_TAGS[v]
_logger.warning(
"Replaced outdated tag '%s' with '%s', replace it to avoid future regressions.",
v,
tag,
)
if v not in _found_deprecated_tags:
_logger.warning(
"Replaced outdated tag '%s' with '%s', replace it to avoid future regressions",
v,
tag,
)
_found_deprecated_tags.add(v)
v = tag
result.append(v)
return result
Expand Down