fix: rename range rule's row to line#1664
Conversation
BREAKING CHANGE: fix #1663 There is an inconsistency between the use of line and row in the ast-grep node's API and rule parameters. The node uses line, while the rule uses row, which may lead to confusion.
|
Caution Review failedThe pull request is closed. WalkthroughThe pull request addresses an inconsistency in terminology across the ast-grep codebase, systematically replacing Changes
Assessment against linked issues
Possibly related PRs
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (2)
crates/pyo3/tests/test_rule.py (1)
156-157: LGTM! Test cases updated to use new terminology.The test cases have been updated to use "line" instead of "row" consistently. However, we could enhance the test coverage.
Consider adding a test case that explicitly verifies the behavior when using the old "row" key to ensure it fails appropriately, helping users identify the breaking change:
def test_deprecated_row_key(): with pytest.raises(ValueError, match="'row' is no longer supported, use 'line' instead"): root.find(range={ "start": {"row": 0, "column": 9}, "end": {"row": 0, "column": 13}, })Also applies to: 162-163
crates/napi/__test__/index.spec.ts (1)
390-391: LGTM! Updated range test to use newlineterminologyThe test case correctly uses the new
lineproperty instead ofrow.Consider adding additional test cases to verify edge cases:
// Test negative line numbers { start: { line: -1, column: 0 }, end: { line: 0, column: 0 } } // Test out of bounds line numbers { start: { line: 999999, column: 0 }, end: { line: 999999, column: 1 } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
crates/cli/src/print/cloud_print.rs(1 hunks)crates/cli/src/print/colored_print.rs(2 hunks)crates/cli/src/print/interactive_print.rs(3 hunks)crates/cli/src/print/json_print.rs(1 hunks)crates/config/src/combined.rs(2 hunks)crates/config/src/rule/range.rs(9 hunks)crates/core/src/node.rs(5 hunks)crates/lsp/src/utils.rs(1 hunks)crates/napi/__test__/index.spec.ts(1 hunks)crates/napi/index.d.ts(1 hunks)crates/napi/manual.d.ts(1 hunks)crates/napi/src/sg_node.rs(1 hunks)crates/pyo3/ast_grep_py/__init__.py(1 hunks)crates/pyo3/src/range.rs(1 hunks)crates/pyo3/tests/test_range.py(1 hunks)crates/pyo3/tests/test_rule.py(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- crates/napi/index.d.ts
🔇 Additional comments (17)
crates/cli/src/print/json_print.rs (1)
149-149: Update to line() method for position retrieval
Changed pos.row() to pos.line() to ensure consistency with the updated terminology across the codebase.
Also applies to: 153-153
crates/pyo3/tests/test_range.py (1)
57-57: Update range keys from row to line
Modified the range parameter to use "line" instead of "row", aligning with the updated API specification.
crates/pyo3/ast_grep_py/__init__.py (1)
19-19: Rename attribute row to line in PosRule
Updated the PosRule class attribute from row to line to standardize terminology across the codebase.
Ensure that all references to PosRule.row have been updated to PosRule.line throughout the codebase.
Run the following script to verify:
✅ Verification successful
Attribute rename from row to line in PosRule has been properly implemented
The verification shows that:
- The old attribute
rowexisted in a previous commit (bfd4945) - The current implementation correctly uses
lineinstead ofrow - No remaining references to
PosRule.rowexist in the codebase - The change appears to be consistently applied as
PosRuleis only used in__init__.pyfor type definitions
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find any usages of 'PosRule.row' in the codebase.
# Test: Search for 'PosRule.row' references. Expect: No results.
rg 'PosRule\.row\b'
Length of output: 21
Script:
#!/bin/bash
# Let's first verify if PosRule exists and check its current implementation
ast-grep --pattern 'class PosRule'
# Also search for any references to PosRule to understand its usage
rg 'PosRule' -A 2
Length of output: 448
Script:
#!/bin/bash
# Let's check the git history to see if there was a recent change from 'row' to 'line'
git log -p --grep="row" -- crates/pyo3/ast_grep_py/__init__.py
# Also let's check for any historical references to 'row' in this file
git grep 'row' $(git rev-list --all) -- crates/pyo3/ast_grep_py/__init__.py
Length of output: 247
crates/lsp/src/utils.rs (1)
64-64: LGTM! Method calls updated consistently.
The change from row() to line() is applied consistently while preserving the type conversion to u32.
Also applies to: 68-68
crates/config/src/rule/range.rs (1)
8-9: LGTM! Documentation and field name updated consistently.
The renaming from row to line has been properly implemented, with documentation updated to reflect the change.
crates/cli/src/print/cloud_print.rs (2)
97-98: LGTM! Method calls updated consistently.
The change from row() to line() is consistent with the PR objectives and maintains the same functionality.
Line range hint 20-23: LGTM! New macro follows existing patterns.
The Diffs! macro is implemented consistently with the existing Matches! macro pattern.
crates/config/src/combined.rs (2)
Line range hint 21-27: LGTM! Suppression line calculation updated consistently.
The change from row() to line() is properly implemented in the suppression collection logic, maintaining the same functionality.
Line range hint 42-46: LGTM! Suppression checking updated consistently.
The change from row() to line() is properly implemented in the suppression checking logic.
crates/cli/src/print/interactive_print.rs (1)
85-85: LGTM! Consistent renaming from row() to line()
The changes align with the PR objective of standardizing terminology from "row" to "line". The modifications maintain the same functionality while improving API consistency.
Let's verify that all occurrences of row() have been replaced:
Also applies to: 177-177, 196-196
✅ Verification successful
Remaining row() calls are from tree-sitter's API and should not be changed
The remaining row() calls are from the tree-sitter library's Point type (tree_sitter::Point), which is an external API that we cannot modify. These occurrences are different from our internal API changes:
- In
debug_query.rs: Converting from tree-sitter'sPointwhich usesrow() - In
node.rs: Working directly with tree-sitter's position API
Our internal API standardization to line() is complete and correct, while these remaining row() calls should stay as they are to maintain compatibility with the tree-sitter library.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any remaining instances of row() method calls
# Expect: No matches as all should be renamed to line()
rg "\.row\(\)"
Length of output: 219
Script:
#!/bin/bash
# Let's check the context of these remaining row() calls to understand if they need to be updated
# Check debug_query.rs
echo "=== debug_query.rs ==="
rg -B 2 -A 2 "\.row\(\)" crates/cli/src/utils/debug_query.rs
# Check node.rs
echo -e "\n=== node.rs ==="
rg -B 2 -A 2 "\.row\(\)" crates/core/src/node.rs
# Let's also check if there are any line() methods in these files
# to see if there's an ongoing pattern of conversion
echo -e "\n=== Checking line() usage in the same files ==="
rg "\.line\(\)" crates/cli/src/utils/debug_query.rs crates/core/src/node.rs
Length of output: 1254
Script:
#!/bin/bash
# Let's check the tree-sitter API documentation by looking at imports and type definitions
# to understand if these are different APIs
# Check tree-sitter imports and types
echo "=== Checking tree-sitter imports ==="
rg "use tree_sitter" -A 3 crates/cli/src/utils/debug_query.rs crates/core/src/node.rs
# Check Point type usage and definition
echo -e "\n=== Checking Point type usage ==="
rg "Point" -B 1 -A 1 crates/cli/src/utils/debug_query.rs crates/core/src/node.rs
Length of output: 1472
crates/napi/src/sg_node.rs (1)
45-45: LGTM! Updated position conversion to use line()
The change correctly updates the position conversion to use line() instead of row(), maintaining consistency with the new terminology.
crates/cli/src/print/colored_print.rs (1)
270-270: LGTM: Consistent terminology change from row to line.
The changes correctly replace row() with line() in the MatchMerger struct, maintaining the same functionality while standardizing terminology.
Let's verify no instances of row remain in this file:
Also applies to: 299-299
✅ Verification successful
Terminology change from row to line is complete and consistent
The verification confirms that there are no remaining instances of row or row() in the file crates/cli/src/print/colored_print.rs. While row terminology exists in other parts of the codebase, they are in different components and contexts, not related to this specific change.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any remaining instances of 'row' that might need updating
rg '\brow\b' --type rust
Length of output: 654
Script:
#!/bin/bash
# Let's check the specific file mentioned in the review comment for any 'row' instances
rg '\brow\b' 'crates/cli/src/print/colored_print.rs'
# Also let's check for any remaining instances of 'row()' method calls
rg '\.row\(\)' 'crates/cli/src/print/colored_print.rs'
Length of output: 107
crates/core/src/node.rs (5)
13-13: Documentation correctly updated to use "line" terminology.
The documentation has been properly updated to reflect the terminology change from "row" to "line".
Also applies to: 18-19
27-27: Constructor and accessor methods updated consistently.
The Position struct's constructor and accessor methods have been updated to use "line" terminology consistently:
- Constructor parameter renamed from
rowtoline - Field renamed from
rowtoline - Accessor method renamed from
row()toline()
Also applies to: 29-35
44-44: Tree-sitter Point conversion updated.
The ts_point method has been updated to use the line field instead of row.
293-293: Display context calculation updated.
The DisplayContext struct's start_line calculation has been updated to use line() instead of row().
18-19: Verify impact of breaking changes.
This is a breaking change that renames the public API from row to line. While the changes look correct, we should verify the impact on dependent code.
Let's check for any external usage of the old row API:
Also applies to: 27-27, 34-35
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1664 +/- ##
==========================================
+ Coverage 87.11% 87.13% +0.01%
==========================================
Files 96 96
Lines 15458 15476 +18
==========================================
+ Hits 13467 13485 +18
Misses 1991 1991 ☔ View full report in Codecov by Sentry. |
BREAKING CHANGE: fix #1663
There is an inconsistency between the use of line and row in the ast-grep node's API and rule parameters. The node uses line, while the rule uses row, which may lead to confusion.
Summary by CodeRabbit
Release Notes
New Features
Improvements
Bug Fixes