Skip to content

Commit

Permalink
Check for missing or duplicated anchors, rework #2
Browse files Browse the repository at this point in the history
  • Loading branch information
newrushbolt committed Feb 27, 2022
1 parent 3ad948c commit a52d0eb
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 213 deletions.
11 changes: 3 additions & 8 deletions docs/rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ This page describes the rules and their options.
:local:
:depth: 1

anchor-duplicates
------
anchors
-------

.. automodule:: yamllint.rules.anchor_duplicates
.. automodule:: yamllint.rules.anchors

braces
------
Expand Down Expand Up @@ -123,8 +123,3 @@ truthy
---------------

.. automodule:: yamllint.rules.truthy

unknown-aliases
---------------

.. automodule:: yamllint.rules.unknown_aliases
44 changes: 0 additions & 44 deletions tests/rules/test_anchor_duplicates.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
from tests.common import RuleTestCase


NORMAL_ANCHOR = '''---
key: &keyanchor a
otherkey: *keyanchor
'''

NORMAL_ANCHOR_NO_DOC_START = '''---
key: &keyanchor a
otherkey: *keyanchor
'''

DUPLICATED_ANCHOR = '''---
key1: &keyanchor a
key2: &keyanchor b
otherkey: *keyanchor
'''

HIT_ANCHOR_POINTER = '''---
key: &keyanchor a
otherkey: *keyanchor
Expand Down Expand Up @@ -67,33 +83,83 @@
'''


class UnknownAliasesTestCase(RuleTestCase):
rule_id = 'unknown-aliases'

DEFAULT = {'forbid-unknown-aliases': True,
'forbid-duplicated-anchors': False}


class AnchorsTestCase(RuleTestCase):
rule_id = 'anchors'

def test_disabled(self):
conf = 'unknown-aliases: disable'
conf = ('anchors:\n'
' forbid-unknown-aliases: false\n'
' forbid-duplicated-anchors: false\n'
)

self.check(NORMAL_ANCHOR, conf)
self.check(NORMAL_ANCHOR_NO_DOC_START, conf)
self.check(DUPLICATED_ANCHOR, conf)
self.check(HIT_ANCHOR_POINTER, conf)
self.check(MISS_ANCHOR_POINTER, conf)
self.check(HIT_ANCHOR_MERGE, conf)
self.check(MISS_ANCHOR_MERGE, conf)
self.check(MULTI_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_MISS_ANCHOR_POINTER, conf)
self.check(MULTI_DOC_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_DOC_MISS_ANCHOR_POINTER, conf)

def test_unknown_aliases(self):
conf = ('anchors:\n'
' forbid-unknown-aliases: true\n'
' forbid-duplicated-anchors: false\n'
)

self.check(NORMAL_ANCHOR, conf)
self.check(DUPLICATED_ANCHOR, conf)
self.check(HIT_ANCHOR_POINTER, conf)
self.check(MISS_ANCHOR_POINTER, conf, problem=(3, 11))
self.check(HIT_ANCHOR_MERGE, conf)
self.check(MISS_ANCHOR_MERGE, conf, problem=(5, 7))
self.check(MULTI_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_MISS_ANCHOR_POINTER, conf,
problem1=(3, 11), problem2=(4, 16))
self.check(MULTI_DOC_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_DOC_MISS_ANCHOR_POINTER, conf,
problem1=(3, 11), problem2=(6, 11))

def test_duplicated_anchors(self):
conf = ('anchors:\n'
' forbid-unknown-aliases: false\n'
' forbid-duplicated-anchors: true\n'
)

self.check(NORMAL_ANCHOR, conf)
self.check(DUPLICATED_ANCHOR, conf, problem=(3, 7))
self.check(HIT_ANCHOR_POINTER, conf)
self.check(MISS_ANCHOR_POINTER, conf)
self.check(HIT_ANCHOR_MERGE, conf)
self.check(MISS_ANCHOR_MERGE, conf)
self.check(MULTI_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_MISS_ANCHOR_POINTER, conf)
self.check(MULTI_DOC_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_DOC_MISS_ANCHOR_POINTER, conf)

def test_enabled(self):
conf = 'unknown-aliases: enable'
conf = ('anchors:\n'
' forbid-unknown-aliases: true\n'
' forbid-duplicated-anchors: true\n'
)

self.check(NORMAL_ANCHOR, conf)
self.check(DUPLICATED_ANCHOR, conf, problem=(3, 7))
self.check(HIT_ANCHOR_POINTER, conf)
self.check(MISS_ANCHOR_POINTER, conf, problem=(3, 11))
self.check(HIT_ANCHOR_MERGE, conf)
self.check(MULTI_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_DOC_HIT_ANCHOR_POINTER, conf)

self.check(MISS_ANCHOR_POINTER, conf, problem=(3,11))
self.check(MISS_ANCHOR_MERGE, conf, problem=(5, 7))
self.check(MULTI_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_MISS_ANCHOR_POINTER, conf,
problem1=(3, 11), problem2=(4, 16))
self.check(MULTI_DOC_HIT_ANCHOR_POINTER, conf)
self.check(MULTI_DOC_MISS_ANCHOR_POINTER, conf,
problem1=(3, 11), problem2=(6, 11))
3 changes: 1 addition & 2 deletions yamllint/conf/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yaml-files:
- '.yamllint'

rules:
anchor-duplicates: disable
anchors: enable
braces: enable
brackets: enable
colons: enable
Expand All @@ -32,4 +32,3 @@ rules:
trailing-spaces: enable
truthy:
level: warning
unknown-aliases: enable
6 changes: 2 additions & 4 deletions yamllint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from yamllint.rules import (
anchor_duplicates,
anchors,
braces,
brackets,
colons,
Expand All @@ -37,11 +37,10 @@
quoted_strings,
trailing_spaces,
truthy,
unknown_aliases,
)

_RULES = {
anchor_duplicates.ID: anchor_duplicates,
anchors.ID: anchors,
braces.ID: braces,
brackets.ID: brackets,
colons.ID: colons,
Expand All @@ -63,7 +62,6 @@
quoted_strings.ID: quoted_strings,
trailing_spaces.ID: trailing_spaces,
truthy.ID: truthy,
unknown_aliases.ID: unknown_aliases,
}


Expand Down
65 changes: 0 additions & 65 deletions yamllint/rules/anchor_duplicates.py

This file was deleted.

0 comments on commit a52d0eb

Please sign in to comment.