Skip to content

Commit

Permalink
chore: run format --migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 19, 2024
1 parent a504872 commit 354e714
Show file tree
Hide file tree
Showing 28 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/ash/actions/read/read.ex
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ defmodule Ash.Actions.Read do
initial_limit: query.limit,
initial_offset: query.offset,
page_opts:
unless opts[:inital_data] do
if !opts[:inital_data] do
page_opts
end,
initial_query: query,
Expand Down
4 changes: 2 additions & 2 deletions lib/ash/changeset/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ defmodule Ash.Changeset do
else
explicitly_changing_attributes =
Enum.map(
Map.keys(changeset.attributes) -- Map.get(changeset, :defaults, []) -- keys,
Map.keys(changeset.attributes) -- (Map.get(changeset, :defaults, []) -- keys),
fn key ->
{key, Ash.Changeset.get_attribute(changeset, key)}
end
Expand Down Expand Up @@ -2183,7 +2183,7 @@ defmodule Ash.Changeset do
else
tenant =
if identity.all_tenants? do
unless Ash.Resource.Info.multitenancy_global?(changeset.resource) do
if !Ash.Resource.Info.multitenancy_global?(changeset.resource) do
raise ArgumentError,
message: """
Cannot pre or eager check an identity that has `all_tenants?: true`
Expand Down
4 changes: 2 additions & 2 deletions lib/ash/code_interface.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Ash.CodeInterface do
def require_action(resource, interface) do
action = Ash.Resource.Info.action(resource, interface.action || interface.name)

unless action do
if !action do
raise Spark.Error.DslError,
module: resource,
message:
Expand Down Expand Up @@ -434,7 +434,7 @@ defmodule Ash.CodeInterface do
{key, [], Elixir}
end)

unless Enum.uniq(args) == args do
if Enum.uniq(args) != args do
raise """
Arguments #{inspect(args)} for #{interface.name} are not unique!
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/ash/data_layer/ets/ets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ defmodule Ash.DataLayer.Ets do
end)

with {:ok, table} <- wrap_or_create_table(resource, changeset.tenant),
_ <- unless(from_bulk_create?, do: log_create(resource, changeset)),
_ <- if(!from_bulk_create?, do: log_create(resource, changeset)),
{:ok, record} <- Ash.Changeset.apply_attributes(changeset),
record <- unload_relationships(resource, record),
{:ok, record} <- put_or_insert_new(table, {pkey, record}, resource) do
Expand Down Expand Up @@ -1523,7 +1523,7 @@ defmodule Ash.DataLayer.Ets do
pkey = pkey || pkey_map(resource, changeset.data)

with {:ok, table} <- wrap_or_create_table(resource, changeset.tenant),
_ <- unless(from_bulk?, do: log_update(resource, pkey, changeset)),
_ <- if(!from_bulk?, do: log_update(resource, pkey, changeset)),
{:ok, record} <-
do_update(
table,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule Ash.Policy.Authorizer.Transformers.AddMissingFieldPolicies do

module = Transformer.get_persisted(dsl, :module)

unless Enum.empty?(invalid_fields) do
if !Enum.empty?(invalid_fields) do
raise Spark.Error.DslError,
module: module,
path: [:field_policies],
Expand All @@ -82,7 +82,7 @@ defmodule Ash.Policy.Authorizer.Transformers.AddMissingFieldPolicies do
"""
end

unless Enum.empty?(missing_fields) do
if !Enum.empty?(missing_fields) do
raise Spark.Error.DslError,
module: module,
path: [:field_policies],
Expand Down
2 changes: 1 addition & 1 deletion lib/ash/policy/check/built_in_checks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule Ash.Policy.Check.Builtins do
@spec action_type(Ash.Resource.Actions.action_type()) :: Ash.Policy.Check.ref()
def action_type(action_type) do
Enum.each(List.wrap(action_type), fn type ->
unless type in [:create, :read, :update, :destroy, :action] do
if type not in [:create, :read, :update, :destroy, :action] do
raise ArgumentError, "Invalid action type: #{inspect(type)}"
end
end)
Expand Down
6 changes: 3 additions & 3 deletions lib/ash/policy/check/relating_to_actor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Ash.Policy.Check.RelatingToActor do
if is_nil(Map.get(actor, relationship.destination_attribute)) do
false
else
unless relationship.type == :belongs_to do
if relationship.type != :belongs_to do
raise "Can only use `belongs_to` relationships in relating_to_actor checks"
end

Expand Down Expand Up @@ -58,8 +58,8 @@ defmodule Ash.Policy.Check.RelatingToActor do
actor_keys = take_keys(actor, primary_key)
input_keys = take_keys(input, primary_key)

opts[:on_lookup] == :relate and Enum.all?(actor_keys, & &1) &&
Enum.all?(input_keys, & &1) and input_keys == actor_keys
((opts[:on_lookup] == :relate and Enum.all?(actor_keys, & &1)) &&
Enum.all?(input_keys, & &1)) and input_keys == actor_keys

_ ->
false
Expand Down
2 changes: 1 addition & 1 deletion lib/ash/query/function/function.ex
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ defmodule Ash.Query.Function do
can_return_nil?: 1,
returns: 0

unless unquote(opts[:no_inspect?]) do
if !unquote(opts[:no_inspect?]) do
defimpl Inspect do
import Inspect.Algebra

Expand Down
2 changes: 1 addition & 1 deletion lib/ash/query/operator/operator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ defmodule Ash.Query.Operator do
end

defmacro __using__(opts) do
unless opts[:operator] do
if !opts[:operator] do
raise "Operator is required!"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ash/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ defmodule Ash.Resource do
] do
@persist {:simple_notifiers, List.wrap(opts[:simple_notifiers])}

unless embedded? || has_domain? do
if !(embedded? || has_domain?) do
IO.warn("""
Configuration Error:
Expand Down
4 changes: 2 additions & 2 deletions lib/ash/resource/change/change.ex
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ defmodule Ash.Resource.Change do
end

if Module.defines?(__MODULE__, {:atomic, 3}, :def) do
unless Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
if !Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
@impl true
def atomic?, do: true
end
else
unless Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
if !Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
@impl true
def atomic?, do: false
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ash/resource/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ defmodule Ash.Schema do
Enum.each(struct_fields, &Module.put_attribute(__MODULE__, struct_fields_name, &1))
end

unless Kernel.Typespec.defines_type?(__MODULE__, {:t, 0}) do
if !Kernel.Typespec.defines_type?(__MODULE__, {:t, 0}) do
@type t :: %__MODULE__{}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Ash.Resource.Transformers.RequireUniqueActionNames do
|> Transformer.get_entities([:actions])
|> Enum.group_by(& &1.name)
|> Enum.each(fn {name, actions} ->
unless Enum.count(actions) == 1 do
if Enum.count(actions) != 1 do
raise DslError.exception(
message: """
Multiple actions (#{Enum.count(actions)}) with the name `#{name}` defined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Ash.Resource.Transformers.RequireUniqueFieldNames do
|> Enum.each(fn {name, groups} ->
name_count = Enum.count(groups)

unless name_count == 1 do
if name_count != 1 do
raise DslError.exception(
message: """
There are #{name_count} fields(attributes, calculations, aggregates, and relationships) that share the name `#{name}`
Expand Down
2 changes: 1 addition & 1 deletion lib/ash/resource/transformers/set_eager_check_with.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Ash.Resource.Transformers.SetEagerCheckWith do
|> Enum.reject(&(&1.eager_check? == false && &1.eager_check_with == nil))
|> Enum.reduce({:ok, dsl_state}, fn
%{eager_check?: true, eager_check_with: nil} = identity, {:ok, dsl_state} ->
unless domain do
if !domain do
raise Spark.Error.DslError,
module: Spark.Dsl.Transformer.get_persisted(dsl_state, :module),
path: [:identities, identity.name, :eager_check?],
Expand Down
2 changes: 1 addition & 1 deletion lib/ash/resource/transformers/set_pre_check_with.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Ash.Resource.Transformers.SetPreCheckWith do
|> Enum.reject(&(&1.pre_check? == false && &1.pre_check_with == nil))
|> Enum.reduce({:ok, dsl_state}, fn
%{pre_check?: true, pre_check_with: nil} = identity, {:ok, dsl_state} ->
unless domain do
if !domain do
raise Spark.Error.DslError,
module: Spark.Dsl.Transformer.get_persisted(dsl_state, :module),
path: [:identities, identity.name, :pre_check?],
Expand Down
2 changes: 1 addition & 1 deletion lib/ash/resource/transformers/set_primary_actions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ defmodule Ash.Resource.Transformers.SetPrimaryActions do
{type, []}
end

unless type in [:create, :update, :read, :destroy] do
if type not in [:create, :update, :read, :destroy] do
raise Spark.Error.DslError,
path: [:actions, :defaults, i],
message: "#{type} is not a valid action type"
Expand Down
4 changes: 2 additions & 2 deletions lib/ash/resource/validation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ defmodule Ash.Resource.Validation do
end

if Module.defines?(__MODULE__, {:atomic, 3}, :def) do
unless Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
if !Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
@impl true
def atomic?, do: true
end
else
unless Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
if !Module.defines?(__MODULE__, {:atomic?, 0}, :def) do
@impl true
def atomic?, do: false
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Ash.Resource.Verifiers.ValidateActionTypesSupported do
data_layer = Verifier.get_persisted(dsl_state, :data_layer)
resource = Verifier.get_persisted(dsl_state, :module)

unless data_layer && data_layer.can?(resource, action.type) do
if !(data_layer && data_layer.can?(resource, action.type)) do
message = """
`#{inspect(data_layer)}` does not support `#{action.type}` actions on this resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Ash.Resource.Verifiers.ValidateManagedRelationshipOpts do
&match?(%Ash.Resource.Change{change: {Ash.Resource.Change.ManageRelationship, _}}, &1)
)
|> Enum.each(fn %Ash.Resource.Change{change: {_, opts}} ->
unless Enum.find(action.arguments, &(&1.name == opts[:argument])) do
if !Enum.find(action.arguments, &(&1.name == opts[:argument])) do
raise Spark.Error.DslError,
path:
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Ash.Resource.Verifiers.ValidateRelationshipAttributes do
end

defp validate_relationship(relationship, attribute_names) do
unless relationship.source_attribute in attribute_names do
if relationship.source_attribute not in attribute_names do
raise Spark.Error.DslError,
path: [:relationships, relationship.name],
message:
Expand All @@ -37,14 +37,14 @@ defmodule Ash.Resource.Verifiers.ValidateRelationshipAttributes do
|> Ash.Resource.Info.attributes()
|> Enum.map(& &1.name)

unless relationship.source_attribute_on_join_resource in through_attributes do
if relationship.source_attribute_on_join_resource not in through_attributes do
raise Spark.Error.DslError,
path: [:relationships, relationship.name],
message:
"Relationship `#{relationship.name}` expects source attribute on resource `#{relationship.source_attribute_on_join_resource}` to be defined on #{inspect(relationship.through)}"
end

unless relationship.destination_attribute_on_join_resource in through_attributes do
if relationship.destination_attribute_on_join_resource not in through_attributes do
raise Spark.Error.DslError,
path: [:relationships, relationship.name],
message:
Expand All @@ -58,7 +58,7 @@ defmodule Ash.Resource.Verifiers.ValidateRelationshipAttributes do
|> Ash.Resource.Info.attributes()
|> Enum.map(& &1.name)

unless relationship.destination_attribute in destination_attributes do
if relationship.destination_attribute not in destination_attributes do
raise Spark.Error.DslError,
path: [:relationships, relationship.name],
message:
Expand Down
2 changes: 1 addition & 1 deletion lib/ash/resource/verifiers/verify_identities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Ash.Resource.Verifiers.VerifyIdentityFields do

for identity <- identities do
for key <- identity.keys do
unless Ash.Resource.Info.attribute(dsl, key) || Ash.Resource.Info.calculation(dsl, key) do
if !(Ash.Resource.Info.attribute(dsl, key) || Ash.Resource.Info.calculation(dsl, key)) do
raise Spark.Error.DslError,
module: Spark.Dsl.Verifier.get_persisted(dsl, :module),
message: "All identity keys must be attributes or calculations. Got: #{inspect(key)}",
Expand Down
8 changes: 4 additions & 4 deletions lib/ash/tracer/tracer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule Ash.Tracer do
compiling? = Code.can_await_module_compilation?()

metadata =
unless compiling? do
if !compiling? do
case :telemetry.list_handlers(telemetry_name) do
[] -> %{}
_ when is_function(metadata) -> apply(metadata, [])
Expand All @@ -99,7 +99,7 @@ defmodule Ash.Tracer do

start = System.monotonic_time()

unless compiling? do
if !compiling? do
:telemetry.execute(
telemetry_name ++ [:start],
%{system_time: System.system_time()},
Expand All @@ -112,7 +112,7 @@ defmodule Ash.Tracer do
after
duration = System.monotonic_time() - start

unless compiling? do
if !compiling? do
:telemetry.execute(
telemetry_name ++ [:stop],
%{system_time: System.system_time(), duration: duration},
Expand Down Expand Up @@ -221,7 +221,7 @@ defmodule Ash.Tracer do
def set_metadata(tracers, type, metadata) when is_list(tracers) do
tracers = Enum.filter(tracers, &Ash.Tracer.trace_type?(&1, type))

unless Enum.empty?(tracers) do
if !Enum.empty?(tracers) do
metadata = resolve_lazy(metadata)
Enum.each(tracers, & &1.set_metadata(type, metadata))
end
Expand Down
8 changes: 4 additions & 4 deletions lib/ash/type/type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ defmodule Ash.Type do

ash_type? = Ash.Type.ash_type?(type)

unless ash_type? do
if !ash_type? do
raise """
#{inspect(value)} is not a valid type.
Expand Down Expand Up @@ -2112,12 +2112,12 @@ defmodule Ash.Type do
defmacro __before_compile__(_env) do
quote generated: true do
if Module.defines?(__MODULE__, {:equal?, 2}, :def) do
unless Module.defines?(__MODULE__, {:simple_equality, 0}, :def) do
if !Module.defines?(__MODULE__, {:simple_equality, 0}, :def) do
@impl true
def simple_equality?, do: false
end
else
unless Module.defines?(__MODULE__, {:simple_equality, 0}, :def) do
if !Module.defines?(__MODULE__, {:simple_equality, 0}, :def) do
@impl true
def simple_equality?, do: true
end
Expand Down Expand Up @@ -2190,7 +2190,7 @@ defmodule Ash.Type do
def custom_apply_constraints_array?, do: false
end

unless Module.defines?(__MODULE__, {:can_load?, 1}, :def) do
if !Module.defines?(__MODULE__, {:can_load?, 1}, :def) do
@impl Ash.Type
if Module.defines?(__MODULE__, {:load, 4}, :def) do
def can_load?(_), do: true
Expand Down
4 changes: 2 additions & 2 deletions lib/ash/type/union.ex
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ defmodule Ash.Type.Union do

:map_with_tag ->
case Enum.find(types, fn {_type_name, config} ->
unless config[:tag] && config[:tag_value] do
if !(config[:tag] && config[:tag_value]) do
raise "Found a type without a tag when using the `:map_with_tag` storage constraint. Constraints: #{inspect(constraints)}"
end

Expand Down Expand Up @@ -700,7 +700,7 @@ defmodule Ash.Type.Union do
:map_with_tag ->
config = union_constraints[:types][type_name]

unless config[:tag] && config[:tag_value] do
if !(config[:tag] && config[:tag_value]) do
raise "Found a type without a tag when using the `:map_with_tag` storage constraint. Constraints: #{inspect(union_constraints)}"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/comparable/comp.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unless Code.ensure_loaded?(Comp) do
if !Code.ensure_loaded?(Comp) do
defmodule Comp do
@moduledoc """
Provides utilities to implement and work with `Comparable` types
Expand Down
2 changes: 1 addition & 1 deletion lib/comparable/comparable.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unless Code.ensure_loaded?(Comparable) do
if !Code.ensure_loaded?(Comparable) do
defprotocol Comparable do
@moduledoc """
Protocol which describes ordering relation for pair of types
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/gen/ash.gen.resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if Code.ensure_loaded?(Igniter) do
base =
Igniter.Project.Module.parse(options[:base])

unless base in List.wrap(Application.get_env(app_name, :base_resources)) do
if base not in List.wrap(Application.get_env(app_name, :base_resources)) do
raise """
The base module #{inspect(base)} is not in the list of base resources.
Expand Down

0 comments on commit 354e714

Please sign in to comment.