Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade stream_data #149

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
167 changes: 70 additions & 97 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
configs: [
%{
#
# Run any exec using `mix credo -C <name>`. If no exec name is given
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
Expand Down Expand Up @@ -39,6 +39,10 @@
#
strict: false,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
Expand All @@ -51,107 +55,76 @@
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, false},
{Credo.Check.Consistency.SpaceInParentheses, false},
{Credo.Check.Consistency.TabsOrSpaces, []},
{Credo.Check.Consistency.UnusedVariableNames, false},
checks: %{
enabled: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 4, if_called_more_often_than: 2]},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Design.TagTODO, false},
{Credo.Check.Design.TagFIXME, false},
#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 4, if_called_more_often_than: 2]},

#
## Readability Checks
#
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.AliasOrder, false},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, false},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PredicateFunctionNames, false},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, [max_blank_lines: 1]},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.SpaceAfterCommas, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
# TODO: enable by default in Credo 1.1
{Credo.Check.Readability.UnnecessaryAliasExpansion, false},
{Credo.Check.Readability.VariableNames, []},
#
## Readability Checks
#
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, [max_blank_lines: 1]},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.VariableNames, []},

#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.CaseTrivialMatches, false},
{Credo.Check.Refactor.CondStatements, false},
{Credo.Check.Refactor.CyclomaticComplexity, [max_complexity: 18]},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, false},
{Credo.Check.Refactor.MapInto, false},
{Credo.Check.Refactor.MatchInCondition, false},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, false},
{Credo.Check.Refactor.PipeChainStart, false},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Refactor.WithClauses, []},
#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CyclomaticComplexity, [max_complexity: 18]},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
#
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.LazyLogging, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, false},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.UnsafeToAtom, false},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []}
]
#
## Warnings
#
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []}
]
}
}
]
}
24 changes: 12 additions & 12 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
elixir: [1.11]
otp: [23.3]
elixir: [1.13]
otp: [25.3]
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup
Expand All @@ -28,7 +28,7 @@ jobs:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Retrieve Cached Dependencies
uses: actions/cache@v2
uses: actions/cache@v4
id: mix-cache
with:
path: |
Expand All @@ -51,10 +51,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
elixir: [1.11]
otp: [23.3]
elixir: [1.13]
otp: [25.3]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup elixir
Expand All @@ -63,7 +63,7 @@ jobs:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Retrieve Cached Dependencies
uses: actions/cache@v2
uses: actions/cache@v4
id: mix-cache
with:
path: |
Expand All @@ -80,18 +80,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
elixir: [1.11]
otp: [23.3]
elixir: [1.13]
otp: [25.3]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Retrieve Cached Dependencies
uses: actions/cache@v2
uses: actions/cache@v4
id: mix-cache
with:
path: |
Expand Down
30 changes: 0 additions & 30 deletions config/config.exs

This file was deleted.

6 changes: 1 addition & 5 deletions lib/norm/conformer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ defmodule Norm.Conformer do
|> Enum.join(" ")
end

defp build_path(keys) do
keys
|> Enum.map(&format_val/1)
|> Enum.join("/")
end
defp build_path(keys), do: Enum.map_join(keys, "/", &format_val/1)

defp format_val(nil), do: "nil"
defp format_val(msg) when is_binary(msg), do: "\"#{msg}\""
Expand Down
1 change: 0 additions & 1 deletion lib/norm/core/all_of.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ defmodule Norm.Core.AllOf do
end
end
end

24 changes: 11 additions & 13 deletions lib/norm/core/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ defmodule Norm.Core.Schema do
# Conforming a struct
def conform(%{specs: specs, struct: target}, input, path) when not is_nil(target) do
# Ensure we're mapping the correct struct
cond do
Map.get(input, :__struct__) != target ->
short_name =
target
|> Atom.to_string()
|> String.replace("Elixir.", "")

{:error, [Conformer.error(path, input, "#{short_name}")]}

true ->
with {:ok, conformed} <- check_specs(specs, Map.from_struct(input), path) do
{:ok, struct(target, conformed)}
end
if Map.get(input, :__struct__) != target do
short_name =
target
|> Atom.to_string()
|> String.replace("Elixir.", "")

{:error, [Conformer.error(path, input, "#{short_name}")]}
else
with {:ok, conformed} <- check_specs(specs, Map.from_struct(input), path) do
{:ok, struct(target, conformed)}
end
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/norm/core/selection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ defmodule Norm.Core.Selection do
defp build_all_selectors(schema) do
schema.specs
|> Enum.map(fn
{name, %Schema{}=inner_schema} -> {name, build_all_selectors(inner_schema)}
{name, %Schema{} = inner_schema} -> {name, build_all_selectors(inner_schema)}
{name, _} -> name
end)
end

defp validate_selectors!([]), do: true
defp validate_selectors!([{_key, inner} | rest]), do: validate_selectors!(inner) and validate_selectors!(rest)
defp validate_selectors!([_key | rest]), do: validate_selectors!(rest)
defp validate_selectors!(other), do: raise ArgumentError, "select expects a list of keys but received: #{inspect other}"
defp validate_selectors!(other), do: raise(ArgumentError, "select expects a list of keys but received: #{inspect other}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the following compilation warning:

Screenshot 2024-05-29 at 1 19 53 PM


defp assert_spec!(%Schema{}=schema, key) do
defp assert_spec!(%Schema{} = schema, key) do
case Schema.key_present?(schema, key) do
false -> raise SpecError, {:selection, key, schema}
true -> Schema.spec(schema, key)
Expand Down
1 change: 1 addition & 0 deletions lib/norm/core/spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ defmodule Norm.Core.Spec do
end
end

# credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity
defp build_generator(gen) do
case gen do
:is_atom -> StreamData.atom(:alphanumeric)
Expand Down
Loading