Repository navigation
Conversation
The raw_line property is documented as 1-based but was incorrectly computed by adding 1 to an already 1-based line number from the parser. This caused: - Incorrect line numbers shown to users - Tab adjustment logic using the wrong line - EOF clamping logic incorrectly triggering on the last line Changes: - Remove the +1 offset in native/libcst/src/parser/errors.rs - Fix EOF clamping to check 'line > len' instead of 'line + 1 > len' - Fix EOF clamping to set 'line = len' instead of 'line = len - 1' - Add regression tests for line number and caret position accuracy Fixes Instagram#1472
Test that parser errors reported past end-of-file are correctly clamped to the last line with column 0, ensuring the EOF clamping logic fixed in the previous commit works as intended. Related to Instagram#1472
|
Hi @hippi345! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Fix ParserSyntaxError line number off-by-one error
Summary
Fixes #1472
The
raw_lineproperty inParserSyntaxErroris documented and treated as 1-based, but was being computed by adding 1 to an already 1-based line number from the parser. This caused several related bugs:Changes
Rust changes (
native/libcst/src/parser/errors.rs):+1offset when passinglinetoraw_line(line 59)line + 1 > lines.len()toline > lines.len()(line 51)line = lines.len() - 1toline = lines.len()(line 52)Python changes (
libcst/tests/test_exceptions.py):test_parser_error_line_numbers()that verifies:raw_line=1raw_line/raw_columnandeditor_line/editor_columnare correcttest_parser_error_tab_adjustment_on_correct_line()that verifies:Testing
All tests pass:
cargo testinnative/(all tests pass)uv run poe test(2163 tests pass, 14 skipped, 2 expected failures)Before fix:
After fix:
Scope
This fix is scoped to the issue and only modifies:
The fix maintains backward compatibility with the Python API -
raw_lineandeditor_lineremain 1-based as documented, but now report the correct values.