Jump.CredoChecks.UndeclaredExternalResource (Jump.CredoChecks v0.4.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

When a module attribute reads from the file system (via File.read!/1, File.ls!/1, etc.), the file's contents get baked into the compiled module. Without an @external_resource declaration, mix compile has no idea the module depends on that file, so editing the file will not trigger a recompile and the module will keep stale data until something else forces a rebuild.

# ❌ Bad — editing prompt.md won't recompile this module
defmodule Foo do
  @prompt_path "priv/data/prompt.md"
  @prompt File.read!(@prompt_path)
end

# ✅ Good
defmodule Foo do
  @prompt_path "priv/data/prompt.md"
  @external_resource @prompt_path
  @prompt File.read!(@prompt_path)
end

When both the paths being read and the @external_resource values are hard-coded strings (written inline, held in a module attribute, or built by joining hard-coded strings with Path.join), this check also verifies that they match up.

However, when either side is built dynamically (via variables, other function calls, etc.), the presence of any @external_resource declaration in the module satisfies the check.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.