Marcus
Recode - A linter with autocorrection and a refactoring tool
Recode is an experimental package to lint, autocorrect and refactor code. The package uses the great Sourceror library by @dorgan.
So far, there are only a small number of autocorrections and just one refactoring command.
The following example runs recode in a project with some nonsense code:
> mix recode --dry
Found 11 files, including 2 scripts.
.............................................................................
File: lib/my_code.ex
[Specs 15/3] Functions should have a @spec type specification.
File: lib/my_code/alias_expansion.ex
Updates: 1
Changed by: AliasExpansion
001 |defmodule MyCode.AliasExpansion do
002 - | alias MyCode.{PipeFunOne, SinglePipe}
002 + | alias MyCode.PipeFunOne
003 + | alias MyCode.SinglePipe
004 |
005 | def foo(x) do
[Specs 5/3] Functions should have a @spec type specification.
File: lib/my_code/alias_order.ex
Updates: 2
Changed by: AliasOrder, AliasExpansion
012 |
013 |defmodule Mycode.AliasOrder do
014 - | alias MyCode.SinglePipe
014 + | alias MyCode.Echo
015 + | alias MyCode.Foxtrot
016 | alias MyCode.PipeFunOne
017 - | alias MyCode.{Foxtrot, Echo}
017 + | alias MyCode.SinglePipe
018 |
019 | @doc false
File: lib/my_code/fun.ex
Updates: 1
Changed by: Format
002 | @moduledoc false
003 |
004 - |
005 - |
006 - |
007 - |
008 - |
004 | def noop(x), do: x
005 |end
File: lib/my_code/multi.ex
Updates: 2
Changed by: SinglePipe, PipeFunOne
007 |
008 | def pipe(x) do
009 - | x |> double |> double()
009 + | x |> double() |> double()
010 | end
011 |
012 | def single(x) do
013 - | x |> double()
013 + | double(x)
014 | end
015 |
File: lib/my_code/pipe_fun_one.ex
Updates: 1
Changed by: PipeFunOne
005 |
006 | def pipe(x) do
007 - | x |> double |> double()
007 + | x |> double() |> double()
008 | end
009 |end
File: lib/my_code/singel_pipe.ex
Updates: 1
Changed by: SinglePipe
005 |
006 | def single_pipe(x) do
007 - | x |> double()
007 + | double(x)
008 | end
009 |
010 - | def reverse(a), do: a |> Enum.reverse()
010 + | def reverse(a), do: Enum.reverse(a)
011 |end
012 |
File: test/my_code_test.exs
Updates: 1
Changed by: TestFileExt
Moved from: test/my_code_test.ex
The refactoring task:
> mix recode.rename --dry MyCode.SinglePipe.double dbl
Found 11 files, including 2 scripts.
...........
File: lib/my_code/alias_expansion.ex
Updates: 1
Changed by: Rename
003 |
004 | def foo(x) do
005 - | SinglePipe.double(x) + PipeFunOne.double(x)
005 + | SinglePipe.dbl(x) + PipeFunOne.double(x)
006 | end
007 |end
File: lib/my_code/alias_order.ex
Updates: 1
Changed by: Rename
018 | @doc false
019 | def foo do
020 - | {SinglePipe.double(2), PipeFunOne.double(3)}
020 + | {SinglePipe.dbl(2), PipeFunOne.double(3)}
021 | end
022 |
File: lib/my_code/singel_pipe.ex
Updates: 1
Changed by: Rename
002 | @moduledoc false
003 |
004 - | def double(x), do: x + x
004 + | def dbl(x), do: x + x
005 |
006 | def single_pipe(x) do
007 - | x |> double()
007 + | x |> dbl()
008 | end
009 |
Differences to Credo
recode was started as a plugin for credo. Unfortunately it was not possible
to implement autocorrection as a plugin because the traversation of the code does
not support changing the code.
Maybe some code lines from recode could be used as inspiration for credo
to bring the autocorrect feature to credo.
Other differences:
recoderequiers Elixir 1.12,credorequiers Elixir 1.7recodehas autocorrectioncredohas much more checkerscredois fastercredohas more features
Trending in Announcing
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly.
One of i...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses:
I had hope...
New
Other Trending Topics
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Introduction
Founded in 2017 by landscape ecologist and fire mitigation expert Harry Statter, Frontline developed the first fully integra...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 8 of 8 Posts!
lud
Hello,
Recode chokes on this:
WIth error:
The error is emitted at the start of the command, so it stops the execution. Otherwise I have other errors that are logged.
Otherwise it is a great tool, thank you!
Marcus
0.4.0
The new release removes the
mixtaskrecode.renameto get focus on the linting and auto-correction.The package was divided. The part that takes care of the files, sources and the project is now in
rewrite.The output for a
--dry/--verboserun has been updated:mohammedzeglam
awesome project i use it, it similar to hlint in some functionality.
Marcus
I have release 0.5.0 of
recode. The new version adds theRecode.FormatterPlugin. This plugin allows you to run Recode autocorrecting tasks together when executingmix format. See the documentation ofRecode.FormatterPluginfor how to set this up.Marcus
Recode version 0.6.0 is now available.
The new version adds
mixtaskrecode.helpto print a list of allrecodetasks or the doc for a givenrecodetaskmixtaskrecode.update.configto update an existingrecodeconfig.mix recode.Recode.Task.TagFIXMEto check for FIXME tags.Recode.Task.TagTODOto check for TODO tags.Recode.Task.Nestingto report issues when functions are nested too deep.Recode.Task.FilterCountto rewriteEnum.filter(fn ...) |> Enum.count()toEnum.count(fn ...).Recode.Task.Dbgto removedbgcalls or report issues for such calls.Recode.Task.IOInspectto removeIO.inspectcalls or report issues for such calls.The tasks
DbgandIOInspectare configured withautocorrect: falsein the default config. To remove all calls todbgandIO.inspect, you can usemix recodelike this:The
-avstands for the switches--autocorrectand--verbose. The switch--verbosecausesrecodeto display all changes as a diff on the console.An example for
FilterCount:apoorv-2204
this could be a vscode extension
BartOtten
It could be a whole minor mode in Emacs
It could be a plugin in (neo)vim
It could be anything.
Are you willing to make it?
apoorv-2204
I think we should merge this two projects , and the work force
this tool and