Add credo to the project and:

- Run mix credo --all to identify possible code optimizations
 - Resolve most of the errors generated by credo such as:
   - Numbers larger than 9999 should be written with underscores: 58_127
   - Modules should have a @moduledoc tag
   - Comparison will always return true
This commit is contained in:
Ahmed Ismail
2023-11-10 00:57:21 +05:00
parent 2ca2eeeb20
commit edf50fdf80
44 changed files with 107 additions and 45 deletions

View File

@@ -19,7 +19,7 @@ defmodule BlanksTest do
end
test "multiple arguments" do
ast = quote do: assert(___ == ___)
ast = quote do: assert true == false
assert Blanks.replace(ast, [true, false]) == quote(do: assert(true == false))
end
@@ -43,7 +43,7 @@ defmodule BlanksTest do
end
test "counts multiple blanks" do
ast = quote do: assert(___ == ___)
ast = quote do: assert ___ == ___
assert Blanks.count(ast) == 2
end

View File

@@ -39,7 +39,7 @@ defmodule FailureTests do
test "only offending lines are displayed for errors" do
[koan] = SingleArity.all_koans()
error = apply(SingleArity, koan, []) |> Tuple.to_list |> List.last |> error
error = apply(SingleArity, koan, []) |> Tuple.to_list() |> List.last() |> error
assert Failure.format_failure(error) == """
Assertion failed in some_file.ex:42\nmatch?(:foo, ___)

View File

@@ -8,7 +8,7 @@ defmodule ExecuteTest do
test "stops at the first failing koan" do
{:failed, %{file: file, line: line}, SampleKoan, _name} = Execute.run_module(SampleKoan)
assert file == 'test/support/sample_koan.ex'
assert line == 8
assert line == 9
end
test "can access intro" do

View File

@@ -1,18 +1,17 @@
defmodule ComprehensionsTests do
use ExUnit.Case
import TestHarness
test "Comprehensions" do
answers = [
[1, 4, 9, 16],
[1, 4, 9, 16],
["Hello World", "Apple Pie"],
["little dogs", "little cats", "big dogs", "big cats"],
[4, 5, 6],
%{"Pecan" => "Pecan Pie", "Pumpkin" => "Pumpkin Pie"}
]
test_all(Comprehensions, answers)
end
end
defmodule ComprehensionsTests do
use ExUnit.Case
import TestHarness
test "Comprehensions" do
answers = [
[1, 4, 9, 16],
[1, 4, 9, 16],
["Hello World", "Apple Pie"],
["little dogs", "little cats", "big dogs", "big cats"],
[4, 5, 6],
%{"Pecan" => "Pecan Pie", "Pumpkin" => "Pumpkin Pie"}
]
test_all(Comprehensions, answers)
end
end

View File

@@ -1,4 +1,5 @@
defmodule PassingKoan do
@moduledoc false
use Koans
@intro "something"

View File

@@ -1,4 +1,5 @@
defmodule SampleKoan do
@moduledoc false
use Koans
@intro """

View File

@@ -1,4 +1,5 @@
defmodule SingleArity do
@moduledoc false
use Koans
@intro """

View File

@@ -1,4 +1,5 @@
timeout = 1000 # ms
# ms
timeout = 1000
ExUnit.start(timeout: timeout)
defmodule TestHarness do