Skip to content

Commit

Permalink
fix(rules_check): report correct offsets for configuration code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed Nov 15, 2024
1 parent 5d17af2 commit a101ef9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions xtask/rules_check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,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 @@ -696,12 +713,18 @@ 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());
diagnostics.subtract_offset = wrapped_offset
.zip(original_offset)
.and_then(|(wrapped, original)| wrapped.checked_sub(original))
.unwrap_or_default();

dbg!(&diagnostics.subtract_offset);

synthetic_root
}
OptionsParsingMode::FullConfiguration => {
Expand Down

0 comments on commit a101ef9

Please sign in to comment.