[FIX] xml-double-quotes-py: fix tag detection and report exact attrib…#188
Merged
[FIX] xml-double-quotes-py: fix tag detection and report exact attrib…#188
Conversation
…ute line Previously, `NodeContent._read_node` failed to identify the start of an XML tag when it appeared after other content on the same line (e.g. `<li>text<strong`) or spanned multiple lines. This caused `xml-double-quotes-py` to miss elements in those layouts. Additionally, the error line number was wrong: lxml's `sourceline` points to the *end* of the opening tag, not the line of the specific attribute that triggers the warning. Changes: - `NodeContent.__init__` now accepts an optional `locator` (`XMLStartTagLocator`). When provided, it is used as the authoritative source for the tag start position and line, avoiding fragile line-by-line heuristics. - A regex backward-scan fallback is kept for callers that do not supply a locator. - `check_xml_double_quotes_py` passes the already-cached locator (via `_get_tag_locator`) to `NodeContent`, and uses `locator.get_attr()` to report the exact line of the offending attribute instead of `elem.sourceline`. - Added regression test `test_xml_double_quotes_py_reports_correct_line_for_inline_and_multiline_tags` to `tests/test_node_xml.py`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously,
NodeContent._read_nodefailed to identify the start of an XML tag when it appeared after other content on the same line (e.g.<li>text<strong) or spanned multiple lines. This causedxml-double-quotes-pyto miss elements in those layouts.Additionally, the error line number was wrong: lxml's
sourcelinepoints to the end of the opening tag, not the line of the specific attribute that triggers the warning.Changes:
NodeContent.__init__now accepts an optionallocator(XMLStartTagLocator). When provided, it is used as the authoritative source for the tag start position and line, avoiding fragile line-by-line heuristics.check_xml_double_quotes_pypasses the already-cached locator (via_get_tag_locator) toNodeContent, and useslocator.get_attr()to report the exact line of the offending attribute instead ofelem.sourceline.test_xml_double_quotes_py_reports_correct_line_for_inline_and_multiline_tagstotests/test_node_xml.py.Using IA with Claude