From f08a129a85e29c5a66005d7d00bcf2d71ca89863 Mon Sep 17 00:00:00 2001 From: Satyaki Ghosh Date: Mon, 6 Jul 2026 14:24:08 -0400 Subject: [PATCH] Fix yaml line numbers --- src/template-model/src/parser/yaml.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/template-model/src/parser/yaml.rs b/src/template-model/src/parser/yaml.rs index 2ef6df1..c04cbac 100644 --- a/src/template-model/src/parser/yaml.rs +++ b/src/template-model/src/parser/yaml.rs @@ -257,12 +257,14 @@ impl MarkedEventReceiver for CfnYamlLoader { } self.path_stack.push(v.clone()); let path = self.current_path(); - // mark.line() and mark.col() are 0-based - self.span_map.insert(path, (mark.line() as u32 + 1, mark.col() as u32 + 1)); + // yaml_rust2 Marker reports line 1-based but column 0-based, + // so only the column is shifted to the 1-based column every + // other diagnostic reports (see the parse-error path above). + self.span_map.insert(path, (mark.line() as u32, mark.col() as u32 + 1)); // Remember this key's position so a later duplicate of it // can be anchored at the offending occurrence. if let Some(slot) = self.key_marks.last_mut() { - *slot = Some((mark.line() as u32 + 1, mark.col() as u32 + 1)); + *slot = Some((mark.line() as u32, mark.col() as u32 + 1)); } } } else if matches!(parent.0, Yaml::Array(_)) @@ -549,10 +551,6 @@ mod tests { assert_eq!(messages(&yaml), messages(&json)); } - /// A bare (integer) YAML key and a quoted string key of the same digits are - /// distinct source keys, so — matching cfn-lint, which compares keys by value - /// and never flags them — no F0000 is emitted. (The two are coerced to the same - /// string later, but that must not manufacture a duplicate diagnostic.) #[test] fn integer_key_and_string_key_are_not_duplicates() { let input = "Resources:\n R:\n Type: AWS::S3::Bucket\n Metadata:\n 1: a\n \"1\": b\n"; @@ -1023,9 +1021,6 @@ mod tests { ); } - /// A literal duplicate key inside a mapping that also uses `<<` is suppressed, - /// matching cfn-lint's `using_merge` behavior (the whole mapping's dup check is - /// disabled). Ordering of the duplicate relative to `<<` must not matter. #[test] fn yaml_merge_key_suppresses_literal_duplicate_in_same_mapping() { let input = "Anchors:\n Base: &base\n X: 1\nResources:\n Derived:\n Type: AWS::S3::Bucket\n Dup: 1\n Dup: 2\n <<: *base\n";