-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct node position for FuncDef nodes and fix sonar codemods #423
Conversation
Quality Gate passedIssues Measures |
case cst.FunctionDef(): | ||
# By default a function's position includes the entire | ||
# function definition. Instead, we will only use the first line | ||
# of the function definition. | ||
params_end = self.get_metadata(PositionProvider, node.params).end | ||
return CodeRange( | ||
start=self.get_metadata(PositionProvider, node).start, | ||
end=CodePosition(params_end.line, params_end.column + 1), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rater have a general solution instead making one for every node type. I suggest changing either includes/excludes match or node_is_selected
to match match any node that begins on a given line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree with a more general solution like that. In that case, why do we care about start/end columns at all right now? Is there not a reason why we do column matching in match_location
nearby code? If there is, then that more general solution of just matching start line doesn't make much sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since discussions about matching nodes are pending, I think this is ok for a temporary solution.
Overview
Add custom node_position for libcst.FuncDef nodes to support codemods that change code at function level
Description
However, for many codemods we really just care about matching the first line of the function def. So I've implemented this instead
so the end position is the text length of the
def ...
line but index 0.This now allows us to add include/exclude and results filtering to these codemods
Additional Details
Closes #413