Skip to content

Commit

Permalink
Merge pull request #6 from brentjr/add-credo-ci-and-some-docs
Browse files Browse the repository at this point in the history
Add credo, ci, and some docs
  • Loading branch information
brentjr authored Jun 28, 2023
2 parents d882bba + 3cbc223 commit 5e42aad
Show file tree
Hide file tree
Showing 23 changed files with 306 additions and 28 deletions.
209 changes: 209 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# 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 <name>`. 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: %{
enabled: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{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.ImplTrue, []},
{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, []},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StrictModuleLayout, [order: [:shortdoc, :moduledoc, :behaviour, :use, :import, :alias, :require], ignore: [:defstruct]]},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
{Credo.Check.Readability.WithSingleClause, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.ABCSize, [max_size: 60]},
{Credo.Check.Refactor.Apply, []},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, [max_complexity: 10]},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.MapJoin, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},
{Credo.Check.Refactor.FilterFilter, []},
{Credo.Check.Refactor.RejectReject, []},
{Credo.Check.Refactor.RedundantWithClauseResult, []},

#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.SpecWithStruct, []},
{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.WrongTestFileExtension, []},
{Credo.Check.Warning.UnusedTupleOperation, []},
{Credo.Check.Warning.UnsafeExec, []},
# {Credo.Check.Warning.UnsafeToAtom, []}
],
disabled: [
#
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)

#
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
# and be sure to use `mix credo --strict` to see low priority checks)
#
{Credo.Check.Consistency.UnusedVariableNames, []},
{Credo.Check.Design.DuplicatedCode, []},
{Credo.Check.Design.SkipTestWithoutComment, []},
{Credo.Check.Readability.AliasAs, []},
{Credo.Check.Readability.BlockPipe, []},
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.FilterReject, []},
{Credo.Check.Refactor.IoPuts, []},
{Credo.Check.Refactor.MapMap, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.RejectFilter, []},
{Credo.Check.Refactor.VariableRebinding, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},

# {Credo.Check.Refactor.MapInto, []},

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
}
]
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# add github group owner for ex_twilio only
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
setup:
runs-on: ubuntu-latest
env:
MIX_ENV: test
TWILIO_TEST_ACCOUNT_SID: ""
TWILIO_TEST_AUTH_TOKEN: "test-auth-token"

strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04, ubuntu-20.04]
elixir_version: [1.12.3, 1.13.3, 1.14.1]
otp_version: [24, 25]
exclude:
- otp_version: 25
elixir_version: 1.12.3
steps:
- uses: actions/checkout@v3

- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp_version}}
elixir-version: ${{matrix.elixir_version}}

- uses: actions/cache@v3
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ matrix.otp_version }}-${{ matrix.elixir_version }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
deps-${{ runner.os }}-${{ matrix.otp_version }}-${{ matrix.elixir_version }}
- run: mix deps.get

- run: mix format --check-formatted

- run: mix deps.unlock --check-unused

- run: mix deps.compile

- run: mix compile --warnings-as-errors

- run: mix credo --strict --format=oneline

- run: mix test --warnings-as-errors
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

import_config "#{Mix.env()}.exs"
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :ex_twilio,
account_sid: {:system, "TWILIO_ACCOUNT_SID"},
Expand Down
2 changes: 1 addition & 1 deletion config/docs.exs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use Mix.Config
import Config
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :ex_twilio,
account_sid: {:system, "TWILIO_TEST_ACCOUNT_SID"},
Expand Down
9 changes: 9 additions & 0 deletions guides/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Local Development configuration

## Env vars

| Name | Description | Default value |
| - | - | - |
| `TWILIO_ACCOUNT_SID` | Sid of twilio account. | `null` |
| `TWILIO_AUTH_TOKEN` | Auth token for twilio account. | `null` |
| `TWILIO_WORKSPACE_SID` | Workspace sid for twilio account. | `null` |
3 changes: 1 addition & 2 deletions lib/ex_twilio/capability.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ defmodule ExTwilio.Capability do
"xxxxx.yyyyy.zzzzz"
"""

alias ExTwilio.Config
use Joken.Config
alias ExTwilio.Config

defstruct incoming_client_names: [],
outgoing_client_app: nil,
Expand Down
5 changes: 2 additions & 3 deletions lib/ex_twilio/jwt/access_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ defmodule ExTwilio.JWT.AccessToken do
https://www.twilio.com/docs/iam/access-tokens
"""

alias ExTwilio.JWT.Grant
alias ExTwilio.Ext
use Joken.Config
alias ExTwilio.Ext
alias ExTwilio.JWT.Grant

@enforce_keys [:account_sid, :api_key, :api_secret, :identity, :grants, :expires_in]

Expand Down
7 changes: 2 additions & 5 deletions lib/ex_twilio/request_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ defmodule ExTwilio.RequestValidator do
- [Twilio docs](https://www.twilio.com/docs/usage/security)
"""

import Bitwise
alias ExTwilio.Config

use Bitwise

def valid?(url, params, signature) do
valid?(url, params, signature, Config.auth_token())
end
Expand All @@ -28,8 +26,7 @@ defmodule ExTwilio.RequestValidator do
params
|> Map.keys()
|> Enum.sort()
|> Enum.map(fn key -> key <> Map.get(params, key) end)
|> Enum.join()
|> Enum.map_join(fn key -> key <> Map.get(params, key) end)
end

defp compute_hmac(data, key), do: hmac(:sha, key, data)
Expand Down
14 changes: 9 additions & 5 deletions lib/ex_twilio/resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ defmodule ExTwilio.Resource do
quote bind_quoted: [import_functions: import_functions] do
alias ExTwilio.Api
alias ExTwilio.Parser
alias ExTwilio.UrlGenerator, as: Url
alias ExTwilio.ResultStream
alias ExTwilio.UrlGenerator, as: Url

@spec new :: %__MODULE__{}
def new, do: %__MODULE__{}
Expand Down Expand Up @@ -59,22 +59,26 @@ defmodule ExTwilio.Resource do

if :find in import_functions do
@spec find(String.t() | nil, list, list) :: Parser.parsed_list_response()
def find(sid, options \\ [], request_opts \\ []), do: Api.find(__MODULE__, sid, options, request_opts)
def find(sid, options \\ [], request_opts \\ []),
do: Api.find(__MODULE__, sid, options, request_opts)
end

if :create in import_functions do
@spec create(Api.data(), list, list) :: Parser.parsed_response()
def create(data, options \\ [], request_opts \\ []), do: Api.create(__MODULE__, data, options, request_opts)
def create(data, options \\ [], request_opts \\ []),
do: Api.create(__MODULE__, data, options, request_opts)
end

if :update in import_functions do
@spec update(String.t(), Api.data(), list, list) :: Parser.parsed_response()
def update(sid, data, options \\ [], request_opts \\ []), do: Api.update(__MODULE__, sid, data, options, request_opts)
def update(sid, data, options \\ [], request_opts \\ []),
do: Api.update(__MODULE__, sid, data, options, request_opts)
end

if :destroy in import_functions do
@spec destroy(String.t(), list, list) :: Parser.success_delete() | Parser.error()
def destroy(sid, options \\ [], request_opts \\ []), do: Api.destroy(__MODULE__, sid, options, request_opts)
def destroy(sid, options \\ [], request_opts \\ []),
do: Api.destroy(__MODULE__, sid, options, request_opts)
end

@doc """
Expand Down
1 change: 1 addition & 0 deletions lib/ex_twilio/resources/add_on/installed_add_on.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ExTwilio.InstalledAddOn do
@moduledoc false
defstruct [
:sid,
:account_sid,
Expand Down
Loading

0 comments on commit 5e42aad

Please sign in to comment.