Skip to content

Commit 56f1e04

Browse files
fahchenclaude
andcommitted
chore: fix credo issues surfaced by 1.7.18 upgrade
Credo 1.7.18 tightens default checks compared to 1.7.7. All issues are pre-existing but were hidden by the older version. - Replace `length(list) > 0` with `list != []` in colset and doc_fields - Name unused match variables (`_occurrence`, `_args`) to follow repo convention - Flatten three too-deeply-nested function bodies by extracting helpers in arc, binding, and computation modules; behavior unchanged Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8782d04 commit 56f1e04

7 files changed

Lines changed: 69 additions & 52 deletions

File tree

lib/coloured_flow/definition/arc.ex

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,21 @@ defmodule ColouredFlow.Definition.Arc do
8888

8989
def build_expression(:p_to_t, code) do
9090
with {:ok, expression} <- Expression.build(code) do
91-
case validate_bind_exprs(expression.expr) do
92-
[] ->
93-
{:error, {[], "missing `bind` in expression", code}}
94-
95-
validations ->
96-
case Enum.find(validations, &match?({:error, _reason}, &1)) do
97-
nil -> {:ok, expression}
98-
{:error, reason} -> {:error, reason}
99-
end
100-
end
91+
validate_p_to_t_bindings(expression, code)
92+
end
93+
end
94+
95+
defp validate_p_to_t_bindings(expression, code) do
96+
case validate_bind_exprs(expression.expr) do
97+
[] -> {:error, {[], "missing `bind` in expression", code}}
98+
validations -> first_binding_error(expression, validations)
99+
end
100+
end
101+
102+
defp first_binding_error(expression, validations) do
103+
case Enum.find(validations, &match?({:error, _reason}, &1)) do
104+
nil -> {:ok, expression}
105+
{:error, reason} -> {:error, reason}
101106
end
102107
end
103108

lib/coloured_flow/enabled_binding_elements/binding.ex

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,20 @@ defmodule ColouredFlow.EnabledBindingElements.Binding do
7171
"""
7272
@spec combine(bindings_list :: [[[binding()]]]) :: [[binding()]]
7373
def combine(bindings_list) do
74-
Enum.reduce(bindings_list, [[]], fn bindings, prevs ->
75-
for prev <- prevs, binding <- bindings, reduce: [] do
76-
acc ->
77-
case get_conflicts(prev, binding) do
78-
[] -> [Keyword.merge(prev, binding) | acc]
79-
_other -> acc
80-
end
81-
end
82-
end)
74+
Enum.reduce(bindings_list, [[]], &combine_step/2)
75+
end
76+
77+
defp combine_step(bindings, prevs) do
78+
for prev <- prevs, binding <- bindings, reduce: [] do
79+
acc -> merge_if_compatible(acc, prev, binding)
80+
end
81+
end
82+
83+
defp merge_if_compatible(acc, prev, binding) do
84+
case get_conflicts(prev, binding) do
85+
[] -> [Keyword.merge(prev, binding) | acc]
86+
_other -> acc
87+
end
8388
end
8489

8590
@doc """

lib/coloured_flow/enabled_binding_elements/computation.ex

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,43 @@ defmodule ColouredFlow.EnabledBindingElements.Computation do
5151
binding_combinations = Binding.combine(arc_bindings)
5252

5353
Enum.flat_map(binding_combinations, fn binding ->
54-
inputs
55-
|> Enum.reduce_while([], fn {arc, place}, acc ->
56-
arc_binding = merge_constants(binding, arc, constants)
57-
58-
with(
59-
{:ok, {coefficient, value}} <- eval_arc(arc, arc_binding),
60-
colour_set = fetch_colour_set!(place.colour_set, cpnet),
61-
of_type_context = build_of_type_context(cpnet),
62-
{:ok, ^value} <- ColourSet.Of.of_type(value, colour_set.type, of_type_context),
63-
guard_binding = merge_constants(binding, transition, constants),
64-
{:ok, true} <- eval_transition_guard(transition, guard_binding),
65-
marking = get_marking(place, markings),
66-
tokens = MultiSet.duplicate(value, coefficient),
67-
true <- MultiSet.include?(marking.tokens, tokens)
68-
) do
69-
{:cont, [%Marking{place: place.name, tokens: tokens} | acc]}
70-
else
71-
_other -> {:halt, :error}
72-
end
73-
end)
74-
|> case do
75-
:error ->
76-
[]
54+
build_binding_element(inputs, binding, transition, constants, markings, cpnet)
55+
end)
56+
end
7757

78-
to_consume ->
79-
# binding here should not contain constants
80-
[BindingElement.new(transition.name, binding, to_consume)]
81-
end
58+
defp build_binding_element(inputs, binding, transition, constants, markings, cpnet) do
59+
case collect_consumption(inputs, binding, transition, constants, markings, cpnet) do
60+
:error -> []
61+
to_consume -> [BindingElement.new(transition.name, binding, to_consume)]
62+
end
63+
end
64+
65+
defp collect_consumption(inputs, binding, transition, constants, markings, cpnet) do
66+
Enum.reduce_while(inputs, [], fn {arc, place}, acc ->
67+
try_consume(arc, place, binding, transition, constants, markings, cpnet, acc)
8268
end)
8369
end
8470

71+
defp try_consume(arc, place, binding, transition, constants, markings, cpnet, acc) do
72+
arc_binding = merge_constants(binding, arc, constants)
73+
74+
with(
75+
{:ok, {coefficient, value}} <- eval_arc(arc, arc_binding),
76+
colour_set = fetch_colour_set!(place.colour_set, cpnet),
77+
of_type_context = build_of_type_context(cpnet),
78+
{:ok, ^value} <- ColourSet.Of.of_type(value, colour_set.type, of_type_context),
79+
guard_binding = merge_constants(binding, transition, constants),
80+
{:ok, true} <- eval_transition_guard(transition, guard_binding),
81+
marking = get_marking(place, markings),
82+
tokens = MultiSet.duplicate(value, coefficient),
83+
true <- MultiSet.include?(marking.tokens, tokens)
84+
) do
85+
{:cont, [%Marking{place: place.name, tokens: tokens} | acc]}
86+
else
87+
_other -> {:halt, :error}
88+
end
89+
end
90+
8591
@spec reject_invalid_bandings([[[BindingElement.binding()]]], ColouredPetriNet.t()) ::
8692
[[[BindingElement.binding()]]]
8793
defp reject_invalid_bandings(bindings_list, cpnet) do

lib/coloured_flow/notation/colset.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ defmodule ColouredFlow.Notation.Colset do
173173
defp decompose_union([], acc) do
174174
duplicate_tags = find_duplicate_tags(acc)
175175

176-
if length(duplicate_tags) > 0 do
176+
if duplicate_tags != [] do
177177
raise """
178178
Invalid union tags, duplicate tags found: `#{type_to_string(duplicate_tags)}`
179179
"""

lib/coloured_flow/runner/enactment/workitem_calibration.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ defmodule ColouredFlow.Runner.Enactment.WorkitemCalibration do
134134
workitem_occurrences = Keyword.fetch!(options, :workitem_occurrences)
135135

136136
to_consume_markings =
137-
Enum.flat_map(workitem_occurrences, fn {workitem, _} ->
137+
Enum.flat_map(workitem_occurrences, fn {workitem, _occurrence} ->
138138
workitem.binding_element.to_consume
139139
end)
140140

@@ -170,7 +170,8 @@ defmodule ColouredFlow.Runner.Enactment.WorkitemCalibration do
170170
ColouredPetriNet.t()
171171
) :: {enactment_state(), MultiSet.t(BindingElement.t())}
172172
defp produce_workitems(%Enactment{} = state, workitem_occurrences, %ColouredPetriNet{} = cpnet) do
173-
completed_workitem_ids = Enum.map(workitem_occurrences, fn {workitem, _} -> workitem.id end)
173+
completed_workitem_ids =
174+
Enum.map(workitem_occurrences, fn {workitem, _occurrence} -> workitem.id end)
174175
occurrences = Enum.map(workitem_occurrences, &elem(&1, 1))
175176

176177
{steps, markings} =

lib/coloured_flow/runner/storage/schemas/json_instance/codec/colour_set.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ defmodule ColouredFlow.Runner.Storage.Schemas.JsonInstance.Codec.ColourSet do
151151
Converts the `descr` to a JSON representation.
152152
"""
153153
@spec encode_descr(ColourSet.descr()) :: map()
154-
def encode_descr({primitive, _}) when primitive in @primitive_types do
154+
def encode_descr({primitive, _args}) when primitive in @primitive_types do
155155
%{
156156
"type" => Atom.to_string(primitive),
157157
"args" => []

lib/typed_structor/plugins/doc_fields.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule TypedStructor.Plugins.DocFields do
3535
end)
3636

3737
parameters_docs =
38-
if length(parameters) > 0 do
38+
if parameters != [] do
3939
"""
4040
## Parameters
4141
@@ -64,7 +64,7 @@ defmodule TypedStructor.Plugins.DocFields do
6464
end)
6565

6666
fields_docs =
67-
if length(fields) > 0 do
67+
if fields != [] do
6868
"""
6969
## Fields
7070

0 commit comments

Comments
 (0)