Skip to content

Commit cb4165b

Browse files
authored
Lint Main File (#9)
I just realized that the main file and its test are included in Credo's ignore list. This fixes that oversight by removing the affected files from the ignore list and fixing all of the errors mentioned by Credo.
1 parent b8f3ddd commit cb4165b

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

.credo.exs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
excluded: [
2929
~r"/_build/",
3030
~r"/deps/",
31-
~r"/lib/diff_check.ex",
32-
~r"/test/support",
33-
~r"/test/diff_check_test.exs"
31+
~r"/test/support"
3432
]
3533
},
3634
#

lib/diff_check.ex

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
defmodule DiffCheck do
2+
@moduledoc """
3+
DiffCheck is a command-line tool that compares two files and prints the
4+
differences between them.
5+
6+
The way this works is that it builds a 2D matrix of the two files by
7+
computing for the longest subsequence between each files. It then prints
8+
the differences between the two files by backtracking through the matrix.
9+
10+
The LCS implementation used is based on this Wikipedia article:
11+
12+
https://en.wikipedia.org/wiki/Longest_common_subsequence
13+
"""
14+
215
alias DiffCheck.BuildMatrix
316
alias DiffCheck.PrintDiff
417

18+
@spec main(args :: [String.t()], disable_printing :: boolean) :: :ok | {:error, String.t()}
519
def main(args, disable_printing \\ false) do
620
case validate_args(args) do
721
:ok ->
822
[file1_path, file2_path] = args
923

10-
file1 = File.read!(file1_path) |> String.split("\n")
11-
file2 = File.read!(file2_path) |> String.split("\n")
24+
file1 = stringify_file(file1_path)
25+
file2 = stringify_file(file2_path)
1226

1327
file1
1428
|> BuildMatrix.call(file2)
@@ -46,4 +60,10 @@ defmodule DiffCheck do
4660

4761
:ok
4862
end
63+
64+
defp stringify_file(file_path) do
65+
file_path
66+
|> File.read!()
67+
|> String.split("\n")
68+
end
4969
end

test/diff_check_test.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
defmodule DiffCheckTest do
2-
use ExUnit.Case
3-
doctest DiffCheck
2+
use ExUnit.Case, async: true
43

54
test "works with valid arguments" do
65
file1 = Path.expand("support/fixtures/test_response_1.json", __DIR__)

0 commit comments

Comments
 (0)