Skip to content

Commit

Permalink
fix(rules): report correct offsets for configuration code block diagn…
Browse files Browse the repository at this point in the history
…ostics
  • Loading branch information
cr7pt0gr4ph7 committed Nov 15, 2024
1 parent 92aefd2 commit 1cdd653
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions codegen/src/lintdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,23 @@ fn make_json_object_with_single_member<V: Into<AnyJsonValue>>(
)
}

fn get_first_member<V: Into<AnyJsonValue>>(parent: V, expected_name: &str) -> Option<AnyJsonValue> {
let parent_value: AnyJsonValue = parent.into();
let member = parent_value
.as_json_object_value()?
.json_member_list()
.into_iter()
.next()?
.ok()?;
let member_name = member.name().ok()?.inner_string_text().ok()?.to_string();

if member_name.as_str() == expected_name {
member.value().ok()
} else {
None
}
}

/// Parse the options fragment for a lint rule and return the parsed options.
fn parse_rule_options(
group: &'static str,
Expand Down Expand Up @@ -624,6 +641,10 @@ fn parse_rule_options(
let wrapped_offset = synthetic_root
.value()
.ok()
.and_then(|v| get_first_member(v, "linter"))
.and_then(|v| get_first_member(v, "rules"))
.and_then(|v| get_first_member(v, group))
.and_then(|v| get_first_member(v, rule))
.map(|v| AstNode::range(&v).start());
let subtract_offset = wrapped_offset
.zip(original_offset)
Expand Down

0 comments on commit 1cdd653

Please sign in to comment.