Repository navigation
Correct node position for FuncDef nodes and fix sonar codemods - #423
Conversation
|
| 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.
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.
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.
andrecsilva
left a comment
There was a problem hiding this comment.
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