Skip to content

Commit 5ed2f75

Browse files
committed
Add Localize.Lua: Localize formatting bindings for the Lua (Luerl) VM
0 parents  commit 5ed2f75

20 files changed

Lines changed: 1604 additions & 0 deletions

.credo.exs

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
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+
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+
# Enabled: aliasing nested modules to collapse the namespace
86+
# by the primary level (`Tempo.Foo.Bar` → `Bar`) is the house
87+
# style — it keeps call sites reading as domain verbs rather
88+
# than fully-qualified paths. `excluded_lastnames` keeps names
89+
# that would shadow an Elixir/Erlang built-in — or the `:lua`
90+
# dependency's own `Lua` module — fully qualified (e.g.
91+
# `Localize.Calendar`, `Localize.Lua`): aliasing those to the
92+
# bare name silently captures the stdlib/dependency module.
93+
{Credo.Check.Design.AliasUsage,
94+
[
95+
excluded_lastnames: ~w(
96+
Calendar Inspect Date Time DateTime NaiveDateTime Range Stream
97+
Map List Set Keyword Tuple Atom Integer Float String Process
98+
Task Agent Node Port System IO File Path URI Version Regex
99+
Module Macro Code Enum Access Base Exception Kernel Lua
100+
)
101+
]},
102+
# Disabled: TODO/FIXME work is tracked in TODO.md, the system
103+
# of record — inline tags are intentional pointers, not debt
104+
# for Credo to flag.
105+
{Credo.Check.Design.TagFIXME, false},
106+
{Credo.Check.Design.TagTODO, false},
107+
108+
#
109+
## Readability Checks
110+
#
111+
{Credo.Check.Readability.AliasOrder, []},
112+
{Credo.Check.Readability.FunctionNames, []},
113+
{Credo.Check.Readability.LargeNumbers, []},
114+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
115+
{Credo.Check.Readability.ModuleAttributeNames, []},
116+
{Credo.Check.Readability.ModuleDoc, []},
117+
{Credo.Check.Readability.ModuleNames, []},
118+
{Credo.Check.Readability.ParenthesesInCondition, []},
119+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
120+
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
121+
{Credo.Check.Readability.PredicateFunctionNames, []},
122+
{Credo.Check.Readability.PreferImplicitTry, []},
123+
{Credo.Check.Readability.RedundantBlankLines, []},
124+
{Credo.Check.Readability.Semicolons, []},
125+
{Credo.Check.Readability.SpaceAfterCommas, []},
126+
{Credo.Check.Readability.StringSigils, []},
127+
{Credo.Check.Readability.TrailingBlankLine, []},
128+
{Credo.Check.Readability.TrailingWhiteSpace, []},
129+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
130+
{Credo.Check.Readability.VariableNames, []},
131+
{Credo.Check.Readability.WithSingleClause, []},
132+
133+
#
134+
## Refactoring Opportunities
135+
#
136+
{Credo.Check.Refactor.Apply, []},
137+
{Credo.Check.Refactor.CondStatements, []},
138+
# Default (9). Vocabulary dispatch (Allen relations, cron
139+
# cascade, iteration shapes) is expressed as multi-head
140+
# function clauses rather than one branchy function.
141+
{Credo.Check.Refactor.CyclomaticComplexity, []},
142+
{Credo.Check.Refactor.FilterCount, []},
143+
{Credo.Check.Refactor.FilterFilter, []},
144+
{Credo.Check.Refactor.FunctionArity, []},
145+
{Credo.Check.Refactor.LongQuoteBlocks, []},
146+
{Credo.Check.Refactor.MapJoin, []},
147+
{Credo.Check.Refactor.MatchInCondition, []},
148+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
149+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
150+
# Default depth (2). A `case`/`with` nested inside another
151+
# `with`/`if` is extracted to a multi-head helper rather than
152+
# tolerated — depth 3+ flags.
153+
{Credo.Check.Refactor.Nesting, []},
154+
{Credo.Check.Refactor.RedundantWithClauseResult, []},
155+
{Credo.Check.Refactor.RejectReject, []},
156+
{Credo.Check.Refactor.UnlessWithElse, []},
157+
{Credo.Check.Refactor.WithClauses, []},
158+
159+
#
160+
## Warnings
161+
#
162+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
163+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
164+
{Credo.Check.Warning.Dbg, []},
165+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
166+
{Credo.Check.Warning.IExPry, []},
167+
{Credo.Check.Warning.IoInspect, []},
168+
{Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, []},
169+
{Credo.Check.Warning.OperationOnSameValues, []},
170+
{Credo.Check.Warning.OperationWithConstantResult, []},
171+
{Credo.Check.Warning.RaiseInsideRescue, []},
172+
{Credo.Check.Warning.SpecWithStruct, []},
173+
{Credo.Check.Warning.StructFieldAmount, []},
174+
{Credo.Check.Warning.UnsafeExec, []},
175+
{Credo.Check.Warning.UnusedEnumOperation, []},
176+
{Credo.Check.Warning.UnusedFileOperation, []},
177+
{Credo.Check.Warning.UnusedKeywordOperation, []},
178+
{Credo.Check.Warning.UnusedListOperation, []},
179+
{Credo.Check.Warning.UnusedMapOperation, []},
180+
{Credo.Check.Warning.UnusedPathOperation, []},
181+
{Credo.Check.Warning.UnusedRegexOperation, []},
182+
{Credo.Check.Warning.UnusedStringOperation, []},
183+
{Credo.Check.Warning.UnusedTupleOperation, []},
184+
{Credo.Check.Warning.WrongTestFilename, []}
185+
],
186+
disabled: [
187+
#
188+
# Checks scheduled for next check update (opt-in for now)
189+
{Credo.Check.Refactor.UtcNowTruncate, []},
190+
191+
#
192+
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
193+
# and be sure to use `mix credo --strict` to see low priority checks)
194+
#
195+
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
196+
{Credo.Check.Consistency.UnusedVariableNames, []},
197+
{Credo.Check.Design.DuplicatedCode, []},
198+
{Credo.Check.Design.SkipTestWithoutComment, []},
199+
{Credo.Check.Readability.AliasAs, []},
200+
{Credo.Check.Readability.BlockPipe, []},
201+
{Credo.Check.Readability.ImplTrue, []},
202+
{Credo.Check.Readability.MultiAlias, []},
203+
{Credo.Check.Readability.NestedFunctionCalls, []},
204+
{Credo.Check.Readability.OneArityFunctionInPipe, []},
205+
{Credo.Check.Readability.OnePipePerLine, []},
206+
{Credo.Check.Readability.SeparateAliasRequire, []},
207+
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
208+
{Credo.Check.Readability.SinglePipe, []},
209+
{Credo.Check.Readability.Specs, []},
210+
{Credo.Check.Readability.StrictModuleLayout, []},
211+
{Credo.Check.Readability.WithCustomTaggedTuple, []},
212+
{Credo.Check.Refactor.ABCSize, []},
213+
{Credo.Check.Refactor.AppendSingleItem, []},
214+
{Credo.Check.Refactor.CondInsteadOfIfElse, []},
215+
{Credo.Check.Refactor.DoubleBooleanNegation, []},
216+
{Credo.Check.Refactor.FilterReject, []},
217+
{Credo.Check.Refactor.IoPuts, []},
218+
{Credo.Check.Refactor.MapMap, []},
219+
{Credo.Check.Refactor.ModuleDependencies, []},
220+
{Credo.Check.Refactor.NegatedIsNil, []},
221+
{Credo.Check.Refactor.PassAsyncInTestCases, []},
222+
{Credo.Check.Refactor.PipeChainStart, []},
223+
{Credo.Check.Refactor.RejectFilter, []},
224+
{Credo.Check.Refactor.VariableRebinding, []},
225+
{Credo.Check.Warning.LazyLogging, []},
226+
{Credo.Check.Warning.LeakyEnvironment, []},
227+
{Credo.Check.Warning.MapGetUnsafePass, []},
228+
{Credo.Check.Warning.MixEnv, []},
229+
{Credo.Check.Warning.UnsafeToAtom, []}
230+
# {Credo.Check.Warning.UnusedOperation, [{MyMagicModule, [:fun1, :fun2]}]}
231+
232+
# {Credo.Check.Refactor.MapInto, []},
233+
234+
#
235+
# Custom checks can be created using `mix credo.gen.check`.
236+
#
237+
]
238+
}
239+
}
240+
]
241+
}

.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

.githooks/pre-commit

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
#
3+
# LocalizeLua pre-commit hook.
4+
#
5+
# Runs `mix format` on every staged `.ex` / `.exs` / `.heex` file so
6+
# that CI's `mix format --check-formatted` cannot fail on a freshly-
7+
# committed file. Re-stages each formatted file in-place so the
8+
# commit you wrote is the commit that lands.
9+
#
10+
# Lives under .githooks/ (committed to the repo, not under .git/hooks/
11+
# which is local-only). Activate with:
12+
#
13+
# git config core.hooksPath .githooks
14+
#
15+
16+
set -eu
17+
18+
# Collect staged Elixir files (added, copied, modified — not deleted).
19+
# Avoid `mapfile` so this works on macOS's stock bash 3.2.
20+
staged="$(
21+
git diff --cached --name-only --diff-filter=ACM \
22+
| grep -E '\.(ex|exs|heex)$' || true
23+
)"
24+
25+
if [ -z "$staged" ]; then
26+
exit 0
27+
fi
28+
29+
# Skip files that no longer exist on disk (e.g. renamed away after
30+
# staging) and accumulate the ones we can format.
31+
to_format=""
32+
while IFS= read -r f; do
33+
if [ -f "$f" ]; then
34+
to_format="$to_format $f"
35+
fi
36+
done <<EOF
37+
$staged
38+
EOF
39+
40+
# Trim leading whitespace; bail if nothing's left.
41+
to_format="${to_format# }"
42+
if [ -z "$to_format" ]; then
43+
exit 0
44+
fi
45+
46+
# Format the files in place. Word-splitting on `to_format` is
47+
# intentional — the file list is space-separated.
48+
# shellcheck disable=SC2086
49+
mix format $to_format
50+
51+
# Re-stage anything `mix format` actually changed. `git add` is a
52+
# no-op for files that didn't change, so this is safe to call on
53+
# every file in the list.
54+
# shellcheck disable=SC2086
55+
git add $to_format

0 commit comments

Comments
 (0)