Skip to content

Commit 96cd7a7

Browse files
committedNov 1, 2024
Add tooling for code quality
1 parent aaaddc3 commit 96cd7a7

10 files changed

+394
-114
lines changed
 

‎.credo.exs

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

‎.formatter.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals_without_parens = [rule: 2, rule?: 2]
22

33
[
4-
inputs: ["{mix,.formatter}.exs", "{lib,test}/**/*.{ex,exs}"],
4+
inputs: ["{mix,.formatter,.credo}.exs", "{lib,test}/**/*.{ex,exs}"],
55
line_length: 135,
66
locals_without_parens: locals_without_parens,
77
export: [

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
_build
2+
deps
3+
doc

‎TODO.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- [x] Merge TokenMatcher and TokenExtractor
21
- Use line info from metada in error reporting
32
- Don't raise, better throw, and convert into a {:error, bla} return value for parse/1
43
- Make the upper behavior optional, using a opt when "using" Grammar module
5-
- [x] Remove nasty IO.inspect() and IO.puts() :)
4+
- Make spaces dropping an optional behaviour
5+
- Split code related to code generation in dedicated modules

0 commit comments

Comments
 (0)