Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ex_doc admonition blocks when possible #12445

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/elixir/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ defmodule Application do
You can also change the application environment dynamically by using functions
such as `put_env/3` and `delete_env/2`.

> Note: The config files `config/config.exs` and `config/runtime.exs`
> #### Environment in Libraries {: .tip}
>
> The config files `config/config.exs` and `config/runtime.exs`
> are rarely used by libraries. Libraries typically define their environment
> in the `def application` function of their `mix.exs`. Configuration files
> in the `application/0` function of their `mix.exs`. Configuration files
> are rather used by applications to configure their libraries.

> Note: Each application is responsible for its own environment. Do not
> #### Reading the Environment of Other Applications {: .warning}
>
> Each application is responsible for its own environment. Do not
> use the functions in this module for directly accessing or modifying
> the environment of other applications. Whenever you change the application
> environment, Elixir's build tool will only recompile the files that
Expand Down
8 changes: 6 additions & 2 deletions lib/elixir/lib/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5540,7 +5540,9 @@ defmodule Kernel do
As seen as in the example above, `super` can be used to call the default
implementation.

> Note: use `defoverridable` with care. If you need to define multiple modules
> #### Disclaimer {: .tip}
>
> Use `defoverridable` with care. If you need to define multiple modules
> with the same behaviour, it may be best to move the default implementation
> to the caller, and check if a callback exists via `Code.ensure_loaded?/1` and
> `function_exported?/3`.
Expand Down Expand Up @@ -5722,7 +5724,9 @@ defmodule Kernel do
the usual macro rules apply, and its return value should be quoted code
that is then inserted where `use/2` is called.

> Note: `use MyModule` works as a code injection point in the caller.
> #### Code Injection {: .warning}
>
> `use MyModule` works as a **code-injection point** in the caller.
> Given the caller of `use MyModule` has little control over how the
> code is injected, `use/2` should be used with care. If you can,
> avoid use in favor of `import/2` or `alias/2` whenever possible.
Expand Down
4 changes: 3 additions & 1 deletion lib/elixir/lib/macro.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ defmodule Macro do
To learn more about Elixir's AST and how to build them programmatically,
see `quote/2`.

> Note: the functions in this module do not evaluate code. In fact,
> #### Evaluating Code {: .tip}
>
> The functions in this module do not evaluate code. In fact,
> evaluating code from macros is often an anti-pattern. For code
> evaluation, see the `Code` module.

Expand Down
10 changes: 7 additions & 3 deletions lib/elixir/lib/map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ defmodule Map do
map.non_existing_key
** (KeyError) key :non_existing_key not found in: %{baz: "bong", foo: "bar"}

> Note: do not add parens when accessing fields, such as in `data.key()`.
> If parenthesis are used, Elixir will expect `data` to be an atom representing
> #### Avoid Parentheses {: .warning}
>
> Do not add parentheses when accessing fields, such as in `data.key()`.
> If parentheses are used, Elixir will expect `data` to be an atom representing
> a module and attempt to call the *function* `key/0` in it.

The two syntaxes for accessing keys reveal the dual nature of maps. The `map[key]`
Expand Down Expand Up @@ -1078,7 +1080,9 @@ defmodule Map do
See also `reject/2` which discards all elements where the
function returns a truthy value.

> Note: if you find yourself doing multiple calls to `Map.filter/2`
> #### Performance Considerations {: .tip}
>
> If you find yourself doing multiple calls to `Map.filter/2`
> and `Map.reject/2` in a pipeline, it is likely more efficient
> to use `Enum.map/2` and `Enum.filter/2` instead and convert to
> a map at the end using `Map.new/1`.
Expand Down
6 changes: 4 additions & 2 deletions lib/elixir/lib/map_set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,12 @@ defmodule MapSet do
Also see `reject/2` which discards all elements where the function returns
a truthy value.

> Note: if you find yourself doing multiple calls to `MapSet.filter/2`
> #### Performance Considerations {: .tip}
>
> If you find yourself doing multiple calls to `MapSet.filter/2`
> and `MapSet.reject/2` in a pipeline, it is likely more efficient
> to use `Enum.map/2` and `Enum.filter/2` instead and convert to
> a map at the end using `Map.new/1`.
> a map at the end using `MapSet.new/1`.

## Examples

Expand Down
4 changes: 3 additions & 1 deletion lib/elixir/lib/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,9 @@ defmodule String do
function will search if any of the strings in `contents`
are part of `string`.

> Note: if you want to check if `string` is listed in `contents`,
> #### Searching For a String In a List {: .tip}
>
> If you want to check if `string` is listed in `contents`,
> where `contents` is a list, use `Enum.member?(contents, string)`
> instead.

Expand Down
4 changes: 3 additions & 1 deletion lib/elixir/lib/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ defmodule Supervisor do
a generic server, that keeps a counter. Other processes can then send
messages to this process to read the counter and bump its value.

> Note: in practice you would not define a counter as a GenServer. Instead,
> #### Disclaimer {: .neutral}
>
> In practice you would not define a counter as a GenServer. Instead,
> if you need a counter, you would pass it around as inputs and outputs to
> the functions that need it. The reason we picked a counter in this example
> is due to its simplicity, as it allows us to focus on how supervisors work.
Expand Down
6 changes: 4 additions & 2 deletions lib/elixir/lib/uri.ex
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,10 @@ defmodule URI do
If a `%URI{}` struct is given to this function, this function returns it
unmodified.

> Note: this function sets the field :authority for backwards
> compatibility reasons but it is deprecated.
> #### `:authority` Field {: .info}
>
> This function sets the field `:authority` for backwards-compatibility reasons
> but it is deprecated.

## Examples

Expand Down
4 changes: 3 additions & 1 deletion lib/mix/lib/mix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ defmodule Mix do
the application environment. On this section, we will focus on how to configure
it at two distinct moments: build-time and runtime.

> Note: The application environment is discouraged for libraries. See Elixir's
> #### Avoiding the Application Environment {: .warning}
>
> The application environment is discouraged for libraries. See Elixir's
> [Library Guidelines](https://hexdocs.pm/elixir/library-guidelines.html) for
> more information.

Expand Down
4 changes: 3 additions & 1 deletion lib/mix/lib/mix/tasks/escript.build.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ defmodule Mix.Tasks.Escript.Build do
the compiled `.beam` files to reduce the size of the escript.
If this is not desired, check the `:strip_beams` option.

> Note: escripts do not support projects and dependencies
> #### `priv` Directory Support {: .warning}
>
> escripts do not support projects and dependencies
> that need to store or read artifacts from the priv directory.

## Command line options
Expand Down