Skip to content

Commit 776ec02

Browse files
committed
Use credo - Elixir linter
1 parent ad8f98d commit 776ec02

File tree

6 files changed

+141
-13
lines changed

6 files changed

+141
-13
lines changed

.credo.exs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
%{
2+
configs: [
3+
%{
4+
name: "default",
5+
files: %{
6+
#
7+
# You can give explicit globs or simply directories.
8+
# In the latter case `**/*.{ex,exs}` will be used.
9+
#
10+
included: ["."],
11+
excluded: [~r"/_build/", ~r"/deps/"]
12+
},
13+
requires: [],
14+
strict: true,
15+
color: true,
16+
checks: [
17+
{Credo.Check.Consistency.ExceptionNames},
18+
{Credo.Check.Consistency.LineEndings},
19+
{Credo.Check.Consistency.ParameterPatternMatching},
20+
{Credo.Check.Consistency.SpaceAroundOperators},
21+
{Credo.Check.Consistency.SpaceInParentheses},
22+
{Credo.Check.Consistency.TabsOrSpaces},
23+
24+
# You can customize the priority of any check
25+
# Priority values are: `low, normal, high, higher`
26+
#
27+
{Credo.Check.Design.AliasUsage, priority: :low},
28+
29+
# For some checks, you can also set other parameters
30+
#
31+
# If you don't want the `setup` and `test` macro calls in ExUnit tests
32+
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
33+
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
34+
#
35+
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},
36+
{Credo.Check.Design.TagTODO, exit_status: 2},
37+
{Credo.Check.Design.TagFIXME},
38+
39+
{Credo.Check.Readability.FunctionNames},
40+
{Credo.Check.Readability.LargeNumbers},
41+
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 80},
42+
{Credo.Check.Readability.ModuleAttributeNames},
43+
{Credo.Check.Readability.ModuleDoc},
44+
{Credo.Check.Readability.ModuleNames},
45+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
46+
{Credo.Check.Readability.ParenthesesInCondition},
47+
{Credo.Check.Readability.PredicateFunctionNames},
48+
{Credo.Check.Readability.PreferImplicitTry},
49+
{Credo.Check.Readability.RedundantBlankLines},
50+
{Credo.Check.Readability.StringSigils},
51+
{Credo.Check.Readability.TrailingBlankLine},
52+
{Credo.Check.Readability.TrailingWhiteSpace},
53+
{Credo.Check.Readability.VariableNames},
54+
{Credo.Check.Readability.Semicolons},
55+
{Credo.Check.Readability.SpaceAfterCommas},
56+
57+
{Credo.Check.Refactor.DoubleBooleanNegation},
58+
{Credo.Check.Refactor.CondStatements},
59+
{Credo.Check.Refactor.CyclomaticComplexity},
60+
{Credo.Check.Refactor.FunctionArity},
61+
{Credo.Check.Refactor.LongQuoteBlocks},
62+
{Credo.Check.Refactor.MatchInCondition},
63+
{Credo.Check.Refactor.NegatedConditionsInUnless},
64+
{Credo.Check.Refactor.NegatedConditionsWithElse},
65+
{Credo.Check.Refactor.Nesting},
66+
{Credo.Check.Refactor.PipeChainStart},
67+
{Credo.Check.Refactor.UnlessWithElse},
68+
69+
{Credo.Check.Warning.BoolOperationOnSameValues},
70+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck},
71+
{Credo.Check.Warning.IExPry},
72+
{Credo.Check.Warning.IoInspect},
73+
{Credo.Check.Warning.LazyLogging},
74+
{Credo.Check.Warning.OperationOnSameValues},
75+
{Credo.Check.Warning.OperationWithConstantResult},
76+
{Credo.Check.Warning.UnusedEnumOperation},
77+
{Credo.Check.Warning.UnusedFileOperation},
78+
{Credo.Check.Warning.UnusedKeywordOperation},
79+
{Credo.Check.Warning.UnusedListOperation},
80+
{Credo.Check.Warning.UnusedPathOperation},
81+
{Credo.Check.Warning.UnusedRegexOperation},
82+
{Credo.Check.Warning.UnusedStringOperation},
83+
{Credo.Check.Warning.UnusedTupleOperation},
84+
{Credo.Check.Warning.RaiseInsideRescue},
85+
86+
# Controversial and experimental checks (opt-in, just remove `, false`)
87+
#
88+
{Credo.Check.Refactor.ABCSize, false},
89+
{Credo.Check.Refactor.AppendSingleItem, false},
90+
{Credo.Check.Refactor.VariableRebinding, false},
91+
{Credo.Check.Warning.MapGetUnsafePass, false},
92+
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
93+
94+
# Deprecated checks (these will be deleted after a grace period)
95+
#
96+
{Credo.Check.Readability.Specs, false},
97+
{Credo.Check.Warning.NameRedeclarationByAssignment, false},
98+
{Credo.Check.Warning.NameRedeclarationByCase, false},
99+
{Credo.Check.Warning.NameRedeclarationByDef, false},
100+
{Credo.Check.Warning.NameRedeclarationByFn, false},
101+
102+
# Custom checks can be created using `mix credo.gen.check`.
103+
#
104+
]
105+
}
106+
]
107+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
deps
2+
_build

01.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ defmodule Puzzle do
1818

1919
defp sum_("", ""), do: 0
2020
defp sum_(string, shifted) do
21-
{ a, rest_string } = String.next_grapheme(string)
22-
{ b, rest_shifted } = String.next_grapheme(shifted)
21+
{a, rest_string} = String.next_grapheme(string)
22+
{b, rest_shifted} = String.next_grapheme(shifted)
2323

2424
inc = if a == b, do: String.to_integer(a), else: 0
2525
inc + sum_(rest_string, rest_shifted)
@@ -128,7 +128,7 @@ if mode == "test" do
128128
end
129129
end
130130
else
131-
data = File.read!("01.txt") |> String.trim_trailing
131+
data = "01.txt" |> File.read! |> String.trim_trailing
132132
sum = Puzzle.sum(data)
133133
sum_mid = Puzzle.sum_mid(data)
134134
IO.puts "The sum is: #{sum}"

02.exs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ defmodule Puzzle do
66
|> String.split("\n", trim: true)
77
|> Enum.map(&minmax/1)
88
|> Enum.map(
9-
fn { nil, nil } -> 0
10-
{ min, max } -> max - min
9+
fn {nil, nil} -> 0
10+
{min, max} -> max - min
1111
end
1212
)
1313
|> Enum.sum
@@ -20,24 +20,24 @@ defmodule Puzzle do
2020
|> String.split("\n", trim: true)
2121
|> Enum.map(&divides/1)
2222
|> Enum.map(
23-
fn [{ nil, nil }] -> 0
24-
[{ divided, divider }] -> div(divided, divider)
23+
fn [{nil, nil}] -> 0
24+
[{divided, divider}] -> div(divided, divider)
2525
end
2626
)
2727
|> Enum.sum
2828
end
2929

30-
defp minmax(""), do: { nil, nil }
30+
defp minmax(""), do: {nil, nil}
3131
defp minmax(row) do
3232
row
3333
|> String.split
3434
|> Enum.map(&String.to_integer/1)
3535
|> Enum.reduce(
36-
{ nil, nil },
36+
{nil, nil},
3737
fn(digit, acc) ->
3838
cond do
3939
is_nil(elem(acc, 0)) ->
40-
{ digit, digit }
40+
{digit, digit}
4141
digit < elem(acc, 0) ->
4242
put_elem(acc, 0, digit)
4343
digit > elem(acc, 1) ->
@@ -49,14 +49,14 @@ defmodule Puzzle do
4949
)
5050
end
5151

52-
defp divides(""), do: { nil, nil }
52+
defp divides(""), do: {nil, nil}
5353
defp divides(row) do
5454
ints = row |> String.split |> Enum.map(&String.to_integer/1)
5555
for a <- ints,
5656
b <- ints,
5757
a > b,
5858
rem(a, b) == 0,
59-
do: { a, b }
59+
do: {a, b}
6060
end
6161
end
6262

@@ -105,7 +105,7 @@ if mode == "test" do
105105
end
106106
end
107107
else
108-
data = File.read!("02.txt") |> String.trim_trailing
108+
data = "02.txt" |> File.read! |> String.trim_trailing
109109
checksum = Puzzle.checksum(data)
110110
checksum_div = Puzzle.checksum_div(data)
111111
IO.puts "The checksum is: #{checksum}"

mix.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule AdventOfCode2017.Mixfile do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :advent_of_code_2017,
7+
version: "1.0.0",
8+
deps: deps()
9+
]
10+
end
11+
12+
defp deps do
13+
[
14+
{:credo, "~> 0.8", only: [:dev, :test], runtime: false}
15+
]
16+
end
17+
end

mix.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [], [], "hexpm"},
2+
"credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"}}

0 commit comments

Comments
 (0)