Skip to content

Commit

Permalink
chore: satisfy credo
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaAK committed Feb 1, 2024
1 parent c034b00 commit 66dce77
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 21 deletions.
132 changes: 132 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
allowed_imports = [
[:Plug],
[:Telemetry, :Metrics]
]

%{
configs: [
%{
name: "default",
files: %{
included: [
"lib/",
"test/"
],
excluded: [~r"_build/", ~r"deps/"]
},
plugins: [],
requires: ["deps/blitz_credo/lib/blitz_credo/"],
strict: true,
parse_timeout: 10000,
color: true,
checks: [

# BlitzCredoChecks

{BlitzCredoChecks.SetWarningsAsErrorsInTest, false},
{BlitzCredoChecks.DocsBeforeSpecs, []},
{BlitzCredoChecks.DoctestIndent, []},
{BlitzCredoChecks.NoAsyncFalse, []},
{BlitzCredoChecks.NoDSLParentheses, []},
{BlitzCredoChecks.NoIsBitstring, []},
{BlitzCredoChecks.StrictComparison, []},
{BlitzCredoChecks.UseStream, []},
{BlitzCredoChecks.LowercaseTestNames, []},
{BlitzCredoChecks.ImproperImport, allowed_modules: allowed_imports},

# 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
{Credo.Check.Design.AliasUsage, false},

# No outstanding TODOs
{Credo.Check.Design.TagTODO, []},
{Credo.Check.Design.TagFIXME, []},

# # Readability Checks
{Credo.Check.Readability.AliasOrder, false},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [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, false},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, false},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, false},
{Credo.Check.Readability.TrailingWhiteSpace, false},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
#
# Refactoring Opportunities
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, false},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, false},
{Credo.Check.Refactor.MapInto, false},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, false},
{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, false},
{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, []},

# Controversial and experimental checks
{Credo.Check.Readability.StrictModuleLayout, false},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.UnusedVariableNames, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{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, []},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}
]
}
]
}



13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
status:
project:
default:
target: 75%
threshold: 0%
base: auto
patch:
default:
target: 80%
threshold: 2%
base: auto

22 changes: 22 additions & 0 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"skip_files": [
"test/support/*"
],

"terminal_options": {
"file_column_width": 75
},

"coverage_options": {
"html_filter_full_covered": true,
"treat_no_relevant_lines_as_covered": true,
"minimum_coverage": 70
},

"custom_stop_words": [
"defdelegate"
]
}



29 changes: 13 additions & 16 deletions lib/pinecone.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ defmodule Pinecone do
@moduledoc """
Elixir client for the [Pinecone](https://pinecone.io) REST API.
"""
import Pinecone.Http

alias Pinecone.Index
alias Pinecone.{Index, HTTP}

@type success_type(inner) :: {:ok, inner}
@type error_type :: {:error, String.t()}
Expand Down Expand Up @@ -41,7 +39,7 @@ defmodule Pinecone do
def list_indices(opts \\ []) do
opts = Keyword.validate!(opts, [:config])

with {:ok, %{"indexes" => indexes}} <- get(:indices, "", opts[:config]) do
with {:ok, %{"indexes" => indexes}} <- HTTP.get(:indices, "", opts[:config]) do
{:ok, indexes}
end
end
Expand All @@ -60,7 +58,7 @@ defmodule Pinecone do
success_type(map()) | error_type()
def describe_index(index_name, opts \\ []) do
opts = Keyword.validate!(opts, [:config])
get(:indices, index_name, opts[:config])
HTTP.get(:indices, index_name, opts[:config])
end

@valid_clouds ["gcp", "aws", "azure"]
Expand Down Expand Up @@ -110,7 +108,6 @@ defmodule Pinecone do
spec: []
])

# TODO: validate metadata
validate!("index_name", index_name, :binary)
validate!("dimension", opts[:dimension], :non_negative_integer)
validate!("metric", opts[:metric], :one_of, @valid_metric_types)
Expand All @@ -124,7 +121,7 @@ defmodule Pinecone do
"spec" => spec_params
}

post(:indices, "", body, opts[:config])
HTTP.post(:indices, "", body, opts[:config])
end

defp validate_create_index_opts(spec_opts) do
Expand Down Expand Up @@ -190,7 +187,7 @@ defmodule Pinecone do
def delete_index(index_name, opts \\ []) do
opts = Keyword.validate!(opts, [:config])

delete(:indices, index_name, opts[:config])
HTTP.delete(:indices, index_name, opts[:config])
end

@doc """
Expand Down Expand Up @@ -223,7 +220,7 @@ defmodule Pinecone do
"pod_type" => to_pod_type(opts[:pod_type])
}

patch(:indices, index_name, body, opts[:config])
HTTP.patch(:indices, index_name, body, opts[:config])
end

## Vector operations
Expand Down Expand Up @@ -363,19 +360,19 @@ defmodule Pinecone do

defp delete_vector(path, name, config, opts) do
with {:ok, host} <- index_host(name) do
delete({:vectors, host}, path, config, opts)
HTTP.delete({:vectors, host}, path, config, opts)
end
end

defp get_vector(path, name, config, opts) do
with {:ok, host} <- index_host(name) do
get({:vectors, host}, path, config, opts)
HTTP.get({:vectors, host}, path, config, opts)
end
end

defp post_vector(path, name, body, opts) do
with {:ok, host} <- index_host(name) do
post({:vectors, host}, path, body, opts)
HTTP.post({:vectors, host}, path, body, opts)
end
end

Expand Down Expand Up @@ -469,7 +466,7 @@ defmodule Pinecone do
"source" => index_name
}

post(:collections, "", body, opts[:config])
HTTP.post(:collections, "", body, opts[:config])
end

@doc """
Expand All @@ -487,7 +484,7 @@ defmodule Pinecone do
def describe_collection(collection_name, opts \\ []) when is_binary(collection_name) do
opts = Keyword.validate!(opts, [:config])

get(:collections, collection_name, opts[:config])
HTTP.get(:collections, collection_name, opts[:config])
end

@doc """
Expand All @@ -503,7 +500,7 @@ defmodule Pinecone do
def list_collections(opts \\ []) do
opts = Keyword.validate!(opts, [:config])

get(:collections, "", opts[:config])
HTTP.get(:collections, "", opts[:config])
end

@doc """
Expand All @@ -521,7 +518,7 @@ defmodule Pinecone do
def delete_collection(collection_name, opts \\ []) when is_binary(collection_name) do
opts = Keyword.validate!(opts, [:config])

get(:collections, collection_name, opts[:config])
HTTP.get(:collections, collection_name, opts[:config])
end

defp to_pod_type({type, size}), do: "#{Atom.to_string(type)}.#{Atom.to_string(size)}"
Expand Down
2 changes: 1 addition & 1 deletion lib/pinecone/http.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Pinecone.Http do
defmodule Pinecone.HTTP do
@moduledoc false

require Logger
Expand Down
47 changes: 43 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,30 @@ defmodule Pinecone.MixProject do
def project do
[
app: :pinecone,
version: "0.1.0",
elixir: "~> 1.14",
version: "0.1.1",
elixir: "~> 1.12",
description: "Pinecone.io API integration",
start_permanent: Mix.env() == :prod,
deps: deps()
deps: deps(),
docs: docs(),
package: package(),

preferred_cli_env: [
dialyzer: :test
],

elixirc_options: [
warnings_as_errors: true
],

dialyzer: [
plt_add_apps: [:ex_unit, :mix, :credo],
list_unused_filters: true,
plt_local_path: ".dialyzer",
plt_core_path: ".dialyzer",
ignore_warnings: ".dialyzer-ignore.exs",
flags: [:unmatched_returns, :no_improper_lists]
]
]
end

Expand All @@ -22,9 +42,28 @@ defmodule Pinecone.MixProject do
defp deps do
[
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:blitz_credo_checks, "~> 0.1", only: [:test, :dev], runtime: false},
{:ex_doc, ">= 0.0.0", optional: true, only: :dev},

{:jason, "~> 1.4"},
{:req, "~> 0.3"}
]
end

defp package do
[
maintainers: ["Mika Kalathil"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/theblitzapp/prometheus_telemetry_elixir"},
files: ~w(mix.exs README.md CHANGELOG.md LICENSE lib config priv)
]
end

defp docs do
[
main: "Pinecone",
source_url: "https://github.com/mikaak/pinecone"
]
end
end
7 changes: 7 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
%{
"blitz_credo_checks": {:hex, :blitz_credo_checks, "0.1.10", "54ae0aa673101e3edd4f2ab0ee7860f90c3240e515e268546dd9f01109d2b917", [:mix], [{:credo, "~> 1.4", [hex: :credo, repo: "hexpm", optional: false]}], "hexpm", "b3248dd2c88a6fe907e84ed104e61b863c6451d8755aa609b36d3eb6c7bab9db"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
"credo": {:hex, :credo, "1.7.3", "05bb11eaf2f2b8db370ecaa6a6bda2ec49b2acd5e0418bc106b73b07128c0436", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "35ea675a094c934c22fb1dca3696f3c31f2728ae6ef5a53b5d648c11180a4535"},
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
"finch": {:hex, :finch, "0.17.0", "17d06e1d44d891d20dbd437335eebe844e2426a0cd7e3a3e220b461127c73f70", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8d014a661bb6a437263d4b5abf0bcbd3cf0deb26b1e8596f2a271d22e48934c7"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"},
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
"mint": {:hex, :mint, "1.5.2", "4805e059f96028948870d23d7783613b7e6b0e2fb4e98d720383852a760067fd", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "d77d9e9ce4eb35941907f1d3df38d8f750c357865353e21d335bdcdf6d892a02"},
"nimble_options": {:hex, :nimble_options, "1.1.0", "3b31a57ede9cb1502071fade751ab0c7b8dbe75a9a4c2b5bbb0943a690b63172", [:mix], [], "hexpm", "8bbbb3941af3ca9acc7835f5655ea062111c9c27bcac53e004460dfd19008a99"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"nimble_pool": {:hex, :nimble_pool, "1.0.0", "5eb82705d138f4dd4423f69ceb19ac667b3b492ae570c9f5c900bb3d2f50a847", [:mix], [], "hexpm", "80be3b882d2d351882256087078e1b1952a28bf98d0a287be87e4a24a710b67a"},
"req": {:hex, :req, "0.4.8", "2b754a3925ddbf4ad78c56f30208ced6aefe111a7ea07fb56c23dccc13eb87ae", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.9", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "7146e51d52593bb7f20d00b5308a5d7d17d663d6e85cd071452b613a8277100c"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
Expand Down

0 comments on commit 66dce77

Please sign in to comment.