Source code for flowstrider.helpers.rules_checker

# SPDX-FileCopyrightText: 2025 German Aerospace Center (DLR)
#
# SPDX-License-Identifier: BSD-3-Clause

import typing

from flowstrider import settings
from flowstrider.converters.dfd_to_dot_converter import wrap_text as wrap
from flowstrider.helpers.warnings import WarningsCounter
from flowstrider.rules import common_rules
from flowstrider.rules.collections import all_collections


[docs] def check_rule_name_duplicates() -> None: """ Checks all rule collections for duplicate rule names (Rule names have to be unique) and throws a warning if duplicates are found """ all_rules: typing.Set[str] = set() for collection in all_collections: collection_rules: typing.List[typing.Type[common_rules.Rule]] = [] collection_rules.extend(collection.node_rules) collection_rules.extend(collection.edge_rules) collection_rules.extend(collection.dfd_rules) collection_rules.extend(collection.graph_rules) for rule in collection_rules: if rule.__name__ in all_rules: # Found duplicate rule name _ = settings.lang_sys.gettext print( settings.C_WARNING + wrap( _("Warning: ") + _( 'the rule "{name}" exists twice. Rule names have to be ' + "unique!" ).format(name=rule.__name__) ) + settings.C_DEFAULT ) WarningsCounter.add_warning() else: all_rules.add(rule.__name__)