diff --git a/CHANGELOG.md b/CHANGELOG.md index fb4241e..9112415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed + +- Internal coding style changes. + ## [1.8.0] - 2024-10-25 ### Added diff --git a/lib/meta_logger/slicer.ex b/lib/meta_logger/slicer.ex index d28a239..8c055b2 100644 --- a/lib/meta_logger/slicer.ex +++ b/lib/meta_logger/slicer.ex @@ -1,6 +1,6 @@ defmodule MetaLogger.Slicer do @moduledoc """ - A bebaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. + A behaviour for slicing long entries into a list of entries shorter than a passed `max_entry_length` value. """ @typedoc "Max length in bytes or `:infinity` if the entry should not be sliced." diff --git a/lib/meta_logger/slicer/default_impl.ex b/lib/meta_logger/slicer/default_impl.ex index 12948b2..6d6deef 100644 --- a/lib/meta_logger/slicer/default_impl.ex +++ b/lib/meta_logger/slicer/default_impl.ex @@ -25,13 +25,12 @@ defmodule MetaLogger.Slicer.DefaultImpl do """ @impl MetaLogger.Slicer - @spec slice(binary(), MetaLogger.Slicer.max_entry_length()) :: [binary()] def slice(entry, max_entry_length) when max_entry_length == :infinity when byte_size(entry) <= max_entry_length, do: [entry] - def slice(entry, max_entry_length) do + def slice(entry, max_entry_length) when is_binary(entry) do entry_length = byte_size(entry) rem = rem(entry_length, max_entry_length) sliced_entries = for <>, do: slice diff --git a/lib/meta_logger/slicer/utf8_impl.ex b/lib/meta_logger/slicer/utf8_impl.ex index 5af26ab..1782e00 100644 --- a/lib/meta_logger/slicer/utf8_impl.ex +++ b/lib/meta_logger/slicer/utf8_impl.ex @@ -34,9 +34,8 @@ defmodule MetaLogger.Slicer.Utf8Impl do when byte_size(entry) <= max_entry_length, do: [entry] - def slice(entry, max_entry_length) do - do_slice(entry, max_entry_length, [], [], 0) - end + def slice(entry, max_entry_length) when is_binary(entry), + do: do_slice(entry, max_entry_length, [], [], 0) @spec do_slice(binary(), integer(), [binary()], [iodata()], integer()) :: [String.t()] defp do_slice(<<>>, _max_length, slices, partial_slice, _partial_size) do @@ -78,12 +77,10 @@ defmodule MetaLogger.Slicer.Utf8Impl do # Converts the inverted list of codepoints into a # binary slice and appends it to our list of slices. @spec bank_partial_slice([binary()], [iodata()]) :: [binary()] - defp bank_partial_slice(slices, partial_slice) do - [reconstruct_current_slice_as_binary(partial_slice) | slices] - end + defp bank_partial_slice(slices, partial_slice), + do: [reconstruct_current_slice_as_binary(partial_slice) | slices] @spec reconstruct_current_slice_as_binary([iodata()]) :: binary() - defp reconstruct_current_slice_as_binary(current_slice) do - IO.iodata_to_binary(Enum.reverse(current_slice)) - end + defp reconstruct_current_slice_as_binary(current_slice), + do: IO.iodata_to_binary(Enum.reverse(current_slice)) end diff --git a/test/meta_logger/slicer/default_impl_test.exs b/test/meta_logger/slicer/default_impl_test.exs index 25f248f..ee523ff 100644 --- a/test/meta_logger/slicer/default_impl_test.exs +++ b/test/meta_logger/slicer/default_impl_test.exs @@ -18,8 +18,10 @@ defmodule MetaLogger.Slicer.DefaultImplTest do assert Subject.slice(entry, :infinity) == [entry] end - test "when max entry length is smaller than the size of given entry, " <> - "returns a list with one entry", + test """ + when max entry length is smaller than the size of given entry, \ + returns a list with one entry + """, %{ entry: entry } do @@ -33,8 +35,10 @@ defmodule MetaLogger.Slicer.DefaultImplTest do assert Subject.slice(entry, 5) == ["01234", "56789"] end - test "when given max entry length is three and the given entry size is 10, " <> - "returns a list with four entries", + test """ + when given max entry length is three and the given entry size is 10, \ + returns a list with four entries + """, %{ entry: entry } do diff --git a/test/meta_logger/slicer/utf8_impl_test.exs b/test/meta_logger/slicer/utf8_impl_test.exs index a52efd7..47b10fe 100644 --- a/test/meta_logger/slicer/utf8_impl_test.exs +++ b/test/meta_logger/slicer/utf8_impl_test.exs @@ -18,8 +18,10 @@ defmodule MetaLogger.Slicer.Utf8ImplTest do assert Subject.slice(entry, :infinity) == [entry] end - test "when max entry length is smaller than the size of given entry, " <> - "returns a list with one entry", + test """ + when max entry length is smaller than the size of given entry, \ + returns a list with one entry + """, %{ entry: entry } do @@ -33,8 +35,10 @@ defmodule MetaLogger.Slicer.Utf8ImplTest do assert Subject.slice(entry, 5) == ["01234", "56789"] end - test "when given max entry length is three and the given entry size is 10, " <> - "returns a list with four entries", + test """ + when given max entry length is three and the given entry size is 10, + returns a list with four entries + """, %{ entry: entry } do diff --git a/test/tesla/middleware/meta_logger_test.exs b/test/tesla/middleware/meta_logger_test.exs index 75b1c31..2472380 100644 --- a/test/tesla/middleware/meta_logger_test.exs +++ b/test/tesla/middleware/meta_logger_test.exs @@ -212,8 +212,10 @@ defmodule Tesla.Middleware.MetaLoggerTest do assert logs =~ ~s([debug] [#{inspect(Subject)}] {"email":"foo@bar.baz","response":"value"}) end - test "when the max entry length is given, " <> - "logs the request and the response splitting the body" do + test """ + when the max entry length is given, \ + logs the request and the response splitting the body + """ do request_body_slice1 = String.duplicate("x", 100) request_body_slice2 = String.duplicate("y", 100)