diff --git a/doc_rules/elvis_style/prefer_unquoted_atoms.md b/doc_rules/elvis_style/prefer_unquoted_atoms.md index 673b41d2..1f545c6e 100644 --- a/doc_rules/elvis_style/prefer_unquoted_atoms.md +++ b/doc_rules/elvis_style/prefer_unquoted_atoms.md @@ -1,6 +1,6 @@ # Prefer unquoted atoms -Do not use quotes on atoms that are not need it. +Do not use quotes on atoms that don't need to be quoted. > Works on `.beam` file? No. diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 424095ee..4b037cc8 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -1474,22 +1474,17 @@ check_atom_names(Regex, RegexEnclosed, [AtomNode | RemainingAtomNodes], AccIn) - check_atom_quotes([] = _AtomNodes, Acc) -> Acc; check_atom_quotes([AtomNode | RemainingAtomNodes], AccIn) -> - Regex = "^'([a-z_0-9)]+)'$", - RegexEnclosed = ".*", - AtomName0 = ktn_code:attr(text, AtomNode), + AtomName = ktn_code:attr(text, AtomNode), ValueAtomName = ktn_code:attr(value, AtomNode), - {IsEnclosed, AtomName} = string_strip_enclosed(AtomName0), IsException = is_exception_prefer_quoted(ValueAtomName), - RE = re_compile_for_atom_type(IsEnclosed, Regex, RegexEnclosed), + AccOut = - case re:run( - unicode:characters_to_list(AtomName, unicode), RE) - of - {match, _Captured} when not IsException -> + case unicode:characters_to_list(AtomName, unicode) of + [$' | _] when not IsException -> Msg = ?ATOM_PREFERRED_QUOTES_MSG, {Line, _} = ktn_code:attr(location, AtomNode), - Info = [AtomName0, Line, RegexEnclosed], + Info = [AtomName, Line], Result = elvis_result:new(item, Msg, Info, Line), AccIn ++ [Result]; _ -> diff --git a/test/examples/pass_unquoted_atoms.erl b/test/examples/pass_unquoted_atoms.erl index eaded94c..ffbe676e 100644 --- a/test/examples/pass_unquoted_atoms.erl +++ b/test/examples/pass_unquoted_atoms.erl @@ -5,5 +5,7 @@ test(_Test) -> ok. test(_A, nice_atom_name) -> perfect_atomname; -test(_A, _B) -> unquoted_atom. +test(_Reserved, _Words) -> ['after', 'and', 'andalso', 'band', 'begin', 'bnot', 'bor', 'bsl', 'bsr', 'bxor', 'case', + 'catch', 'cond', 'div', 'end', 'fun', 'if', 'let', 'not', 'of', 'or', 'orelse', 'receive', + 'rem', 'try', 'when', 'xor'].