Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,19 @@ python-black-update: .venv/bin/black
. dev/run rel/overlay/bin/couchup test/javascript/run

.PHONY: elixir
elixir: elixir-check-formatted devclean
elixir: elixir-check-formatted elixir-credo devclean
@dev/run -a adm:pass --no-eval test/elixir/run

.PHONY: elixir-check-formatted
elixir-check-formatted:
@cd test/elixir/ && mix format --check-formatted

# Credo is a static code analysis tool for Elixir.
# We use it in our tests
.PHONY: elixir-credo
Comment thread
wohali marked this conversation as resolved.
elixir-credo:
@cd test/elixir/ && mix deps.get && mix credo

Comment thread
wohali marked this conversation as resolved.
.PHONY: javascript
# target: javascript - Run JavaScript test suites or specific ones defined by suites option
javascript: devclean
Expand Down
8 changes: 7 additions & 1 deletion Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,19 @@ python-black-update: .venv/bin/black
. dev\run rel\overlay\bin\couchup test\javascript\run

.PHONY: elixir
elixir: elixir-check-formatted devclean
elixir: elixir-check-formatted elixir-credo devclean
@dev\run -a adm:pass --no-eval test\elixir\run.cmd

.PHONY: elixir-check-formatted
elixir-check-formatted:
@cd test\elixir && mix format --check-formatted

# Credo is a static code analysis tool for Elixir.
# We use it in our tests
.PHONY: elixir-credo
elixir-credo:
@cd test/elixir/ && mix deps.get && mix credo

.PHONY: test-cluster-with-quorum
test-cluster-with-quorum: devclean
-@mkdir share\www\script\test
Expand Down
153 changes: 153 additions & 0 deletions test/elixir/.credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# 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, false},
{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: :normal, max_length: 90]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{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, []},
{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, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, false},
{Credo.Check.Refactor.PipeChainStart,
[excluded_argument_types: [:atom, :binary, :fn, :keyword], 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 remove `, false`)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, 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`.
#
]
}
]
}
2 changes: 1 addition & 1 deletion test/elixir/.formatter.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 120,
line_length: 90,
rename_deprecated_at: "1.5.0"
]
41 changes: 35 additions & 6 deletions test/elixir/lib/couch.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
defmodule Couch.Session do
@moduledoc """
CouchDB session helpers.
"""

@enforce_keys [:cookie]
defstruct [:cookie]

Expand Down Expand Up @@ -155,18 +159,41 @@ defmodule Couch do
options = process_options(options)

body = Keyword.get(options, :body, "")
headers = Keyword.merge(Application.get_env(:httpotion, :default_headers, []), Keyword.get(options, :headers, []))
timeout = Keyword.get(options, :timeout, Application.get_env(:httpotion, :default_timeout, 5000))

headers =
Keyword.merge(
Application.get_env(:httpotion, :default_headers, []),
Keyword.get(options, :headers, [])
)

timeout =
Keyword.get(
options,
:timeout,
Application.get_env(:httpotion, :default_timeout, 5000)
)

ib_options =
Keyword.merge(Application.get_env(:httpotion, :default_ibrowse, []), Keyword.get(options, :ibrowse, []))
Keyword.merge(
Application.get_env(:httpotion, :default_ibrowse, []),
Keyword.get(options, :ibrowse, [])
)

follow_redirects =
Keyword.get(options, :follow_redirects, Application.get_env(:httpotion, :default_follow_redirects, false))
Keyword.get(
options,
:follow_redirects,
Application.get_env(:httpotion, :default_follow_redirects, false)
)

ib_options =
if stream_to = Keyword.get(options, :stream_to),
do: Keyword.put(ib_options, :stream_to, spawn(__MODULE__, :transformer, [stream_to, method, url, options])),
do:
Keyword.put(
ib_options,
:stream_to,
spawn(__MODULE__, :transformer, [stream_to, method, url, options])
),
else: ib_options

ib_options =
Expand All @@ -182,7 +209,9 @@ defmodule Couch do
url: url |> to_string |> process_url(options) |> to_charlist,
body: body |> process_request_body,
headers:
headers |> process_request_headers(options) |> Enum.map(fn {k, v} -> {to_charlist(k), to_charlist(v)} end),
headers
|> process_request_headers(options)
|> Enum.map(fn {k, v} -> {to_charlist(k), to_charlist(v)} end),
timeout: timeout,
ib_options: ib_options,
follow_redirects: follow_redirects
Expand Down
3 changes: 2 additions & 1 deletion test/elixir/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ defmodule Foo.Mixfile do
[
# {:dep_from_hexpm, "~> 0.3.0"},
{:httpotion, "~> 3.0"},
{:jiffy, "~> 0.15.2"}
{:jiffy, "~> 0.15.2"},
{:credo, "~> 1.0.0", only: [:dev, :test], runtime: false}
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
]
end
Expand Down
3 changes: 3 additions & 0 deletions test/elixir/mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"credo": {:hex, :credo, "1.0.0", "aaa40fdd0543a0cf8080e8c5949d8c25f0a24e4fc8c1d83d06c388f5e5e0ea42", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"httpotion": {:hex, :httpotion, "3.1.0", "14d20d9b0ce4e86e253eb91e4af79e469ad949f57a5d23c0a51b2f86559f6589", [:mix], [{:ibrowse, "~> 4.4", [hex: :ibrowse, repo: "hexpm", optional: false]}], "hexpm"},
"ibrowse": {:hex, :ibrowse, "4.4.1", "2b7d0637b0f8b9b4182de4bd0f2e826a4da2c9b04898b6e15659ba921a8d6ec2", [:rebar3], [], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"jiffy": {:hex, :jiffy, "0.15.2", "de266c390111fd4ea28b9302f0bc3d7472468f3b8e0aceabfbefa26d08cd73b7", [:rebar3], [], "hexpm"},
}
Loading