Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Recommend better alternatives for a piece of code? #26

Closed
hanyuone opened this issue Sep 15, 2017 · 3 comments
Closed

Recommend better alternatives for a piece of code? #26

hanyuone opened this issue Sep 15, 2017 · 3 comments

Comments

@hanyuone
Copy link

For example, in RubyMine, there's a feature where something such as:

for a in [*0...10]

RubyMine will automatically recommend you to change the for statement to a each do statement. This also applies to something like when you use if with a negative statement (in which case unless is recommended), etcetera.

This requires a centralised style guide or linter, however.

@faustinoaq
Copy link
Member

Yeah, that functionality is called Code Action, and is in our Roadmap :)

I'm thinking in taking information from error messages like this:

require "http"

server = HTTP::Server.new("0.0.0.0", 8080) do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world!"
end

serve.listen

So the error looks like:

$ crystal u.cr
Error in u.cr:8: undefined local variable or method 'serve' (did you mean 'server'?)

serve.listen

So we should use a light bulb or some mechanism to suggest server instead of serve allowing to the user to fix or even improve the code as you said.

Also We can follow best practices for crystal:

@faustinoaq
Copy link
Member

Hi, I already implementing basic Code Actions (including support for RubyMine 🎉 ) although I think scry doesn't support code style suggestions yet, I guess we can include ameba tool for this, @veelenga WDYT?

@veelenga
Copy link

veelenga commented May 6, 2018

That's right. For example, ameba right now suggests the use of if instead the else block with the unless.

https://github.com/veelenga/ameba/blob/master/src/ameba/rule/unless_else.cr

image

However, ameba is able to find such piece of code, not to change it. To automatically correct (while clicking a light bulb in RubyMine), we need to implement the autocorrect feature crystal-ameba/ameba#34

@bcardiff bcardiff closed this as completed Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants