port-name-suffix: use FindWithDefault for the suffix-set lookup Address review feedback: look the direction up with verible::container::FindWithDefault and an empty-set fallback instead of a manual find()/end() check. Since the map holds a set of valid suffixes per direction, an unknown direction (e.g. `ref`) yields an empty set and is treated as correct, preserving the existing behavior. Signed-off-by: Eylon Krause <eylon1909@gmail.com>
diff --git a/verible/verilog/analysis/checkers/BUILD b/verible/verilog/analysis/checkers/BUILD index bd3a98b..a83f76a 100644 --- a/verible/verilog/analysis/checkers/BUILD +++ b/verible/verilog/analysis/checkers/BUILD
@@ -1821,6 +1821,7 @@ "//verible/common/text:symbol", "//verible/common/text:syntax-tree-context", "//verible/common/text:token-info", + "//verible/common/util:container-util", "//verible/verilog/CST:port", "//verible/verilog/CST:verilog-matchers", "//verible/verilog/analysis:descriptions",
diff --git a/verible/verilog/analysis/checkers/port-name-suffix-rule.cc b/verible/verilog/analysis/checkers/port-name-suffix-rule.cc index 3eaf392..ffecef3 100644 --- a/verible/verilog/analysis/checkers/port-name-suffix-rule.cc +++ b/verible/verilog/analysis/checkers/port-name-suffix-rule.cc
@@ -28,6 +28,7 @@ #include "verible/common/text/symbol.h" #include "verible/common/text/syntax-tree-context.h" #include "verible/common/text/token-info.h" +#include "verible/common/util/container-util.h" #include "verible/verilog/CST/port.h" #include "verible/verilog/CST/verilog-matchers.h" #include "verible/verilog/analysis/descriptions.h" @@ -91,13 +92,15 @@ {"inout", {"io", "nio", "pio"}}}; // `direction` is usually one of the map keys, but the grammar also permits a - // `ref` port direction, which has no suffix convention. Look the direction up - // safely and treat an unknown direction as "correct" (no violation), + // `ref` port direction, which has no suffix convention. FindWithDefault looks + // the direction up with an empty-set fallback, so an unknown direction (e.g. + // `ref`) has no required suffixes and is treated as "correct" (no violation), // consistent with Violation() which also ignores non-input/output/inout - // directions. Using std::map::at() here would throw on e.g. "ref". - const auto it = suffixes.find(direction); - if (it == suffixes.end()) return true; - return it->second.count(suffix) == 1; + // directions. + static const std::set<std::string_view> kNoConvention; + const std::set<std::string_view> &valid = + verible::container::FindWithDefault(suffixes, direction, kNoConvention); + return valid.empty() || valid.count(suffix) == 1; } void PortNameSuffixRule::HandleSymbol(const Symbol &symbol,