Skip to content

Commit 4f489ba

Browse files
Improved tag validation and normalization
1 parent 0850522 commit 4f489ba

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/convert_to_ide_formats.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ def sync_plugin_metadata(version: str) -> None:
3838

3939
def matches_tag_filter(rule_tags: list[str], filter_tags: list[str]) -> bool:
4040
"""
41-
Check if rule has all required tags (case-insensitive AND logic).
41+
Check if rule has all required tags (AND logic).
4242
4343
Args:
44-
rule_tags: List of tags from the rule (already lowercase from parsing)
45-
filter_tags: List of tags to filter by
44+
rule_tags: List of tags from the rule (already normalized to lowercase)
45+
filter_tags: List of tags to filter by (already normalized to lowercase)
4646
4747
Returns:
4848
True if rule has all filter tags (or no filter), False otherwise
4949
"""
5050
if not filter_tags:
5151
return True # No filter means all pass
5252

53-
return all(tag.lower() in rule_tags for tag in filter_tags)
53+
return all(tag in rule_tags for tag in filter_tags)
5454

5555

5656
def update_skill_md(language_to_rules: dict[str, list[str]], skill_path: str) -> None:
@@ -351,10 +351,10 @@ def _resolve_source_paths(args) -> list[Path]:
351351

352352
# Convert all sources
353353
aggregated = {"success": [], "errors": [], "skipped": []}
354-
# Parse comma-separated tags
354+
# Parse comma-separated tags and normalize to lowercase
355355
filter_tags = None
356356
if cli_args.tags:
357-
filter_tags = [tag.strip() for tag in cli_args.tags.split(",") if tag.strip()]
357+
filter_tags = [tag.strip().lower() for tag in cli_args.tags.split(",") if tag.strip()]
358358

359359
# Print tag filter info if active
360360
if filter_tags:

src/utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,27 @@ def validate_tags(tags, filename=None) -> list[str]:
6262
Validate tags list and return normalized (lowercase) tags.
6363
6464
Args:
65-
tags: The tags value to validate (should be a list)
65+
tags: The tags value to validate (should be a non-empty list)
6666
filename: Optional filename for better error messages
6767
6868
Returns:
6969
List of normalized (lowercase) tags
7070
7171
Raises:
72-
ValueError: If tags are invalid (wrong type, contain whitespace, empty, etc.)
72+
ValueError: If tags are invalid (wrong type, empty list, contain whitespace, etc.)
73+
74+
Note:
75+
An empty tags list (tags: []) is considered invalid. If you have no tags,
76+
omit the 'tags' field entirely from the frontmatter.
7377
"""
7478
context = f" in {filename}" if filename else ""
7579

7680
if not isinstance(tags, list):
7781
raise ValueError(f"'tags' must be a list{context}")
7882

83+
if not tags:
84+
raise ValueError(f"'tags' list cannot be empty{context}. Omit the field if you have no tags.")
85+
7986
normalized = []
8087
for tag in tags:
8188
if not isinstance(tag, str):
@@ -89,7 +96,7 @@ def validate_tags(tags, filename=None) -> list[str]:
8996

9097
normalized.append(tag.lower())
9198

92-
return normalized
99+
return list(set(normalized))
93100

94101

95102
def get_version_from_pyproject() -> str:

0 commit comments

Comments
 (0)