LintFix change multiple parts with pattern

Skip to first unread message

Saman Sattari

Jan 31, 2022, 8:48:09 AMJan 31
to lint-dev
I have a code like below:
notif("Hello", 2000).show()
but I can also use it like below:
val n = notif("Hello"2000)
So I made another fun that simplifies the first one into this:
Now I have added a lint rule that detects the first one and warns the user to change it to showNotif. but I don't know how to make a LintFix to that. I tried this:
             .name("Use `showNotif()` function")
But It gives me this error: Illegal escape: \k
So how can I change multiple parts of a code?

Róbert Papp

Feb 8, 2022, 4:15:54 AMFeb 8
to lint-dev
Hi, if I understand your use case correctly: from a quick glance at the LintFix class, looks like you can do this:

but it might not do what you want, I think you're better off detecting the two patterns separately and providing different fixes.
This is because notif and show looks like two different methods, i.e. show() is just empty params, so you need to do more AST transform to get to showNotif(...) usage (guess that's what `with` was meant to be).

Reply all
Reply to author
0 new messages