Recode.Task behaviour (Recode v0.8.0)
View SourceThe behaviour for a recode task.
To create a recode task, you'll need to:
- Create a module.
- Call
use Recode.Taskin that module. - Implement the callbacks
run/2. - Optionally,
init/1can also be implemented.
use Recode.Task
When you use Recode.Task, the Recode.Task module will
set @behaviour Recode.Task.
Recode.Task will also set default implementations for the callbacks
update_source/3 and new_issue/2.
Summary
Callbacks
A callback to check and manipulate config before any recode task runs.
Creates a new issue with the given opts.
Creates a new issue with the given message and opts.
Applies a task with the given source and opts.
Update the given source with the given updates.
Functions
Returns the category for the given task.
Returns true if the given task provides a check for sources.
Returns true if the given task provides a correction functionality for
sources.
Returns the shortdoc for the given task.
Types
Callbacks
A callback to check and manipulate config before any recode task runs.
The callback receives the config that is set in the recode-config.
In the implementation of this callback the config can be checked and
defaults can be set.
When init returns an error tuple, the mix recode task raises an exception
with the returned message.
@callback new_issue(opts :: String.t()) :: Recode.Issue.t()
Creates a new issue with the given opts.
The default implementation of this callback creates an Recode.Issue struct
with reporter: __MODULE__.
@callback new_issue(message :: String.t(), opts :: Keyword.t()) :: Recode.Issue.t()
Creates a new issue with the given message and opts.
The default implementation of this callback creates an Recode.Issue struct
with reporter: __MODULE__.
@callback run(source :: Rewrite.Source.t(), opts :: Keyword.t()) :: Rewrite.Source.t()
Applies a task with the given source and opts.
The opts containing:
The configuration for the task defined in the recode-config. When the
init/1is implemented then theoptsreturned by this callback are in theopts.:dot_formatter- the%Rewrite.DotFormatter{}for the project.:autocorrect- abooleanindicating ifrecoderuns in auto-correction mode.
@callback update_source(Rewrite.Source.t(), opts :: Keyword.t(), updates :: Keyword.t()) :: Rewrite.Source.t()
Update the given source with the given updates.
The default implementation of this callback applies any element from the
updates keyword list to the source with the given opts. The keys
:issue and :issues will be applied with Rewrite.Source.add_issue/2 and
Rewrite.Source.add_issues/2 respectively. Any other key will be applied with
Rewrite.Source.update/4, when opts contains autocorrect: true.
In updates the value for :quoted can be a Sourceror.Zipper. In this case
the source is updated with the return value of Sourceror.Zipper.root/1.
The opts are extended by by: __MODULE__.
Functions
Returns the category for the given task.
Returns true if the given task provides a check for sources.
Returns true if the given task provides a correction functionality for
sources.
Returns the shortdoc for the given task.
Returns nil if @shortdoc is not available for the task.