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

add hub linter for item name collision #1044

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions hublint
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,22 @@ class ContentMatchFile(Linter):
if from_field != from_file:
yield self.err(f"Content field does not match the file: {item._spec.get('path')}")

class ItemNameConflict(Linter):
name = "item-name-conflict"
description = "The item name must be unique"
enabled = True
error = True
seen = {}

def __call__(self, item):
docs = item.yaml_docs()
for doc in docs:
if 'name' not in doc:
continue
k = doc.get('name') + ':' + item.hubtype
if k in self.seen:
yield self.err(f"Item name conflict: {doc['name']} is defined in both {self.seen[k]} and {item._spec.get('path')}")
self.seen[k] = item._spec.get('path')

# --------------------------------------------------------------------- #

Expand Down