Skip to main content

W0055 - Could be a string literal

Information

-module(example).

foo() ->
atom_to_list(foo).
%% ^^^^^^^^^^^^^^^^^ 💡 information: Could be rewritten as a string literal.

bar() ->
atom_to_binary(bar).
%% ^^^^^^^^^^^^^^^^^^^ 💡 information: Could be rewritten as a binary string literal.

baz() ->
list_to_atom("baz").
%% ^^^^^^^^^^^^^^^^^^^ 💡 information: Could be rewritten as an atom literal.

This diagnostic is triggered when a string or atom literal is immediately converted to a different string or atom type.

Whilst the compiler will often optimise these conversions away, it is still good practice to to use the literal type that is most appropriate for the context in order to keep the code clear and concise.

Fix

Rewrite the value as a literal of the appropriate type.

-module(example).

foo() ->
"foo".

bar() ->
~"bar".

baz() ->
baz.