Skip to content

Commit

Permalink
Build pipeline (#21)
Browse files Browse the repository at this point in the history
* Remove Docker assets and .avsc files

* Update deps, add Dialyzer, and TravisCI
  • Loading branch information
doomspork authored Nov 28, 2019
1 parent 390818a commit e9d2987
Show file tree
Hide file tree
Showing 24 changed files with 289 additions and 149 deletions.
160 changes: 160 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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 exec using `mix credo -C <name>`. If no exec 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/"],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# 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,
#
# 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: 2]},
{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, false},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{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, []},
# TODO: enable by default in Credo 1.1
{Credo.Check.Readability.UnnecessaryAliasExpansion, false},
{Credo.Check.Readability.VariableNames, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MapInto, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.PipeChainStart,
[
excluded_argument_types: [:atom, :binary, :fn, :keyword, :number],
excluded_functions: []
]},
{Credo.Check.Refactor.UnlessWithElse, []},

#
## Warnings
#
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.LazyLogging, []},
{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, []},

#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
3 changes: 2 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Used by "mix format"
[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 120
]
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
language: elixir
sudo: false
notifications:
email: false

before_cache:
- rm -rf _build/$MIX_HOME/lib

cache:
directories:
- _build/$MIX_HOME

elixir:
- 1.8
- 1.7

otp_release:
- 21.1
- 20.3
- 19.3
- 18.3

matrix:
exclude:
- elixir: 1.8
otp_release: 19.3
- elixir: 1.8
otp_release: 18.3
- elixir: 1.7
otp_release: 18.3

before_script:
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix compile --force
- travis_wait mix dialyzer --plt

script:
- mix credo --strict
- mix test
20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The docs can be found on [hex.pm](https://hexdocs.pm/avro_ex/AvroEx.html)

```
def deps do
[{:avro_ex, "~> 0.1.0-beta.0"}]
[{:avro_ex, "~> 1.0"}]
end
```

Expand Down
8 changes: 0 additions & 8 deletions docker-compose.yml

This file was deleted.

12 changes: 5 additions & 7 deletions lib/avro_ex/decode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ defmodule AvroEx.Decode do
{decoded_item, buffer} = do_decode(item_schema, context, buffer)
{[decoded_item | decoded_items], buffer}
end)

{Enum.reverse(decoded_items), String.slice(rest, 1..-1)}
else
{[], buffer}
Expand All @@ -197,8 +198,7 @@ defmodule AvroEx.Decode do
end
end

def do_decode(%AvroEx.Schema.Enum{symbols: symbols}, %Context{} = context, data)
when is_binary(data) do
def do_decode(%AvroEx.Schema.Enum{symbols: symbols}, %Context{} = context, data) when is_binary(data) do
{index, rest} = do_decode(%Primitive{type: :long}, context, data)
{:lists.nth(index + 1, symbols), rest}
end
Expand All @@ -215,21 +215,19 @@ defmodule AvroEx.Decode do
end

def variable_integer_decode(<<0::1, n::7, rest::bitstring>>, acc, %Primitive{type: :integer})
when is_bitstring(acc) and is_bitstring(acc) do
when is_bitstring(acc) do
leading_zero_count = 24 - bit_size(acc)
val = <<0::size(leading_zero_count), n::8, acc::bitstring>>
{val, rest}
end

def variable_integer_decode(<<0::1, n::7, rest::bitstring>>, acc, %Primitive{type: :long})
when is_bitstring(acc) and is_bitstring(acc) do
def variable_integer_decode(<<0::1, n::7, rest::bitstring>>, acc, %Primitive{type: :long}) when is_bitstring(acc) do
leading_zero_count = 56 - bit_size(acc)
val = <<0::size(leading_zero_count), n::8, acc::bitstring>>
{val, rest}
end

def variable_integer_decode(<<1::1, n::7, rest::bitstring>>, acc, type)
when is_bitstring(acc) and is_bitstring(acc) do
def variable_integer_decode(<<1::1, n::7, rest::bitstring>>, acc, type) when is_bitstring(acc) do
variable_integer_decode(rest, <<n::7, acc::bitstring>>, type)
end
end
19 changes: 5 additions & 14 deletions lib/avro_ex/encode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ defmodule AvroEx.Encode do
case do_encode(schema, context, data) do
{:error, :data_does_not_match_schema, _data, _schema} = err -> err
{:error, _reason, _value} = err -> err
{:error, _reason} = err -> err
val -> {:ok, val}
end
end
Expand Down Expand Up @@ -278,9 +277,7 @@ defmodule AvroEx.Encode do
<<byte5, byte4, byte3, byte2, byte1>>
end

def variable_integer_encode(
<<0::22, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7>>
) do
def variable_integer_encode(<<0::22, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7>>) do
<<byte2::8>> = wrap(byte2)
<<byte3::8>> = wrap(byte3)
<<byte4::8>> = wrap(byte4)
Expand All @@ -289,9 +286,7 @@ defmodule AvroEx.Encode do
<<byte6, byte5, byte4, byte3, byte2, byte1>>
end

def variable_integer_encode(
<<0::15, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7>>
) do
def variable_integer_encode(<<0::15, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7>>) do
<<byte2::8>> = wrap(byte2)
<<byte3::8>> = wrap(byte3)
<<byte4::8>> = wrap(byte4)
Expand All @@ -301,9 +296,7 @@ defmodule AvroEx.Encode do
<<byte7, byte6, byte5, byte4, byte3, byte2, byte1>>
end

def variable_integer_encode(
<<0::8, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7, byte8::7>>
) do
def variable_integer_encode(<<0::8, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7, byte8::7>>) do
<<byte2::8>> = wrap(byte2)
<<byte3::8>> = wrap(byte3)
<<byte4::8>> = wrap(byte4)
Expand All @@ -315,8 +308,7 @@ defmodule AvroEx.Encode do
end

def variable_integer_encode(
<<0::1, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7, byte8::7,
byte9::7>>
<<0::1, byte1::7, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7, byte8::7, byte9::7>>
) do
<<byte2::8>> = wrap(byte2)
<<byte3::8>> = wrap(byte3)
Expand All @@ -330,8 +322,7 @@ defmodule AvroEx.Encode do
end

def variable_integer_encode(
<<byte1::1, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7, byte8::7,
byte9::7, byte10::7>>
<<byte1::1, byte2::7, byte3::7, byte4::7, byte5::7, byte6::7, byte7::7, byte8::7, byte9::7, byte10::7>>
) do
<<byte2::8>> = wrap(byte2)
<<byte3::8>> = wrap(byte3)
Expand Down
6 changes: 4 additions & 2 deletions lib/avro_ex/schema.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule AvroEx.Schema.Macros do
@moduledoc false

defmacro cast_schema(data_fields: fields) do
quote do
def cast(data) do
Expand All @@ -9,11 +11,11 @@ defmodule AvroEx.Schema.Macros do
end

defmodule AvroEx.Schema do
alias AvroEx.{Schema, Error}
alias AvroEx.Schema.{Array, Context, Fixed, Primitive, Record, Union}
alias AvroEx.{Error, Schema}
alias AvroEx.Schema.Enum, as: AvroEnum
alias AvroEx.Schema.Map, as: AvroMap
alias AvroEx.Schema.Record.Field
alias AvroEx.Schema.{Array, Context, Fixed, Primitive, Record, Union}

defstruct [:context, :schema]

Expand Down
Loading

0 comments on commit e9d2987

Please sign in to comment.