Skip to content

Commit e2284f5

Browse files
authored
Add Credo, CI and some documentation (#5)
Adds some improvements for code quality and CI: * Credo: now checks for suggested changes and problems * GitHub Actions: a new pipeline checks code formatting, warnings, credo and tests * Some documenttation on several modules * Remove unused module * Rename models folder to be schemas
1 parent 8a06473 commit e2284f5

17 files changed

Lines changed: 456 additions & 40 deletions

File tree

.credo.exs

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# This file contains the configuration for Credo and you are probably reading
2+
# this after creating it with `mix credo.gen.config`.
3+
#
4+
# If you find anything wrong or unclear in this file, please report an
5+
# issue on GitHub: https://github.com/rrrene/credo/issues
6+
#
7+
%{
8+
#
9+
# You can have as many configs as you like in the `configs:` field.
10+
configs: [
11+
%{
12+
#
13+
# Run any config using `mix credo -C <name>`. If no config name is given
14+
# "default" is used.
15+
#
16+
name: "default",
17+
#
18+
# These are the files included in the analysis:
19+
files: %{
20+
#
21+
# You can give explicit globs or simply directories.
22+
# In the latter case `**/*.{ex,exs}` will be used.
23+
#
24+
included: [
25+
"lib/",
26+
"src/",
27+
"test/",
28+
"web/",
29+
"apps/*/lib/",
30+
"apps/*/src/",
31+
"apps/*/test/",
32+
"apps/*/web/"
33+
],
34+
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
35+
},
36+
#
37+
# Load and configure plugins here:
38+
#
39+
plugins: [],
40+
#
41+
# If you create your own checks, you must specify the source files for
42+
# them here, so they can be loaded by Credo before running the analysis.
43+
#
44+
requires: [],
45+
#
46+
# If you want to enforce a style guide and need a more traditional linting
47+
# experience, you can change `strict` to `true` below:
48+
#
49+
strict: true,
50+
#
51+
# To modify the timeout for parsing files, change this value:
52+
#
53+
parse_timeout: 5000,
54+
#
55+
# If you want to use uncolored output by default, you can change `color`
56+
# to `false` below:
57+
#
58+
color: true,
59+
#
60+
# You can customize the parameters of any check by adding a second element
61+
# to the tuple.
62+
#
63+
# To disable a check put `false` as second element:
64+
#
65+
# {Credo.Check.Design.DuplicatedCode, false}
66+
#
67+
checks: %{
68+
enabled: [
69+
#
70+
## Consistency Checks
71+
#
72+
{Credo.Check.Consistency.ExceptionNames, []},
73+
{Credo.Check.Consistency.LineEndings, []},
74+
{Credo.Check.Consistency.ParameterPatternMatching, []},
75+
{Credo.Check.Consistency.SpaceAroundOperators, []},
76+
{Credo.Check.Consistency.SpaceInParentheses, []},
77+
{Credo.Check.Consistency.TabsOrSpaces, []},
78+
79+
#
80+
## Design Checks
81+
#
82+
# You can customize the priority of any check
83+
# Priority values are: `low, normal, high, higher`
84+
#
85+
{Credo.Check.Design.AliasUsage,
86+
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 3]},
87+
{Credo.Check.Design.TagFIXME, []},
88+
# You can also customize the exit_status of each check.
89+
# If you don't want TODO comments to cause `mix credo` to fail, just
90+
# set this value to 0 (zero).
91+
#
92+
{Credo.Check.Design.TagTODO, [exit_status: 2]},
93+
94+
#
95+
## Readability Checks
96+
#
97+
{Credo.Check.Readability.AliasOrder, []},
98+
{Credo.Check.Readability.FunctionNames, []},
99+
{Credo.Check.Readability.LargeNumbers, []},
100+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
101+
{Credo.Check.Readability.ModuleAttributeNames, []},
102+
{Credo.Check.Readability.ModuleDoc, []},
103+
{Credo.Check.Readability.ModuleNames, []},
104+
{Credo.Check.Readability.ParenthesesInCondition, []},
105+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
106+
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
107+
{Credo.Check.Readability.PredicateFunctionNames, []},
108+
{Credo.Check.Readability.PreferImplicitTry, []},
109+
{Credo.Check.Readability.RedundantBlankLines, []},
110+
{Credo.Check.Readability.Semicolons, []},
111+
{Credo.Check.Readability.SpaceAfterCommas, []},
112+
{Credo.Check.Readability.StringSigils, []},
113+
{Credo.Check.Readability.TrailingBlankLine, []},
114+
{Credo.Check.Readability.TrailingWhiteSpace, []},
115+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
116+
{Credo.Check.Readability.VariableNames, []},
117+
{Credo.Check.Readability.WithSingleClause, []},
118+
119+
#
120+
## Refactoring Opportunities
121+
#
122+
{Credo.Check.Refactor.Apply, []},
123+
{Credo.Check.Refactor.CondStatements, []},
124+
{Credo.Check.Refactor.CyclomaticComplexity, []},
125+
{Credo.Check.Refactor.FilterCount, []},
126+
{Credo.Check.Refactor.FilterFilter, []},
127+
{Credo.Check.Refactor.FunctionArity, []},
128+
{Credo.Check.Refactor.LongQuoteBlocks, []},
129+
{Credo.Check.Refactor.MapJoin, []},
130+
{Credo.Check.Refactor.MatchInCondition, []},
131+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
132+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
133+
{Credo.Check.Refactor.Nesting, []},
134+
{Credo.Check.Refactor.RedundantWithClauseResult, []},
135+
{Credo.Check.Refactor.RejectReject, []},
136+
{Credo.Check.Refactor.UnlessWithElse, []},
137+
{Credo.Check.Refactor.WithClauses, []},
138+
139+
#
140+
## Warnings
141+
#
142+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
143+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
144+
{Credo.Check.Warning.Dbg, []},
145+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
146+
{Credo.Check.Warning.IExPry, []},
147+
{Credo.Check.Warning.IoInspect, []},
148+
{Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, []},
149+
{Credo.Check.Warning.OperationOnSameValues, []},
150+
{Credo.Check.Warning.OperationWithConstantResult, []},
151+
{Credo.Check.Warning.RaiseInsideRescue, []},
152+
{Credo.Check.Warning.SpecWithStruct, []},
153+
{Credo.Check.Warning.UnsafeExec, []},
154+
{Credo.Check.Warning.UnusedEnumOperation, []},
155+
{Credo.Check.Warning.UnusedFileOperation, []},
156+
{Credo.Check.Warning.UnusedKeywordOperation, []},
157+
{Credo.Check.Warning.UnusedListOperation, []},
158+
{Credo.Check.Warning.UnusedPathOperation, []},
159+
{Credo.Check.Warning.UnusedRegexOperation, []},
160+
{Credo.Check.Warning.UnusedStringOperation, []},
161+
{Credo.Check.Warning.UnusedTupleOperation, []},
162+
{Credo.Check.Warning.WrongTestFileExtension, []}
163+
],
164+
disabled: [
165+
#
166+
# Checks scheduled for next check update (opt-in for now)
167+
{Credo.Check.Refactor.UtcNowTruncate, []},
168+
169+
#
170+
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
171+
# and be sure to use `mix credo --strict` to see low priority checks)
172+
#
173+
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
174+
{Credo.Check.Consistency.UnusedVariableNames, []},
175+
{Credo.Check.Design.DuplicatedCode, []},
176+
{Credo.Check.Design.SkipTestWithoutComment, []},
177+
{Credo.Check.Readability.AliasAs, []},
178+
{Credo.Check.Readability.BlockPipe, []},
179+
{Credo.Check.Readability.ImplTrue, []},
180+
{Credo.Check.Readability.MultiAlias, []},
181+
{Credo.Check.Readability.NestedFunctionCalls, []},
182+
{Credo.Check.Readability.OneArityFunctionInPipe, []},
183+
{Credo.Check.Readability.OnePipePerLine, []},
184+
{Credo.Check.Readability.SeparateAliasRequire, []},
185+
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
186+
{Credo.Check.Readability.SinglePipe, []},
187+
{Credo.Check.Readability.Specs, []},
188+
{Credo.Check.Readability.StrictModuleLayout, []},
189+
{Credo.Check.Readability.WithCustomTaggedTuple, []},
190+
{Credo.Check.Refactor.ABCSize, []},
191+
{Credo.Check.Refactor.AppendSingleItem, []},
192+
{Credo.Check.Refactor.DoubleBooleanNegation, []},
193+
{Credo.Check.Refactor.FilterReject, []},
194+
{Credo.Check.Refactor.IoPuts, []},
195+
{Credo.Check.Refactor.MapMap, []},
196+
{Credo.Check.Refactor.ModuleDependencies, []},
197+
{Credo.Check.Refactor.NegatedIsNil, []},
198+
{Credo.Check.Refactor.PassAsyncInTestCases, []},
199+
{Credo.Check.Refactor.PipeChainStart, []},
200+
{Credo.Check.Refactor.RejectFilter, []},
201+
{Credo.Check.Refactor.VariableRebinding, []},
202+
{Credo.Check.Warning.LazyLogging, []},
203+
{Credo.Check.Warning.LeakyEnvironment, []},
204+
{Credo.Check.Warning.MapGetUnsafePass, []},
205+
{Credo.Check.Warning.MixEnv, []},
206+
{Credo.Check.Warning.UnsafeToAtom, []}
207+
208+
# {Credo.Check.Refactor.MapInto, []},
209+
210+
#
211+
# Custom checks can be created using `mix credo.gen.check`.
212+
#
213+
]
214+
}
215+
}
216+
]
217+
}

.github/workflows/elixir.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: code-analysis
2+
on: push
3+
env:
4+
MIX_ENV: test
5+
ERLANG_VERSION: 26.0.2
6+
ELIXIR_VERSION: 1.16.0
7+
8+
jobs:
9+
compile_deps:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: erlef/setup-beam@v1
14+
with:
15+
otp-version: ${{ env.ERLANG_VERSION }}
16+
elixir-version: ${{ env.ELIXIR_VERSION }}
17+
- name: Retrieve Dependencies Cache
18+
uses: actions/cache@v2
19+
id: mix-cache
20+
with:
21+
path: |
22+
deps
23+
_build
24+
key: ${{ runner.os }}-${{ env.ERLANG_VERSION }}-${{ env.ELIXIR_VERSION }}-mix-${{ hashFiles('**/mix.lock') }}
25+
- name: Install Mix Dependencies
26+
run: |
27+
mix local.rebar --force
28+
mix local.hex --force
29+
mix deps.get
30+
- name: Compile dependencies
31+
run: mix deps.compile
32+
33+
check_format:
34+
needs: [compile_deps]
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v2
38+
- uses: erlef/setup-beam@v1
39+
with:
40+
otp-version: ${{ env.ERLANG_VERSION }}
41+
elixir-version: ${{ env.ELIXIR_VERSION }}
42+
- name: Retrieve Dependencies Cache
43+
uses: actions/cache@v2
44+
id: mix-cache
45+
with:
46+
path: |
47+
deps
48+
_build
49+
key: ${{ runner.os }}-${{ env.ERLANG_VERSION }}-${{ env.ELIXIR_VERSION }}-mix-${{ hashFiles('**/mix.lock') }}
50+
- run: mix format --check-formatted
51+
52+
check_warnings:
53+
needs: [compile_deps]
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v2
57+
- uses: erlef/setup-beam@v1
58+
with:
59+
otp-version: ${{ env.ERLANG_VERSION }}
60+
elixir-version: ${{ env.ELIXIR_VERSION }}
61+
- name: Retrieve Mix Dependencies Cache
62+
uses: actions/cache@v2
63+
id: mix-cache
64+
with:
65+
path: |
66+
deps
67+
_build
68+
key: ${{ runner.os }}-${{ env.ERLANG_VERSION }}-${{ env.ELIXIR_VERSION }}-mix-${{ hashFiles('**/mix.lock') }}
69+
- name: Check application compile warnings
70+
run: mix compile --force --warnings-as-errors
71+
72+
check_credo:
73+
needs: [compile_deps]
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v2
77+
- uses: erlef/setup-beam@v1
78+
with:
79+
otp-version: ${{ env.ERLANG_VERSION }}
80+
elixir-version: ${{ env.ELIXIR_VERSION }}
81+
- name: Retrieve Mix Dependencies Cache
82+
uses: actions/cache@v2
83+
id: mix-cache
84+
with:
85+
path: |
86+
deps
87+
_build
88+
key: ${{ runner.os }}-${{ env.ERLANG_VERSION }}-${{ env.ELIXIR_VERSION }}-mix-${{ hashFiles('**/mix.lock') }}
89+
- name: Check Credo warnings
90+
run: mix credo
91+
92+
run_tests:
93+
needs: [compile_deps]
94+
runs-on: ubuntu-latest
95+
services:
96+
db:
97+
image: postgres:11
98+
ports: ["5432:5432"]
99+
env:
100+
POSTGRES_PASSWORD: postgres
101+
options: >-
102+
--health-cmd pg_isready
103+
--health-interval 10s
104+
--health-timeout 5s
105+
--health-retries 5
106+
steps:
107+
- uses: actions/checkout@v2
108+
- uses: erlef/setup-beam@v1
109+
with:
110+
otp-version: ${{ env.ERLANG_VERSION }}
111+
elixir-version: ${{ env.ELIXIR_VERSION }}
112+
- name: Retrieve Mix Dependencies Cache
113+
uses: actions/cache@v2
114+
id: mix-cache
115+
with:
116+
path: |
117+
deps
118+
_build
119+
key: ${{ runner.os }}-${{ env.ERLANG_VERSION }}-${{ env.ELIXIR_VERSION }}-mix-${{ hashFiles('**/mix.lock') }}
120+
- name: Run Tests
121+
run: mix test

config/config.exs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Config
22

3-
config :tailwind,
4-
version: "3.4.3",
5-
default: [
6-
args: ~w(
7-
--config=tailwind.config.js
8-
--input=css/app.css
9-
--output=../priv/static/assets/app.css
10-
),
11-
cd: Path.expand("../assets", __DIR__)
12-
]
3+
if config_env() == :dev do
4+
config :tailwind,
5+
version: "3.4.3",
6+
default: [
7+
args: ~w(
8+
--config=tailwind.config.js
9+
--input=css/app.css
10+
--output=../priv/static/assets/app.css
11+
),
12+
cd: Path.expand("../assets", __DIR__)
13+
]
14+
end

lib/error_tracker.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
defmodule ErrorTracker do
2+
@moduledoc """
3+
En Elixir based built-in error tracking solution.
4+
"""
5+
26
def report(exception, stacktrace, context \\ %{}) do
37
{:ok, stacktrace} = ErrorTracker.Stacktrace.new(stacktrace)
48
{:ok, error} = ErrorTracker.Error.new(exception, stacktrace)

lib/error_tracker/application.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule ErrorTracker.Application do
2+
@moduledoc false
3+
24
use Application
35

46
def start(_type, _args) do

lib/error_tracker/integrations/oban.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
defmodule ErrorTracker.Integrations.Oban do
2+
@moduledoc """
3+
The ErrorTracker integration with Oban.
4+
5+
## How it works
6+
7+
It works using your application's Telemetry events, so you don't need to
8+
modify anything on your application.
9+
"""
10+
211
def attach do
312
if Application.spec(:oban) do
413
:telemetry.attach(__MODULE__, [:oban, :job, :exception], &handle_event/4, :no_config)

0 commit comments

Comments
 (0)