Skip to content

Commit c34a522

Browse files
committed
🚀 Refacto + upgrade to Elixir 1.19
1 parent e883256 commit c34a522

13 files changed

Lines changed: 745 additions & 375 deletions

File tree

.credo.exs

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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: 0]},
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.PipeIntoAnonymousFunctions, []},
106+
{Credo.Check.Readability.PredicateFunctionNames, []},
107+
{Credo.Check.Readability.PreferImplicitTry, []},
108+
{Credo.Check.Readability.RedundantBlankLines, []},
109+
{Credo.Check.Readability.Semicolons, []},
110+
{Credo.Check.Readability.SpaceAfterCommas, []},
111+
{Credo.Check.Readability.StringSigils, []},
112+
{Credo.Check.Readability.TrailingBlankLine, []},
113+
{Credo.Check.Readability.TrailingWhiteSpace, []},
114+
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
115+
{Credo.Check.Readability.VariableNames, []},
116+
{Credo.Check.Readability.WithSingleClause, []},
117+
118+
#
119+
## Refactoring Opportunities
120+
#
121+
{Credo.Check.Refactor.Apply, []},
122+
{Credo.Check.Refactor.CondStatements, []},
123+
{Credo.Check.Refactor.CyclomaticComplexity, []},
124+
{Credo.Check.Refactor.FilterCount, []},
125+
{Credo.Check.Refactor.FilterFilter, []},
126+
{Credo.Check.Refactor.FunctionArity, []},
127+
{Credo.Check.Refactor.LongQuoteBlocks, []},
128+
{Credo.Check.Refactor.MapJoin, []},
129+
{Credo.Check.Refactor.MatchInCondition, []},
130+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
131+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
132+
{Credo.Check.Refactor.Nesting, []},
133+
{Credo.Check.Refactor.RedundantWithClauseResult, []},
134+
{Credo.Check.Refactor.RejectReject, []},
135+
{Credo.Check.Refactor.UnlessWithElse, []},
136+
{Credo.Check.Refactor.WithClauses, []},
137+
138+
#
139+
## Warnings
140+
#
141+
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
142+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
143+
{Credo.Check.Warning.Dbg, []},
144+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
145+
{Credo.Check.Warning.IExPry, []},
146+
{Credo.Check.Warning.IoInspect, []},
147+
{Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, []},
148+
{Credo.Check.Warning.OperationOnSameValues, []},
149+
{Credo.Check.Warning.OperationWithConstantResult, []},
150+
{Credo.Check.Warning.RaiseInsideRescue, []},
151+
{Credo.Check.Warning.SpecWithStruct, []},
152+
{Credo.Check.Warning.StructFieldAmount, []},
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.UnusedMapOperation, []},
159+
{Credo.Check.Warning.UnusedPathOperation, []},
160+
{Credo.Check.Warning.UnusedRegexOperation, []},
161+
{Credo.Check.Warning.UnusedStringOperation, []},
162+
{Credo.Check.Warning.UnusedTupleOperation, []},
163+
{Credo.Check.Warning.WrongTestFilename, []}
164+
],
165+
disabled: [
166+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
167+
168+
#
169+
# Checks scheduled for next check update (opt-in for now)
170+
{Credo.Check.Refactor.UtcNowTruncate, []},
171+
172+
#
173+
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
174+
# and be sure to use `mix credo --strict` to see low priority checks)
175+
#
176+
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
177+
{Credo.Check.Consistency.UnusedVariableNames, []},
178+
{Credo.Check.Design.DuplicatedCode, []},
179+
{Credo.Check.Design.SkipTestWithoutComment, []},
180+
{Credo.Check.Readability.AliasAs, []},
181+
{Credo.Check.Readability.BlockPipe, []},
182+
{Credo.Check.Readability.ImplTrue, []},
183+
{Credo.Check.Readability.MultiAlias, []},
184+
{Credo.Check.Readability.NestedFunctionCalls, []},
185+
{Credo.Check.Readability.OneArityFunctionInPipe, []},
186+
{Credo.Check.Readability.OnePipePerLine, []},
187+
{Credo.Check.Readability.SeparateAliasRequire, []},
188+
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
189+
{Credo.Check.Readability.SinglePipe, []},
190+
{Credo.Check.Readability.Specs, []},
191+
{Credo.Check.Readability.StrictModuleLayout, []},
192+
{Credo.Check.Readability.WithCustomTaggedTuple, []},
193+
{Credo.Check.Refactor.ABCSize, []},
194+
{Credo.Check.Refactor.AppendSingleItem, []},
195+
{Credo.Check.Refactor.CondInsteadOfIfElse, []},
196+
{Credo.Check.Refactor.DoubleBooleanNegation, []},
197+
{Credo.Check.Refactor.FilterReject, []},
198+
{Credo.Check.Refactor.IoPuts, []},
199+
{Credo.Check.Refactor.MapMap, []},
200+
{Credo.Check.Refactor.ModuleDependencies, []},
201+
{Credo.Check.Refactor.NegatedIsNil, []},
202+
{Credo.Check.Refactor.PassAsyncInTestCases, []},
203+
{Credo.Check.Refactor.PipeChainStart, []},
204+
{Credo.Check.Refactor.RejectFilter, []},
205+
{Credo.Check.Refactor.VariableRebinding, []},
206+
{Credo.Check.Warning.LazyLogging, []},
207+
{Credo.Check.Warning.LeakyEnvironment, []},
208+
{Credo.Check.Warning.MapGetUnsafePass, []},
209+
{Credo.Check.Warning.MixEnv, []},
210+
{Credo.Check.Warning.UnsafeToAtom, []}
211+
# {Credo.Check.Warning.UnusedOperation, [{MyMagicModule, [:fun1, :fun2]}]}
212+
213+
# {Credo.Check.Refactor.MapInto, []},
214+
215+
#
216+
# Custom checks can be created using `mix credo.gen.check`.
217+
#
218+
]
219+
}
220+
}
221+
]
222+
}

.github/workflows/tests.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,27 @@ jobs:
1010
strategy:
1111
matrix:
1212
combo:
13-
- elixir: 'v1.10'
14-
otp: '23'
15-
- elixir: 'v1.11'
16-
otp: '23'
17-
- elixir: 'v1.12'
18-
otp: '23'
19-
- elixir: 'v1.13'
13+
- elixir: '1.15'
2014
otp: '24'
15+
- elixir: '1.19.5'
16+
otp: '28.4'
2117
env:
2218
MIX_ENV: test
2319
steps:
24-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2521
- uses: erlef/setup-beam@v1
2622
with:
2723
otp-version: ${{ matrix.combo.otp }}
2824
elixir-version: ${{ matrix.combo.elixir }}
29-
- uses: actions/cache@v2
25+
- uses: actions/cache@v4
3026
with:
3127
path: deps
3228
key: ${{ runner.os }}-${{ matrix.combo.otp }}-${{ matrix.combo.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
3329
restore-keys: |
3430
${{ runner.os }}-${{ matrix.combo.otp }}-${{ matrix.combo.elixir }}-
3531
- run: mix deps.get
3632
- run: mix format --dry-run --check-formatted
33+
- run: mix compile --warnings-as-errors
3734
- run: mix test --trace
3835
- run: mix coveralls.github
3936
env:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ simple_enum-*.tar
2424

2525
# Ignore some local files
2626
/TODOLIST.md
27+
28+
/.vscode/

CHANGELOG.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
# Changelog
22

3+
## v1.0.0 (2026-04-05)
4+
5+
### Breaking changes
6+
7+
- **Removed legacy introspection via `name/1`**: `color(:__keys__)`,
8+
`color(:__values__)` and `color(:__enumerators__)` no longer work.
9+
Use the new dedicated helpers instead (see migration guide below).
10+
- **Minimum Elixir version bumped to 1.15**.
11+
12+
### Migration from v0.1.0
13+
14+
Replace all legacy introspection calls:
15+
16+
```diff
17+
- color(:__keys__)
18+
+ color_keys()
19+
20+
- color(:__values__)
21+
+ color_values()
22+
23+
- color(:__enumerators__)
24+
+ color_enumerators()
25+
```
26+
27+
If you defined custom guards like:
28+
29+
```diff
30+
- defguard is_color(value) when value in color(:__keys__) or value in color(:__values__)
31+
- defguard is_color_key(value) when value in color(:__keys__)
32+
- defguard is_color_value(value) when value in color(:__values__)
33+
```
34+
35+
You can remove them entirely, they are now generated automatically:
36+
37+
- `is_color/1` - checks if a value is a valid key or value
38+
- `is_color_key/1` - checks if a value is a valid key
39+
- `is_color_value/1` - checks if a value is a valid value
40+
41+
### New features
42+
43+
- **Helpers**: `name_keys/0`, `name_values/0`, `name_enumerators/0` macros
44+
for compile-time access to enum data.
45+
- **Guards**: `is_name/1`, `is_name_key/1`, `is_name_value/1` guard macros
46+
generated automatically for each enum.
47+
48+
### Improvements
49+
50+
- Internal refactoring for cleaner macro generation.
51+
- Updated dependencies (`ex_doc ~> 0.40`).
52+
353
## v0.1.0 (2021-12-26)
454

5-
* Initial release
55+
- Initial release

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SimpleEnum is:
1919
at compile time when it is possible (see. [Fast vs Slow access](guides/fast_vs_slow_access.md))
2020
- **simple**: the use of the library has been designed to be as simple as possible
2121
for a developer to use. In addition to providing Enums, it automatically defines their
22-
[types](guides/enum_types.md) and provides an [introspection system](guides/introspection.md).
22+
[types](guides/enum_types.md), [helpers and guards](guides/helpers.md).
2323

2424
## Installation
2525

@@ -30,7 +30,7 @@ in `mix.exs`:
3030
# my_app/mix.exs
3131
def deps do
3232
[
33-
{:simple_enum, "~> 0.1"}
33+
{:simple_enum, "~> 1.0"}
3434
]
3535
end
3636
```
@@ -72,6 +72,26 @@ iex> MyEnums.day("MON")
7272
:monday
7373
iex> MyEnums.day("MONN")
7474
** (ArgumentError) invalid value "MONN" for Enum MyEnums.day/1. Expected one of [:monday, :tuesday, :wednesday, "MON", "TUE", "WED"]
75+
76+
iex> MyEnums.color_keys()
77+
[:blue, :green, :red]
78+
iex> MyEnums.color_values()
79+
[0, 1, 2]
80+
iex> MyEnums.color_enumerators()
81+
[blue: 0, green: 1, red: 2]
82+
83+
iex> MyEnums.is_color(:blue)
84+
true
85+
iex> MyEnums.is_color(:nope)
86+
false
87+
iex> MyEnums.is_color_key(:blue)
88+
true
89+
iex> MyEnums.is_color_key(0)
90+
false
91+
iex> MyEnums.is_color_value(0)
92+
true
93+
iex> MyEnums.is_color_value(:blue)
94+
false
7595
```
7696

7797
<!-- MDOC !-->

0 commit comments

Comments
 (0)