Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > 016232f1d9a3f7bee85855d35a2bca58 > files > 241

elixir-doc-1.7.2-1.mga7.noarch.rpm

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="ExDoc v0.19.1">
    <title>format – Mix v1.7.2</title>
    <link rel="stylesheet" href="dist/app-240d7fc7e5.css" />
      <link rel="canonical" href="https://hexdocs.pm/mix/v1.7/Mix.Tasks.Format.html" />
    <script src="dist/sidebar_items-0c0044e6e4.js"></script>
    
  </head>
  <body data-type="tasks">
    <script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>
    <div class="main">
<button class="sidebar-button sidebar-toggle">
  <span class="icon-menu" aria-hidden="true"></span>
  <span class="sr-only">Toggle Sidebar</span>
</button>
<button class="sidebar-button night-mode-toggle">
  <span class="icon-theme" aria-hidden="true"></span>
  <span class="sr-only">Toggle Theme</span>
</button>
<section class="sidebar">

  <a href="http://elixir-lang.org/docs.html" class="sidebar-projectLink">
    <div class="sidebar-projectDetails">
      <h1 class="sidebar-projectName">
Mix      </h1>
      <h2 class="sidebar-projectVersion">
        v1.7.2
      </h2>
    </div>
      <img src="assets/logo.png" alt="Mix" class="sidebar-projectImage">
  </a>

  <form class="sidebar-search" action="search.html">
    <button type="submit" class="search-button">
      <span class="icon-search" aria-hidden="true"></span>
    </button>
    <input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" />
  </form>

  <ul class="sidebar-listNav">
    <li><a id="extras-list" href="#full-list">Pages</a></li>

      <li><a id="modules-list" href="#full-list">Modules</a></li>

      <li><a id="exceptions-list" href="#full-list">Exceptions</a></li>

      <li><a id="tasks-list" href="#full-list">Mix Tasks</a></li>
  </ul>
  <div class="gradient"></div>
  <ul id="full-list" class="sidebar-fullList"></ul>
</section>

<section class="content">
  <div class="content-outer">
    <div id="content" class="content-inner">


      <h1>
        <small class="visible-xs">Mix v1.7.2</small>
mix format        
          <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/tasks/format.ex#L1" title="View Source" class="view-source" rel="help">
            <span class="icon-code" aria-hidden="true"></span>
            <span class="sr-only">View Source</span>
          </a>
      </h1>


        <section id="moduledoc">
<p>Formats the given files and patterns.</p>
<pre><code class="nohighlight makeup elixir"><span class="n">mix</span><span class="w"> </span><span class="n">format</span><span class="w"> </span><span class="n">mix</span><span class="o">.</span><span class="n">exs</span><span class="w"> </span><span class="s">&quot;lib/**/*.{ex,exs}&quot;</span><span class="w"> </span><span class="s">&quot;test/**/*.{ex,exs}&quot;</span></code></pre>
<p>If any of the files is <code class="inline">-</code>, then the output is read from stdin
and written to stdout.</p>
<h2 id="module-formatting-options" class="section-heading">
  <a href="#module-formatting-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Formatting options
</h2>

<p>The formatter will read a <code class="inline">.formatter.exs</code> in the current directory for
formatter configuration. Evaluating this file should return a keyword list.</p>
<p>Here is an example <code class="inline">.formatter.exs</code> that works as a starting point:</p>
<pre><code class="nohighlight makeup elixir"><span class="p" data-group-id="7120910524-1">[</span><span class="w">
  </span><span class="ss">inputs</span><span class="p">:</span><span class="w"> </span><span class="p" data-group-id="7120910524-2">[</span><span class="s">&quot;{mix,.formatter}.exs&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;{config,lib,test}/**/*.{ex,exs}&quot;</span><span class="p" data-group-id="7120910524-2">]</span><span class="w">
</span><span class="p" data-group-id="7120910524-1">]</span></code></pre>
<p>Besides the options listed in <a href="https://hexdocs.pm/elixir/Code.html#format_string!/2"><code class="inline">Code.format_string!/2</code></a>, the <code class="inline">.formatter.exs</code>
supports the following options:</p>
<ul>
<li><p><code class="inline">:inputs</code> (a list of paths and patterns) - specifies the default inputs
to be used by this task. For example, <code class="inline">[&quot;mix.exs&quot;, &quot;{config,lib,test}/**/*.{ex,exs}&quot;]</code>.
Patterns are expanded with <a href="https://hexdocs.pm/elixir/Path.html#wildcard/2"><code class="inline">Path.wildcard/2</code></a>.</p>
</li>
<li><p><code class="inline">:subdirectories</code> (a list of paths and patterns) - specifies subdirectories
that have their own formatting rules. Each subdirectory should have a
<code class="inline">.formatter.exs</code> that configures how entries in that subdirectory should be
formatted as. Configuration between <code class="inline">.formatter.exs</code> are not shared nor
inherited. If a <code class="inline">.formatter.exs</code> lists “lib/app” as a subdirectory, the rules
in <code class="inline">.formatter.exs</code> won’t be available in <code class="inline">lib/app/.formatter.exs</code>.
Note that the parent <code class="inline">.formatter.exs</code> must not specify files inside the “lib/app”
subdirectory in its <code class="inline">:inputs</code> configuration. If this happens, the behaviour of
which formatter configuration will be picked is unspecified.</p>
</li>
<li><p><code class="inline">:import_deps</code> (a list of dependencies as atoms) - specifies a list
 of dependencies whose formatter configuration will be imported.
 When specified, the formatter should run in the same directory as
 the <code class="inline">mix.exs</code> file that defines those dependencies. See the “Importing
 dependencies configuration” section below for more information.</p>
</li>
<li><p><code class="inline">:export</code> (a keyword list) - specifies formatter configuration to be exported.
See the “Importing dependencies configuration” section below.</p>
</li>
</ul>
<h2 id="module-task-specific-options" class="section-heading">
  <a href="#module-task-specific-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Task-specific options
</h2>

<ul>
<li><p><code class="inline">--check-formatted</code> - checks that the file is already formatted.
This is useful in pre-commit hooks and CI scripts if you want to
reject contributions with unformatted code. However keep in mind
that the formatted output may differ between Elixir versions as
improvements and fixes are applied to the formatter.</p>
</li>
<li><p><code class="inline">--check-equivalent</code> - checks if the files after formatting have the
same AST as before formatting. If the ASTs are not equivalent,
it is a bug in the code formatter. This option is recommended if you
are automatically formatting files.</p>
</li>
<li><p><code class="inline">--dry-run</code> - does not save files after formatting.</p>
</li>
<li><p><code class="inline">--dot-formatter</code> - path to the file with formatter configuration.
Defaults to <code class="inline">.formatter.exs</code> if one is available. See the “<code class="inline">.formatter.exs</code>”
section for more information.</p>
</li>
</ul>
<p>If any of the <code class="inline">--check-*</code> flags are given and a check fails, the formatted
contents won’t be written to disk nor printed to standard output.</p>
<h2 id="module-when-to-format-code" class="section-heading">
  <a href="#module-when-to-format-code" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  When to format code
</h2>

<p>We recommend developers to format code directly in their editors, either
automatically when saving a file or via an explicit command or key binding. If
such option is not yet available in your editor of choice, adding the required
integration is usually a matter of invoking:</p>
<pre><code class="nohighlight makeup elixir"><span class="n">cd</span><span class="w"> </span><span class="err">$</span><span class="n">project</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">mix</span><span class="w"> </span><span class="n">format</span><span class="w"> </span><span class="err">$</span><span class="n">file</span></code></pre>
<p>where <code class="inline">$file</code> refers to the current file and <code class="inline">$project</code> is the root of your
project.</p>
<p>It is also possible to format code across the whole project by passing a list
of patterns and files to <code class="inline">mix format</code>, as shown at the top of this task
documentation. This list can also be set in the <code class="inline">.formatter.exs</code> under the
<code class="inline">:inputs</code> key.</p>
<h2 id="module-importing-dependencies-configuration" class="section-heading">
  <a href="#module-importing-dependencies-configuration" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Importing dependencies configuration
</h2>

<p>This task supports importing formatter configuration from dependencies.</p>
<p>A dependency that wants to export formatter configuration needs to have a
<code class="inline">.formatter.exs</code> file at the root of the project. In this file, the dependency
can export a <code class="inline">:export</code> option with configuration to export. For now, only one
option is supported under <code class="inline">:export</code>: <code class="inline">:locals_without_parens</code> (whose value has
the same shape as the value of the <code class="inline">:locals_without_parens</code> in <a href="https://hexdocs.pm/elixir/Code.html#format_string!/2"><code class="inline">Code.format_string!/2</code></a>).</p>
<p>The functions listed under <code class="inline">:locals_without_parens</code> in the <code class="inline">:export</code> option of
a dependency can be imported in a project by listing that dependency in the
<code class="inline">:import_deps</code> option of the formatter configuration file of the project.</p>
<p>For example, consider I have a project <code class="inline">my_app</code> that depends on <code class="inline">my_dep</code>.
<code class="inline">my_dep</code> wants to export some configuration, so <code class="inline">my_dep/.formatter.exs</code>
would look like this:</p>
<pre><code class="nohighlight makeup elixir"><span class="c1"># my_dep/.formatter.exs</span><span class="w">
</span><span class="p" data-group-id="8713458867-1">[</span><span class="w">
  </span><span class="c1"># Regular formatter configuration for my_dep</span><span class="w">
  </span><span class="c1"># ...</span><span class="w">

  </span><span class="ss">export</span><span class="p">:</span><span class="w"> </span><span class="p" data-group-id="8713458867-2">[</span><span class="w">
    </span><span class="ss">locals_without_parens</span><span class="p">:</span><span class="w"> </span><span class="p" data-group-id="8713458867-3">[</span><span class="ss">some_dsl_call</span><span class="p">:</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="ss">some_dsl_call</span><span class="p">:</span><span class="w"> </span><span class="mi">3</span><span class="p" data-group-id="8713458867-3">]</span><span class="w">
  </span><span class="p" data-group-id="8713458867-2">]</span><span class="w">
</span><span class="p" data-group-id="8713458867-1">]</span></code></pre>
<p>In order to import configuration, <code class="inline">my_app</code>’s <code class="inline">.formatter.exs</code> would look like
this:</p>
<pre><code class="nohighlight makeup elixir"><span class="c1"># my_app/.formatter.exs</span><span class="w">
</span><span class="p" data-group-id="3835088456-1">[</span><span class="w">
  </span><span class="ss">import_deps</span><span class="p">:</span><span class="w"> </span><span class="p" data-group-id="3835088456-2">[</span><span class="ss">:my_dep</span><span class="p" data-group-id="3835088456-2">]</span><span class="w">
</span><span class="p" data-group-id="3835088456-1">]</span></code></pre>
        </section>

        <section id="summary" class="details-list">
          <h1 class="section-heading">
            <a class="hover-link" href="#summary">
              <span class="icon-link" aria-hidden="true"></span>
              <span class="sr-only">Link to this section</span>
            </a>
            Summary
          </h1>
          
  <div class="summary-functions summary">
    <h2>
      <a href="#functions">Functions</a>
    </h2>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#formatter_opts_for_file/2">formatter_opts_for_file(file, opts \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Returns formatter options to be used for the given file</p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#read_manifest/1">read_manifest(manifest)</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#run/1">run(args)</a>
  </div>
    <div class="summary-synopsis"><p>A task needs to implement <code class="inline">run</code> which receives
a list of command line args</p>
</div>
</div>
  </div>
          
        </section>



        <section id="functions" class="details-list">
          <h1 class="section-heading">
            <a class="hover-link" href="#functions">
              <span class="icon-link" aria-hidden="true"></span>
              <span class="sr-only">Link to this section</span>
            </a>
            Functions
          </h1>
<div class="detail" id="formatter_opts_for_file/2">
  
    <span id="formatter_opts_for_file/1"></span>
  <div class="detail-header">
    <a href="#formatter_opts_for_file/2" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">formatter_opts_for_file(file, opts \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/tasks/format.ex#L155" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
          </div>
  <section class="docstring">
<p>Returns formatter options to be used for the given file.</p>
  </section>
</div>
<div class="detail" id="read_manifest/1">
    <div class="detail-header">
    <a href="#read_manifest/1" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">read_manifest(manifest)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/tasks/format.ex#L213" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
          </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="run/1">
    <div class="detail-header">
    <a href="#run/1" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">run(args)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/mix/lib/mix/tasks/format.ex#L138" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
          </div>
  <section class="docstring">
<p>A task needs to implement <code class="inline">run</code> which receives
a list of command line args.</p>
<p>Callback implementation for <a href="Mix.Task.html#c:run/1"><code class="inline">Mix.Task.run/1</code></a>.</p>
  </section>
</div>
        </section>

          <footer class="footer">
        <p>
          <span class="line">
            Built using
            <a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener">ExDoc</a> (v0.19.1),
          </span>
          <span class="line">
            designed by
            <a href="https://twitter.com/dignifiedquire" target="_blank" rel="noopener" title="@dignifiedquire">Friedel Ziegelmayer</a>.
            </span>
        </p>
      </footer>
    </div>
  </div>
</section>
</div>
  <script src="dist/app-a0c90688fa.js"></script>
  
  </body>
</html>