forked from semgrep/semgrep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Simplify Autofix.render_fix interface (semgrep#6407)
All of the paremeters to `Autofix.render_fix` can be derived from a `Pattern_match.t`, and it's hard to foresee a use case where a caller doesn't have a `Pattern_match.t` but still wants a rendered autofix, and this is a lot simpler. `Autofix.render_fix` now returns a `Textedit.t` instead of the replacement text alone. For now, the range in it is just the range of the `Pattern_match.t`, but that might not always be the case. Maybe later it will become a `Textedit.t list`. The only downside is that this change introduces an additional file read in tests, but that's not a big deal. Test plan: Automated tests
- Loading branch information
Showing
5 changed files
with
26 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,8 @@ | ||
(* Attempts to render a fix. If successful, returns the text that should replace | ||
* the matched range in the target file. If unsuccessful, returns None. *) | ||
val render_fix : | ||
Lang.t -> | ||
(* Needed so that we can replace metavariables in the fix pattern with their | ||
* corresponding AST nodes from the target file *) | ||
Metavariable.bindings -> | ||
(* The fix pattern itself, as written in the rule *) | ||
fix_pattern:string -> | ||
(* The contents of the target file. This is needed so that we can use the | ||
* original text from the target file when printing metavariables. | ||
* | ||
* Lazy because in practice, computing this involves a read from disk which | ||
* can be expensive, and it may not be needed if there is a failure before | ||
* printing or if no metavariables appear in the fix pattern. *) | ||
target_contents:string Lazy.t -> | ||
string option | ||
(* Attempts to render a fix. If successful, returns the edit that should occur | ||
* in the target file. If unsuccessful, returns None. *) | ||
val render_fix : Pattern_match.t -> Textedit.t option | ||
|
||
(* Apply the fix for the list of matches to the given file, returning the | ||
* resulting file contents. Currently used only for tests, but with some changes | ||
* could be used in production as well. *) | ||
val apply_fixes_to_file : | ||
Lang.t -> Pattern_match.t list -> file:string -> string | ||
val apply_fixes_to_file : Pattern_match.t list -> file:string -> string |
This file contains 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
This file contains 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