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
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/update-index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ on:
- 'scenarios/**.yml'
- '.github/workflows/update-index.yml'
- "*.go"
- 'hublint'
jobs:
build:
runs-on: ubuntu-latest
Expand Down
19 changes: 19 additions & 0 deletions hublint
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,25 @@ 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
config = {'hubtypes': ['collections', 'parsers', 'postoverflows', 'appsec-rules', 'appsec-configs']}
seen = {}

def __call__(self, item):
if item.hubtype not in self.config['hubtypes']:
return
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
Loading