9. Build a fix
We build a fix that will replace the text from the first argument by "bar".
A fix is made of at least one edit. We have different functions to build an edit (buildEditAdd
, buildEditRemove
and buildEditUpdate
). We choose buildEditUpdate to replace text in the code.
The function buildEditUpdate takes as arguments:
- the starting line of the edit
- the starting column of the edit
- the ending line of the edit
- the ending column of the edit
- the text to update
To make an edit that replaces the value of the argument, such as, updating from foo to var, build an edit like this:
1const edit = buildEditUpdate(
2 firstArgument.start.line,
3 firstArgument.start.col,
4 firstArgument.end.line,
5 firstArgument.end.col,
6 "bar"
7);
We create a fix with the previously created edit:
1const fix = buildFix("print bar", [edit]);
Finally, once the report and the associated edit is complete, we can report it to the IDE using the function addError().
1addError(error.addFix(fix));
Let's go!
Start interacting with the tutorial!
my-new-rule.js