lpil / dogma

:closed_lock_with_key: A code style linter for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Foreign characters in file causes FunctionClauseError in Dogma.

Gyllsdorff opened this issue · comments

If a file have a ÅÄÖ character Dogma crashes with a FunctionClauseError error:

> mix dogma --strict
** (FunctionClauseError) no function clause matching in Dogma.Util.ScriptStrings.parse_code/2
    lib/dogma/util/script_strings.ex:18: Dogma.Util.ScriptStrings.parse_code(<<229, 10, 32, 32, 32, 32, 116, 101, 115, 116, 32, 34, 102, 111, 111, 34, 44, 32, 100, 111, 58, 32, 97, 115, 115, 101, 114, 116, 32, 34, 97, 34, 32, 61, 61, 32, 34, 229, 34, 10, 101, 110, 100, 10>>, "defmodule FooTester do\n    use ExUnit.Case, async: true\n\n    # ")
    lib/dogma/script.ex:89: Dogma.Script.add_processed_source/1
    lib/dogma/script.ex:47: Dogma.Script.parse/2
    lib/dogma/script_sources.ex:42: anonymous fn/2 in Dogma.ScriptSources.to_scripts/1
    (elixir) lib/enum.ex:1473: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/dogma/script_sources.ex:39: Dogma.ScriptSources.to_scripts/1
    lib/dogma.ex:17: Dogma.run/3
    lib/mix/tasks/dogma.ex:23: Mix.Tasks.Dogma.run/1

This test causes a crash on two points, the comment and the right side of the match. Replace the å with a a and everything works as it should.

defmodule FooTester do
    use ExUnit.Case, async: true

    # å
    test "foo", do: assert "a" == "å"
end

This test does not cause a crash.

defmodule FooTester do
    use ExUnit.Case, async: true

    test "foo", do: assert "a" == "a"
end

The files uses UTF-8 encoding. Erlang and Elixir information:

> iex
Eshell V7.2.1  (abort with ^G)
Interactive Elixir (1.2.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :erlang.system_info(:otp_release)
'18'

Hey! Thanks for the report :)

Could you do me a favour and try this with Dogma master please? I think this may have been fixed.

It works on the master branch. Good work.

Great! I'll release a new version where I can get to a computer.

New version released :)