Autocorrect
Closed this issue · 4 comments
Rubocop has an auto correct method. It would be nice to see something similar within fasterer (with an appropriate warning)
Would you be up for implementing this feature? If so, I'll have to arrange the command line interface.
Ill take a look at how rubocop implements their auto-correct but no promises on any timeframes (so busy lately). Might be a killer feature though 👍
I reason that in principle, rubocop could be able to do the auto-correct since it already is able to do so (for many cops, not all of them though). I myself have been starting with rubocop only since perhaps ~2 months so I am not yet extremely familiar with it.
A simple example would be:
x = "foo"
versus
x = 'foo'
This is very minor, but one could also consider this to be a speed improvement since ruby won't have to consider the "" string for interpolation when we use '' instead, as in the second example (since '' will not be used for interpolation).
More "optimizations" could be:
x = 'foo'; y = x+'bar'
to become:
x = 'foo'; y = "{x}bar"
In this case, the second option with {} should be faster since + will create a new String object, which should be more costly.
Building such a tool is IMHO waste of time. Ruby has very dynamic nature. You can't tell what kind of object is hold in variable until runtime. Suppose you see code:
def add(x)
x + "bar"
end
What kind of variable is x? You can't blindly replace it with "#{x}bar". Even if somehow you know that x
is a string you can't be sure that String#+
was monkey-patched. If it was then these two forms are not equivalent.
@shevegen
This is very minor, but one could also consider this to be a speed improvement since ruby won't have to consider the "" string for interpolation when we use '' instead, as in the second example (since '' will not be used for interpolation).
There is no performance difference between single vs double quotation string in Ruby.