Skip to content

Commit 07a2ce5

Browse files
committed
support pre-commit hook and github workflow
1 parent bdcb2d8 commit 07a2ce5

File tree

5 files changed

+247
-1
lines changed

5 files changed

+247
-1
lines changed

.credo.exs

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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: false,
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+
#
69+
## Consistency Checks
70+
#
71+
{Credo.Check.Consistency.ExceptionNames, []},
72+
{Credo.Check.Consistency.LineEndings, []},
73+
{Credo.Check.Consistency.ParameterPatternMatching, []},
74+
{Credo.Check.Consistency.SpaceAroundOperators, []},
75+
{Credo.Check.Consistency.SpaceInParentheses, []},
76+
{Credo.Check.Consistency.TabsOrSpaces, []},
77+
78+
#
79+
## Design Checks
80+
#
81+
# You can customize the priority of any check
82+
# Priority values are: `low, normal, high, higher`
83+
#
84+
{Credo.Check.Design.AliasUsage,
85+
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
86+
# You can also customize the exit_status of each check.
87+
# If you don't want TODO comments to cause `mix credo` to fail, just
88+
# set this value to 0 (zero).
89+
#
90+
{Credo.Check.Design.TagTODO, [exit_status: 2]},
91+
{Credo.Check.Design.TagFIXME, []},
92+
93+
#
94+
## Readability Checks
95+
#
96+
{Credo.Check.Readability.AliasOrder, []},
97+
{Credo.Check.Readability.FunctionNames, []},
98+
{Credo.Check.Readability.LargeNumbers, []},
99+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
100+
{Credo.Check.Readability.ModuleAttributeNames, []},
101+
{Credo.Check.Readability.ModuleDoc, []},
102+
{Credo.Check.Readability.ModuleNames, []},
103+
{Credo.Check.Readability.ParenthesesInCondition, []},
104+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
105+
{Credo.Check.Readability.PredicateFunctionNames, []},
106+
{Credo.Check.Readability.PreferImplicitTry, []},
107+
{Credo.Check.Readability.RedundantBlankLines, []},
108+
{Credo.Check.Readability.Semicolons, []},
109+
{Credo.Check.Readability.SpaceAfterCommas, []},
110+
{Credo.Check.Readability.StringSigils, []},
111+
{Credo.Check.Readability.TrailingBlankLine, []},
112+
{Credo.Check.Readability.TrailingWhiteSpace, []},
113+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
114+
{Credo.Check.Readability.VariableNames, []},
115+
116+
#
117+
## Refactoring Opportunities
118+
#
119+
{Credo.Check.Refactor.CondStatements, []},
120+
{Credo.Check.Refactor.CyclomaticComplexity, []},
121+
{Credo.Check.Refactor.FunctionArity, []},
122+
{Credo.Check.Refactor.LongQuoteBlocks, []},
123+
# {Credo.Check.Refactor.MapInto, []},
124+
{Credo.Check.Refactor.MatchInCondition, []},
125+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
126+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
127+
{Credo.Check.Refactor.Nesting, []},
128+
{Credo.Check.Refactor.UnlessWithElse, []},
129+
{Credo.Check.Refactor.WithClauses, []},
130+
131+
#
132+
## Warnings
133+
#
134+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
135+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
136+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
137+
{Credo.Check.Warning.IExPry, []},
138+
{Credo.Check.Warning.IoInspect, []},
139+
# {Credo.Check.Warning.LazyLogging, []},
140+
{Credo.Check.Warning.MixEnv, false},
141+
{Credo.Check.Warning.OperationOnSameValues, []},
142+
{Credo.Check.Warning.OperationWithConstantResult, []},
143+
{Credo.Check.Warning.RaiseInsideRescue, []},
144+
{Credo.Check.Warning.UnusedEnumOperation, []},
145+
{Credo.Check.Warning.UnusedFileOperation, []},
146+
{Credo.Check.Warning.UnusedKeywordOperation, []},
147+
{Credo.Check.Warning.UnusedListOperation, []},
148+
{Credo.Check.Warning.UnusedPathOperation, []},
149+
{Credo.Check.Warning.UnusedRegexOperation, []},
150+
{Credo.Check.Warning.UnusedStringOperation, []},
151+
{Credo.Check.Warning.UnusedTupleOperation, []},
152+
{Credo.Check.Warning.UnsafeExec, []},
153+
154+
#
155+
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)
156+
157+
#
158+
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
159+
#
160+
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
161+
{Credo.Check.Consistency.UnusedVariableNames, false},
162+
{Credo.Check.Design.DuplicatedCode, false},
163+
{Credo.Check.Readability.AliasAs, false},
164+
{Credo.Check.Readability.BlockPipe, false},
165+
{Credo.Check.Readability.ImplTrue, false},
166+
{Credo.Check.Readability.MultiAlias, false},
167+
{Credo.Check.Readability.SeparateAliasRequire, false},
168+
{Credo.Check.Readability.SinglePipe, false},
169+
{Credo.Check.Readability.Specs, false},
170+
{Credo.Check.Readability.StrictModuleLayout, false},
171+
{Credo.Check.Readability.WithCustomTaggedTuple, false},
172+
{Credo.Check.Refactor.ABCSize, false},
173+
{Credo.Check.Refactor.AppendSingleItem, false},
174+
{Credo.Check.Refactor.DoubleBooleanNegation, false},
175+
{Credo.Check.Refactor.ModuleDependencies, false},
176+
{Credo.Check.Refactor.NegatedIsNil, false},
177+
{Credo.Check.Refactor.PipeChainStart, false},
178+
{Credo.Check.Refactor.VariableRebinding, false},
179+
{Credo.Check.Warning.LeakyEnvironment, false},
180+
{Credo.Check.Warning.MapGetUnsafePass, false},
181+
{Credo.Check.Warning.UnsafeToAtom, false}
182+
183+
#
184+
# Custom checks can be created using `mix credo.gen.check`.
185+
#
186+
]
187+
}
188+
]
189+
}

.github/workflows/build.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on: push
2+
3+
name: build
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
9+
strategy:
10+
matrix:
11+
otp: [23]
12+
elixir: [1.10, 1.11]
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-elixir@v1
16+
with:
17+
otp-version: ${{matrix.otp}}
18+
elixir-version: ${{matrix.elixir}}
19+
- run: mix deps.get
20+
- run: mix test

.pre-commit-config.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.4.0
4+
hooks:
5+
- id: check-byte-order-marker
6+
- id: check-case-conflict
7+
- id: check-merge-conflict
8+
- id: check-symlinks
9+
- id: check-yaml
10+
- id: end-of-file-fixer
11+
- id: mixed-line-ending
12+
- id: trailing-whitespace
13+
- repo: https://github.com/psf/black
14+
rev: 19.3b0
15+
hooks:
16+
- id: black
17+
- repo: local
18+
hooks:
19+
- id: mix-fmt
20+
name: mix format
21+
description: Format files with mix.
22+
entry: mix format
23+
language: node
24+
files: \.exs{0,1}$
25+
pass_filenames: false
26+
- id: mix-credo
27+
name: mix credo
28+
description: Check the package for errors.
29+
entry: mix credo
30+
language: node
31+
files: \.exs{0,1}$
32+
pass_filenames: false

mix.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ defmodule JsonDataFaker.MixProject do
4141
{:uuid, "~> 1.1"},
4242

4343
# dev/test deps
44-
{:ex_doc, "~> 0.23", only: :dev, runtime: false}
44+
{:ex_doc, "~> 0.23", only: :dev, runtime: false},
45+
{:credo, "~> 1.5", only: [:dev, :test]}
4546
]
4647
end
4748

mix.lock

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
%{
2+
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
3+
"credo": {:hex, :credo, "1.5.1", "4fe303cc828412b9d21eed4eab60914c401e71f117f40243266aafb66f30d036", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "0b219ca4dcc89e4e7bc6ae7e6539c313e738e192e10b85275fa1e82b5203ecd7"},
24
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
35
"ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
46
"ex_json_schema": {:hex, :ex_json_schema, "0.7.4", "09eb5b0c8184e5702bc89625a9d0c05c7a0a845d382e9f6f406a0fc1c9a8cc3f", [:mix], [], "hexpm", "45c67fa840f0d719a2b5578126dc29bcdc1f92499c0f61bcb8a3bcb5935f9684"},
57
"faker": {:hex, :faker, "0.16.0", "1e2cf3e8d60d44a30741fb98118fcac18b2020379c7e00d18f1a005841b2f647", [:mix], [], "hexpm", "fbcb9bf1299dff3c9dd7e50f41802bbc472ffbb84e7656394c8aa913ec315141"},
8+
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
9+
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
610
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
711
"makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"},
812
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},

0 commit comments

Comments
 (0)