Skip to content

Enhancements - #9

Open
Krapaince wants to merge 13 commits into
masterfrom
enhancement
Open

Enhancements#9
Krapaince wants to merge 13 commits into
masterfrom
enhancement

Conversation

@Krapaince

Copy link
Copy Markdown
Contributor
  • chore: bump exfsm version to 1.0.0
  • chore: bump exdoc from 0.38.4 to 0.40.3
  • refactor!: replace @doc by @{transition,bypass}_doc attribute
  • ci: replace travis CI by github workflow
  • test: add transition error handling tests
  • feat: add when clause support for macros
  • feat(format): make macro usable without parens
  • fix: clear Elixir's compiler v1.20 warnings

Changes from 7d60cd3 are a proposition. The best option might be to remove the functions ExFSM.Machine.infos/2, ExFSM.Machine.find_info/2, and the docs/0 function created in the handler module by the ExFSM.__before_compile__/1 macros. The value returned by doc contains the tuple {line, doc} returned by the @doc attribute, however it should only be a string as this doctest shows us. Since no one opened an issue, I think it is safe to remove this unused feature.

@Krapaince
Krapaince force-pushed the enhancement branch 2 times, most recently from c3dcaa0 to 1e85c26 Compare July 27, 2026 13:43
Krapaince added 12 commits July 28, 2026 16:53
@doc is an Elixir reserved attribute which emits a warning when defined multiple
time for a function, Like so:

    warning: redefining @doc attribute previously set at line 20.

    Please remove the duplicate docs. If instead you want to override a
    previously defined @doc, attach the @doc attribute to a function head (the
    function signature not followed by any do-block). For example:

        @doc """
        new docs
        """
        def on(...)

    │
 25 │   @doc "..."
    │   ~~~~~~~~~~~
    │
    └─ test/fsm/light.ex:25: ExFSM.Test.FSM.Light.on/2

Using @transition_doc and @bypass_doc fixes this issue. It also fixes the value
returned by `docs/0` as the @doc attribute comes as a tuple `{line, doc}`
instead of the wanted value `doc`.
Comment thread lib/exfsm.ex
Comment on lines +109 to +112
fsm = Macro.escape(Module.get_attribute(env.module, fsm_attribute_name()))

quote do
def fsm, do: @fsm
def fsm, do: unquote(fsm)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a @fsm un peu partout, sauf ici, c'est voulu ?

Comment on lines +37 to +38
state_pad = rows |> Enum.map(&String.length(elem(&1, 0))) |> Enum.max()
event_pad = rows |> Enum.map(&String.length(elem(&1, 1))) |> Enum.max()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
state_pad = rows |> Enum.map(&String.length(elem(&1, 0))) |> Enum.max()
event_pad = rows |> Enum.map(&String.length(elem(&1, 1))) |> Enum.max()
state_pad = Enum.max_by(rows, &String.length(elem(&1, 0)))
event_pad = Enum.max_by(rows, &String.length(elem(&1, 1)))

@Krapaince Krapaince Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No can do as this function is not yet available in Elixir 1.12 and it needs to work with this version based on the contribution guide

EDIT: I was thinking of Enum.sum_by my bad, max_by was introduced way earlier, will change this.

Comment thread lib/exfsm.ex
defp attribute_description_line, do: :"#{attribute_name()}_line"
defp fsm_attribute_name, do: :fsm

defmacro __build_action_name_macros__(env) do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je sais pas si on veut vraiment les appeler actions vu qu'en jargon FSM c'est de l'output à executer

Comment thread lib/exfsm.ex
A sigil to enumerate transitions.

When an FSM grows, it helps to quickly get an overview of the available
transition. This sigil's purpose is only for documentation purpose:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
transition. This sigil's purpose is only for documentation purpose:
transition. This sigil's purpose is only for documentation:

or something

Comment thread lib/exfsm.ex
end
end

defp format_transitions(transitions) do

@Shakadak Shakadak Aug 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est quoi qui fait qu'on ne peut pas réutiliser ce qu'il y a dans le module du formatter ? ou vice-versa

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est à dire quelle module?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread README.md

- define FSM with handler modules defining each transition as a simple function but using a
```elixir
defmodule Ligh do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defmodule Ligh do
defmodule Light do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants