kowainik / stan

🕵️ Haskell STatic ANalyser
https://kowainik.github.io/projects/stan
Mozilla Public License 2.0
565 stars 48 forks source link

Tailor solutions to the actual code, allowing a full copy/paste swap #341

Closed TomMD closed 4 years ago

TomMD commented 4 years ago

Either by default or via an option, the solutions presented to the user should be tailored to the specific code so the user can delete the startLine to endLine of the span and replace with the solution.

For example, we see:

 ┃     4 ┃
 ┃     5 ┃ someFunc = putStrLn $ show $ foldl (+) 0 [1..10]
 ┃     6 ┃                              ^^^^^
 ┃
 ┃  💡 Possible solution:
 ┃      ⍟ Replace 'foldl' with 'foldl''
 ┃      ⍟ Use 'foldr (flip . f)` instead of 'foldl f'

And could instead see:

 ┃     4 ┃
 ┃     5 ┃ someFunc = putStrLn $ show $ foldl (+) 0 [1..10]
 ┃     6 ┃                              ^^^^^
 ┃
 ┃  💡 Drop-in solution:
 ┃     4 ┃
 ┃     5 ┃ someFunc = putStrLn $ show $ foldl' (+) 0 [1..10]
 ┃     6 ┃                            

While underwhelming in this case, such operation could be more helpful either in complex code or as part of the JSON output (when paired with issue #335)

chshersh commented 4 years ago

This is not aligned with Stan goals. The inspections are for users to understand their code better and choose the most suitable solution among proposed ones. This feature complicates design a lot with too little benefit: it's not always possible to suggest a replacement, it's not us who should decide what solution to suggest as a "drop-in solution", suggestions can use external dependencies and simple copy-paste won't work.

Generally, the static analyser is not an automatic code refactoring tool. Its goal is to help people gain better insight into their code, not just simply replace one code with another.