From 98508cb4f36cebef984c43e7e21fbbe322af6856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20B=C5=82aszk=C3=B3w?= Date: Fri, 25 Mar 2022 12:57:46 +0100 Subject: [PATCH 1/5] Fix warnings when compiled as a dependency --- mix.exs | 9 +++++---- mix.lock | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/mix.exs b/mix.exs index 5593eab..0cc83f5 100644 --- a/mix.exs +++ b/mix.exs @@ -21,13 +21,14 @@ defmodule Bunch.MixProject do end def application do - [extra_applications: []] + [extra_applications: [:crypto]] end defp docs do [ main: "readme", extras: ["README.md"], + formatters: ["html"], source_ref: "v#{@version}", nest_modules_by_prefix: [Bunch] ] @@ -36,7 +37,7 @@ defmodule Bunch.MixProject do defp package do [ maintainers: ["Membrane Team"], - licenses: ["Apache 2.0"], + licenses: ["Apache-2.0"], links: %{ "GitHub" => @github_url, "Membrane Framework Homepage" => "https://membraneframework.org" @@ -46,8 +47,8 @@ defmodule Bunch.MixProject do defp deps do [ - {:ex_doc, "~> 0.21", only: :dev, runtime: false}, - {:dialyxir, "~> 1.0.0", only: :dev, runtime: false} + {:ex_doc, "~> 0.28", only: :dev, runtime: false}, + {:dialyxir, "~> 1.1", only: :dev, runtime: false} ] end end diff --git a/mix.lock b/mix.lock index 0ef8b43..c2fde09 100644 --- a/mix.lock +++ b/mix.lock @@ -1,9 +1,10 @@ %{ "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, - "earmark": {:hex, :earmark, "1.3.5", "0db71c8290b5bc81cb0101a2a507a76dca659513984d683119ee722828b424f6", [:mix], [], "hexpm", "762b999fd414fb41e297944228aa1de2cd4a3876a07f968c8b11d1e9a2190d07"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_doc": {:hex, :ex_doc, "0.21.1", "5ac36660846967cd869255f4426467a11672fec3d8db602c429425ce5b613b90", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "93d2fee94d2f88abf507628378371ea5fab08ed03fa59a6daa3d4469d9159ddd"}, - "makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "a10c6eb62cca416019663129699769f0c2ccf39428b3bb3c0cb38c718a0c186d"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "d4b316c7222a85bbaa2fd7c6e90e37e953257ad196dc229505137c5e505e9eff"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm", "00e3ebdc821fb3a36957320d49e8f4bfa310d73ea31c90e5f925dc75e030da8f"}, + "ex_doc": {:hex, :ex_doc, "0.28.3", "6eea2f69995f5fba94cd6dd398df369fe4e777a47cd887714a0976930615c9e6", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "05387a6a2655b5f9820f3f627450ed20b4325c25977b2ee69bed90af6688e718"}, + "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, } From 4f40350684c3d30349713eac67838002b72c0a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20B=C5=82aszk=C3=B3w?= Date: Fri, 25 Mar 2022 13:06:09 +0100 Subject: [PATCH 2/5] Dialyxir update & docs generation warning fix --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 0cc83f5..831f899 100644 --- a/mix.exs +++ b/mix.exs @@ -27,7 +27,7 @@ defmodule Bunch.MixProject do defp docs do [ main: "readme", - extras: ["README.md"], + extras: ["README.md", "LICENSE"], formatters: ["html"], source_ref: "v#{@version}", nest_modules_by_prefix: [Bunch] diff --git a/mix.lock b/mix.lock index c2fde09..87e140a 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,5 @@ %{ - "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, + "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, "earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.28.3", "6eea2f69995f5fba94cd6dd398df369fe4e777a47cd887714a0976930615c9e6", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "05387a6a2655b5f9820f3f627450ed20b4325c25977b2ee69bed90af6688e718"}, From 67a63b9055db1febaf6121c3ce84594f2762bd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20B=C5=82aszk=C3=B3w?= Date: Fri, 25 Mar 2022 13:27:58 +0100 Subject: [PATCH 3/5] Add credo, fix warns & update CircleCI config --- .circleci/config.yml | 54 ++++++++++-- .credo.exs | 187 +++++++++++++++++++++++++++++++++++++++++ lib/bunch.ex | 9 +- lib/bunch/access.ex | 4 +- lib/bunch/config.ex | 5 +- lib/bunch/macro.ex | 3 +- lib/bunch/short_ref.ex | 2 +- lib/bunch/struct.ex | 4 +- lib/bunch/typespec.ex | 3 +- mix.exs | 1 + mix.lock | 4 + 11 files changed, 260 insertions(+), 16 deletions(-) create mode 100644 .credo.exs diff --git a/.circleci/config.yml b/.circleci/config.yml index 7068fac..a7f81ff 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,17 @@ -version: 2.0 +version: 2.1 +commands: + restore_mix_cache: + steps: + - restore_cache: + keys: + - mix-cache-{{ arch }}-{{ .Branch }}-{{ checksum "mix.lock" }} + - mix-cache-{{ arch }}-{{ .Branch }} + - mix-cache-{{ arch }} + jobs: - build: + test: docker: - - image: circleci/elixir:1.9.4 + - image: cimg/elixir:1.13 environment: MIX_ENV: test @@ -11,8 +20,43 @@ jobs: steps: - checkout - run: mix local.hex --force + - restore_mix_cache - run: mix deps.get - - run: mix format --check-formatted - run: mix compile --force --warnings-as-errors + - save_cache: + key: mix-cache-{{ arch }}-{{ .Branch }}-{{ checksum "mix.lock" }} + paths: ["deps", "_build"] - run: mix test - - run: MIX_ENV=dev mix docs && ! mix docs 2>&1 | grep -q "warning:" + + lint: + docker: + - image: cimg/elixir:1.13 + environment: + MIX_ENV: dev + + working_directory: ~/app + + steps: + - checkout + - run: mix local.hex --force + - restore_mix_cache + - run: mix deps.get + - run: mix format --check-formatted + - run: mix compile + - run: mix credo + - run: mix docs && mix docs 2>&1 | (! grep -q "warning:") + - run: asdf current elixir | awk '{print $2}' > .elixir_version + - restore_cache: + keys: + - dialyzer-cache-{{ arch }}-{{ checksum ".elixir_version" }} + - run: mix dialyzer + - save_cache: + key: dialyzer-cache-{{ arch }}-{{ checksum ".elixir_version" }} + paths: "priv/plts" + +workflows: + version: 2 + build: + jobs: + - test + - lint diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..917f7b7 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,187 @@ +# This file contains the configuration for Credo and you are probably reading +# this after creating it with `mix credo.gen.config`. +# +# If you find anything wrong or unclear in this file, please report an +# issue on GitHub: https://github.com/rrrene/credo/issues +# +%{ + # + # You can have as many configs as you like in the `configs:` field. + configs: [ + %{ + # + # Run any config using `mix credo -C `. If no config name is given + # "default" is used. + # + name: "default", + # + # These are the files included in the analysis: + files: %{ + # + # You can give explicit globs or simply directories. + # In the latter case `**/*.{ex,exs}` will be used. + # + included: [ + "lib/", + "src/", + "test/", + "web/", + "apps/*/lib/", + "apps/*/src/", + "apps/*/test/", + "apps/*/web/" + ], + excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"] + }, + # + # Load and configure plugins here: + # + plugins: [], + # + # If you create your own checks, you must specify the source files for + # them here, so they can be loaded by Credo before running the analysis. + # + requires: [], + # + # If you want to enforce a style guide and need a more traditional linting + # experience, you can change `strict` to `true` below: + # + 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: + # + color: true, + # + # You can customize the parameters of any check by adding a second element + # to the tuple. + # + # To disable a check put `false` as second element: + # + # {Credo.Check.Design.DuplicatedCode, false} + # + checks: [ + # + ## Consistency Checks + # + {Credo.Check.Consistency.ExceptionNames, []}, + {Credo.Check.Consistency.LineEndings, []}, + {Credo.Check.Consistency.ParameterPatternMatching, []}, + {Credo.Check.Consistency.SpaceAroundOperators, []}, + {Credo.Check.Consistency.SpaceInParentheses, []}, + {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: 2, if_called_more_often_than: 0]}, + # You can also customize the exit_status of each check. + # If you don't want TODO comments to cause `mix credo` to fail, just + # set this value to 0 (zero). + # + {Credo.Check.Design.TagTODO, [exit_status: 0]}, + {Credo.Check.Design.TagFIXME, []}, + + # + ## Readability Checks + # + {Credo.Check.Readability.AliasOrder, []}, + {Credo.Check.Readability.FunctionNames, []}, + {Credo.Check.Readability.LargeNumbers, []}, + {Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]}, + {Credo.Check.Readability.ModuleAttributeNames, []}, + {Credo.Check.Readability.ModuleDoc, []}, + {Credo.Check.Readability.ModuleNames, []}, + {Credo.Check.Readability.ParenthesesInCondition, []}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, parens: true}, + {Credo.Check.Readability.PredicateFunctionNames, []}, + {Credo.Check.Readability.PreferImplicitTry, []}, + {Credo.Check.Readability.RedundantBlankLines, []}, + {Credo.Check.Readability.Semicolons, []}, + {Credo.Check.Readability.SpaceAfterCommas, []}, + {Credo.Check.Readability.StringSigils, []}, + {Credo.Check.Readability.TrailingBlankLine, []}, + {Credo.Check.Readability.TrailingWhiteSpace, []}, + {Credo.Check.Readability.UnnecessaryAliasExpansion, []}, + {Credo.Check.Readability.VariableNames, []}, + {Credo.Check.Readability.WithSingleClause, false}, + + # + ## Refactoring Opportunities + # + {Credo.Check.Refactor.CondStatements, []}, + {Credo.Check.Refactor.CyclomaticComplexity, []}, + {Credo.Check.Refactor.FunctionArity, []}, + {Credo.Check.Refactor.LongQuoteBlocks, []}, + {Credo.Check.Refactor.MapInto, false}, + {Credo.Check.Refactor.MatchInCondition, []}, + {Credo.Check.Refactor.NegatedConditionsInUnless, []}, + {Credo.Check.Refactor.NegatedConditionsWithElse, []}, + {Credo.Check.Refactor.Nesting, []}, + {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.MixEnv, []}, + {Credo.Check.Warning.OperationOnSameValues, []}, + {Credo.Check.Warning.OperationWithConstantResult, []}, + {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, []}, + {Credo.Check.Warning.UnsafeExec, []}, + + # + # Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`) + + # + # Controversial and experimental checks (opt-in, just replace `false` with `[]`) + # + {Credo.Check.Readability.StrictModuleLayout, + priority: :normal, order: ~w/shortdoc moduledoc behaviour use import require alias/a}, + {Credo.Check.Consistency.MultiAliasImportRequireUse, false}, + {Credo.Check.Consistency.UnusedVariableNames, force: :meaningful}, + {Credo.Check.Design.DuplicatedCode, false}, + {Credo.Check.Readability.AliasAs, false}, + {Credo.Check.Readability.MultiAlias, false}, + {Credo.Check.Readability.Specs, []}, + {Credo.Check.Readability.SinglePipe, false}, + {Credo.Check.Readability.WithCustomTaggedTuple, false}, + {Credo.Check.Refactor.ABCSize, false}, + {Credo.Check.Refactor.AppendSingleItem, false}, + {Credo.Check.Refactor.DoubleBooleanNegation, false}, + {Credo.Check.Refactor.ModuleDependencies, false}, + {Credo.Check.Refactor.NegatedIsNil, false}, + {Credo.Check.Refactor.PipeChainStart, false}, + {Credo.Check.Refactor.VariableRebinding, false}, + {Credo.Check.Warning.LeakyEnvironment, false}, + {Credo.Check.Warning.MapGetUnsafePass, false}, + {Credo.Check.Warning.UnsafeToAtom, false} + + # + # Custom checks can be created using `mix credo.gen.check`. + # + ] + } + ] +} diff --git a/lib/bunch.ex b/lib/bunch.ex index adca2e7..1a53b73 100644 --- a/lib/bunch.ex +++ b/lib/bunch.ex @@ -272,8 +272,7 @@ defmodule Bunch do [nil] """ - @spec listify(l) :: l when l: list - @spec listify(a) :: [a] when a: any + @spec listify(a | [a]) :: [a] when a: any def listify(list) when is_list(list) do list end @@ -297,7 +296,7 @@ defmodule Bunch do @spec error_if_nil(value, reason) :: Type.try_t(value) when value: any(), reason: any() def error_if_nil(nil, reason), do: {:error, reason} - def error_if_nil(v, _), do: {:ok, v} + def error_if_nil(v, _reason), do: {:ok, v} @doc """ Returns given stateful try value along with its status. @@ -359,7 +358,7 @@ defmodule Bunch do {:&, _meta, [i]} = node, acc when is_integer(i) -> {node, acc} - {:&, meta, _}, _acc -> + {:&, meta, _args}, _acc -> """ The `&` (capture) operator is not allowed in lambda-like version of \ `#{inspect(__MODULE__)}.~>/2`. Use `&1` alone instead. @@ -418,6 +417,8 @@ defmodule Bunch do |> raise_compile_error(__CALLER__) end + @spec raise_compile_error(term(), Macro.Env.t(), Keyword.t()) :: no_return() + @spec raise_compile_error(term(), Macro.Env.t()) :: no_return() defp raise_compile_error(reason, caller, meta \\ []) do raise CompileError, file: caller.file, diff --git a/lib/bunch/access.ex b/lib/bunch/access.ex index 9c1f660..5f6c49f 100644 --- a/lib/bunch/access.ex +++ b/lib/bunch/access.ex @@ -3,9 +3,11 @@ defmodule Bunch.Access do A bunch of functions for easier manipulation on terms of types implementing `Access` behaviour. """ - import Kernel, except: [get_in: 2, put_in: 2, update_in: 3, get_and_update_in: 3, pop_in: 2] + use Bunch + import Kernel, except: [get_in: 2, put_in: 2, update_in: 3, get_and_update_in: 3, pop_in: 2] + @compile {:inline, map_keys: 1} @gen_common_docs fn fun_name -> diff --git a/lib/bunch/config.ex b/lib/bunch/config.ex index cc1d22e..66e1c0c 100644 --- a/lib/bunch/config.ex +++ b/lib/bunch/config.ex @@ -3,9 +3,10 @@ defmodule Bunch.Config do A bunch of helpers for parsing and validating configurations. """ - alias Bunch.Type use Bunch + alias Bunch.Type + @doc """ Parses `config` according to `fields_specs`. @@ -117,7 +118,7 @@ defmodule Bunch.Config do end defp parse_field(key, spec, {:ok, value}, config) do - validate = spec |> Map.get(:validate, fn _ -> :ok end) + validate = spec |> Map.get(:validate, fn _value -> :ok end) in_enum = spec |> Map.get(:in, [value]) withl fun: diff --git a/lib/bunch/macro.ex b/lib/bunch/macro.ex index 6657d4c..a6d12cb 100644 --- a/lib/bunch/macro.ex +++ b/lib/bunch/macro.ex @@ -36,7 +36,7 @@ defmodule Bunch.Macro do defp replace_call(ast_node, {module, fun_name}) when is_atom(module) and is_atom(fun_name) do case ast_node do - {^fun_name, _, args} -> + {^fun_name, _ctx, args} -> quote do apply(unquote(module), unquote(fun_name), unquote(args)) end @@ -130,5 +130,6 @@ defmodule Bunch.Macro do This function uses `Macro.expand/2` under the hood. Check it out for more information and examples. """ + @spec expand_deep(Macro.t(), Macro.Env.t()) :: Macro.t() def expand_deep(ast, env), do: Macro.prewalk(ast, fn tree -> Macro.expand(tree, env) end) end diff --git a/lib/bunch/short_ref.ex b/lib/bunch/short_ref.ex index 1e6fa32..8b2abe8 100644 --- a/lib/bunch/short_ref.ex +++ b/lib/bunch/short_ref.ex @@ -40,7 +40,7 @@ defmodule Bunch.ShortRef do @spec new(reference) :: t def new(ref \\ make_ref()) do ref_list = :erlang.ref_to_list(ref) - <> = :crypto.hash(:sha, ref_list) + <> = :crypto.hash(:sha, ref_list) hash = "#" <> Base.encode16(bin_hash_part, case: :lower) %__MODULE__{ref: ref, hash: hash} end diff --git a/lib/bunch/struct.ex b/lib/bunch/struct.ex index 693a2f1..28e48f1 100644 --- a/lib/bunch/struct.ex +++ b/lib/bunch/struct.ex @@ -2,9 +2,11 @@ defmodule Bunch.Struct do @moduledoc """ A bunch of functions for easier manipulation on structs. """ - import Kernel, except: [get_in: 2, put_in: 2, update_in: 3, get_and_update_in: 3, pop_in: 2] + use Bunch + import Kernel, except: [get_in: 2, put_in: 2, update_in: 3, get_and_update_in: 3, pop_in: 2] + @compile {:inline, map_keys: 1} @gen_common_docs fn fun_name -> diff --git a/lib/bunch/typespec.ex b/lib/bunch/typespec.ex index 70a711f..5ac0a4c 100644 --- a/lib/bunch/typespec.ex +++ b/lib/bunch/typespec.ex @@ -26,7 +26,8 @@ defmodule Bunch.Typespec do :b """ - defmacro @{:list_type, _, [{:"::", _, [{name, _, _} = name_var, list]}]} do + # credo:disable-for-next-line Credo.Check.Consistency.UnusedVariableNames + defmacro @{:list_type, _, [{:"::", _, [{name, _, _env} = name_var, list]}]} do type = list |> Enum.reduce(fn a, b -> {:|, [], [a, b]} end) quote do diff --git a/mix.exs b/mix.exs index 831f899..659d43f 100644 --- a/mix.exs +++ b/mix.exs @@ -48,6 +48,7 @@ defmodule Bunch.MixProject do defp deps do [ {:ex_doc, "~> 0.28", only: :dev, runtime: false}, + {:credo, "~> 1.6", only: :dev, runtime: false}, {:dialyxir, "~> 1.1", only: :dev, runtime: false} ] end diff --git a/mix.lock b/mix.lock index 87e140a..be3fee3 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,12 @@ %{ + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, + "credo": {:hex, :credo, "1.6.4", "ddd474afb6e8c240313f3a7b0d025cc3213f0d171879429bf8535d7021d9ad78", [: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", "c28f910b61e1ff829bffa056ef7293a8db50e87f2c57a9b5c3f57eee124536b7"}, "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, "earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.28.3", "6eea2f69995f5fba94cd6dd398df369fe4e777a47cd887714a0976930615c9e6", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "05387a6a2655b5f9820f3f627450ed20b4325c25977b2ee69bed90af6688e718"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"}, "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, From 388ccef013635b2ba6926308e62ecb6d64104aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20B=C5=82aszk=C3=B3w?= Date: Fri, 25 Mar 2022 13:37:19 +0100 Subject: [PATCH 4/5] Fix Circle config --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a7f81ff..ec68238 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,7 @@ jobs: - run: mix compile - run: mix credo - run: mix docs && mix docs 2>&1 | (! grep -q "warning:") - - run: asdf current elixir | awk '{print $2}' > .elixir_version + - run: elixir -v | tail -n 1 > .elixir_version - restore_cache: keys: - dialyzer-cache-{{ arch }}-{{ checksum ".elixir_version" }} From 5c0f1364978ad8a9c19d4846b9d6211d851289be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20B=C5=82aszk=C3=B3w?= Date: Fri, 25 Mar 2022 15:46:16 +0100 Subject: [PATCH 5/5] Update lib/bunch/typespec.ex Co-authored-by: Mateusz Front --- lib/bunch/typespec.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bunch/typespec.ex b/lib/bunch/typespec.ex index 5ac0a4c..5339ebe 100644 --- a/lib/bunch/typespec.ex +++ b/lib/bunch/typespec.ex @@ -26,8 +26,7 @@ defmodule Bunch.Typespec do :b """ - # credo:disable-for-next-line Credo.Check.Consistency.UnusedVariableNames - defmacro @{:list_type, _, [{:"::", _, [{name, _, _env} = name_var, list]}]} do + defmacro @{:list_type, _meta1, [{:"::", _meta2, [{name, _meta3, _env} = name_var, list]}]} do type = list |> Enum.reduce(fn a, b -> {:|, [], [a, b]} end) quote do