@@ -13,82 +13,76 @@ defmodule Mix.Tasks.Format do
13
13
14
14
## Formatting options
15
15
16
- Formatting is done with the `Code.format_string!/2` function.
17
- For complete list of formatting options please refer to its
18
- description.
19
- A `.formatter.exs` file can also be defined for customizing input
20
- files and the formatter itself.
16
+ The formatter will read a `.formatter.exs` in the current directory for
17
+ formatter configuration. Evaluating this file should return a keyword list
18
+ with any of the options supported by `Code.format_string!/2`.
19
+
20
+ The `.formatter.exs` also supports other options:
21
+
22
+ * `:inputs` (a list of paths and patterns) - specifies the default inputs
23
+ to be used by this task. For example, `["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]`.
24
+
25
+ * `:import_deps` (a list of dependencies as atoms) - specifies a list
26
+ of dependencies whose formatter configuration will be imported.
27
+ When specified, the formatter should run in the same directory as
28
+ the `mix.exs` file that defines those depednencies. See the "Importing
29
+ dependencies configuration" section below for more information.
30
+
31
+ * `:export` (a keyword list) - specifies formatter configuration to be exported.
32
+ See the "Importing dependencies configuration" section below.
21
33
22
34
## Task-specific options
23
35
24
36
* `--check-formatted` - check that the file is already formatted.
25
37
This is useful in pre-commit hooks and CI scripts if you want to
26
- reject contributions with unformatted code. However, keep in mind,
27
- that the formatting output may differ between Elixir versions as
38
+ reject contributions with unformatted code. However keep in mind
39
+ that the formatted output may differ between Elixir versions as
28
40
improvements and fixes are applied to the formatter.
29
41
30
- * `--check-equivalent` - check if the file after formatting has the
31
- same AST. If the ASTs are not equivalent, it is a bug in the code
32
- formatter. This option is recommended if you are automatically
33
- formatting files.
42
+ * `--check-equivalent` - check if the files after formatting have the
43
+ same AST as before formatting . If the ASTs are not equivalent,
44
+ it is a bug in the code formatter. This option is recommended if you
45
+ are automatically formatting files.
34
46
35
47
* `--dry-run` - do not save files after formatting.
36
48
37
- * `--dot-formatter` - the file with formatter configuration.
38
- Defaults to `.formatter.exs` if one is available, see next section.
49
+ * `--dot-formatter` - path to the file with formatter configuration.
50
+ Defaults to `.formatter.exs` if one is available. See the "`.formatter.exs`"
51
+ section for more information.
39
52
40
53
If any of the `--check-*` flags are given and a check fails, the formatted
41
- contents won't be written to disk nor printed to stdout.
42
-
43
- ## `.formatter.exs`
44
-
45
- The formatter will read a `.formatter.exs` in the current directory for
46
- formatter configuration. It should return a keyword list with any of the
47
- options supported by `Code.format_string!/2`.
48
-
49
- The `.formatter.exs` also supports other options:
50
-
51
- * `:inputs` (a list of paths and patterns) - specifies the default inputs
52
- to be used by this task. For example, `["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]`.
53
-
54
- * `:import_deps` (a list of dependencies as atoms) - specifies a list
55
- of dependencies whose formatter configuration will be imported.
56
- See the "Importing dependencies configuration" section below for more
57
- information.
58
-
59
- * `:export` (a keyword list) - specifies formatter configuration to be exported. See the
60
- "Importing dependencies configuration" section below.
54
+ contents won't be written to disk nor printed to standard output.
61
55
62
56
## When to format code
63
57
64
- We recommend developers to format code directly in their editors. Either
65
- automatically on save or via an explicit command/ key binding. If such option
66
- is not yet available in your editor of choice, adding the required integration
67
- is relatively simple as it is a matter of invoking
58
+ We recommend developers to format code directly in their editors, either
59
+ automatically when saving a file or via an explicit command or key binding. If
60
+ such option is not yet available in your editor of choice, adding the required
61
+ integration is usually a matter of invoking:
68
62
69
63
cd $project && mix format $file
70
64
71
65
where `$file` refers to the current file and `$project` is the root of your
72
66
project.
73
67
74
68
It is also possible to format code across the whole project by passing a list
75
- of patterns and files to `mix format`, as showed at the top of this task
69
+ of patterns and files to `mix format`, as shown at the top of this task
76
70
documentation. This list can also be set in the `.formatter.exs` under the
77
71
`:inputs` key.
78
72
79
73
## Importing dependencies configuration
80
74
81
75
This task supports importing formatter configuration from dependencies.
82
76
83
- A dependency that wants to export formatter configuration needs to have a `.formatter.exs` file
84
- at the root of the project. In this file, the dependency can export a `:export` option with
85
- configuration to export. For now, only one option is supported under `:export`:
86
- `: locals_without_parens` (whose value has the same shape as the value of the
87
- `:locals_without_parens` in `Code.format_string!/2`).
77
+ A dependency that wants to export formatter configuration needs to have a
78
+ `.formatter.exs` file at the root of the project. In this file, the dependency
79
+ can export a `:export` option with configuration to export. For now, only one
80
+ option is supported under `:export`: `: locals_without_parens` (whose value has
81
+ the same shape as the value of the `:locals_without_parens` in `Code.format_string!/2`).
88
82
89
- The functions listed under `:locals_without_parens` in the `:export` option of a dependency
90
- can be imported in a project by listing that dependency in the `:import_deps`
91
- option of the formatter configuration file of the project.
83
+ The functions listed under `:locals_without_parens` in the `:export` option of
84
+ a dependency can be imported in a project by listing that dependency in the
85
+ `:import_deps` option of the formatter configuration file of the project.
92
86
93
87
For example, consider I have a project `my_app` that depends on `my_dep`.
94
88
`my_dep` wants to export some configuration, so `my_dep/.formatter.exs`
0 commit comments