Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup elixir formatter #16

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
- run:
name: Run compile
command: mix compile
- run:
name: Elixir formatter
command: mix format --check-formatted --dry-run
- run:
name: Run Credo Linter
command: mix credo
- run:
name: Run migrations
command: mix ecto.migrate
Expand Down
159 changes: 159 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# 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: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
excluded: [~r"/_build/", ~r"/deps/"]
},
#
# 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_called_more_often_than: 2},
# For some checks, you can also set other parameters
#
# If you don't want the `setup` and `test` macro calls in ExUnit tests
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
#
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},
# 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.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc},
{Credo.Check.Readability.ModuleNames},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
{Credo.Check.Readability.ParenthesesInCondition},
{Credo.Check.Readability.PredicateFunctionNames},
{Credo.Check.Readability.PreferImplicitTry},
{Credo.Check.Readability.RedundantBlankLines},
{Credo.Check.Readability.StringSigils},
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.VariableNames},
{Credo.Check.Readability.Semicolons},
{Credo.Check.Readability.SpaceAfterCommas},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.LongQuoteBlocks},
{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], 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.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.RaiseInsideRescue},

#
# Controversial and experimental checks (opt-in, just remove `, false`)
#
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},

#
# Deprecated checks (these will be deleted after a grace period)
#
{Credo.Check.Readability.Specs, false}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
117 changes: 117 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copy parentheses rules from dependencies
# TODO: remove later when most of the rules can be imported directly from deps
locals_without_parens = [
# Phoenix.Channel
intercept: 1,

# Phoenix.Router
connect: 3,
connect: 4,
delete: 3,
delete: 4,
forward: 2,
forward: 3,
forward: 4,
get: 3,
get: 4,
head: 3,
head: 4,
match: 4,
match: 5,
options: 3,
options: 4,
patch: 3,
patch: 4,
pipeline: 2,
pipe_through: 1,
post: 3,
post: 4,
put: 3,
put: 4,
resources: 2,
resources: 3,
resources: 4,
trace: 4,

# Phoenix.Controller
action_fallback: 1,

# Phoenix.Endpoint
plug: 1,
plug: 2,
socket: 2,

# Phoenix.Socket
channel: 2,
channel: 3,

# Phoenix.ChannelTest
assert_broadcast: 2,
assert_broadcast: 3,
assert_push: 2,
assert_push: 3,
assert_reply: 2,
assert_reply: 3,
assert_reply: 4,
refute_broadcast: 2,
refute_broadcast: 3,
refute_push: 2,
refute_push: 3,
refute_reply: 2,
refute_reply: 3,
refute_reply: 4,

# Phoenix.ConnTest
assert_error_sent: 2,

# Ecto Query
from: 2,

# Ecto Schema
field: 1,
field: 2,
field: 3,
timestamps: 0,
timestamps: 1,
belongs_to: 2,
belongs_to: 3,
has_one: 2,
has_one: 3,
has_many: 2,
has_many: 3,
many_to_many: 2,
many_to_many: 3,
embeds_one: 2,
embeds_one: 3,
embeds_one: 4,
embeds_many: 2,
embeds_many: 3,
embeds_many: 4,

# Plug
plug: 1,
plug: 2,
forward: 2,
forward: 3,
forward: 4,
match: 2,
match: 3,
get: 2,
get: 3,
post: 2,
post: 3,
put: 2,
put: 3,
patch: 2,
patch: 3,
delete: 2,
delete: 3,
options: 2,
options: 3
]

[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 100,
locals_without_parens: locals_without_parens
]
27 changes: 14 additions & 13 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
use Mix.Config

# General application configuration
config :sejfguru,
ecto_repos: [Sejfguru.Repo]
config :sejfguru, ecto_repos: [Sejfguru.Repo]

# Configures the endpoint
config :sejfguru, SejfguruWeb.Endpoint,
url: [host: "localhost"],
render_errors: [view: SejfguruWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: Sejfguru.PubSub,
adapter: Phoenix.PubSub.PG2]
pubsub: [name: Sejfguru.PubSub, adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
Expand All @@ -31,8 +29,7 @@ config :sejfguru, SejfguruWeb.AuthRequiredPipeline,
module: SejfguruWeb.Guardian,
error_handler: SejfguruWeb.AuthErrorHandler

config :sejfguru, SejfguruWeb.Endpoint,
secret_key_base: System.get_env("SECRET_KEY_BASE")
config :sejfguru, SejfguruWeb.Endpoint, secret_key_base: System.get_env("SECRET_KEY_BASE")

config :sejfguru, Sejfguru.Repo,
adapter: Ecto.Adapters.Postgres,
Expand All @@ -43,20 +40,24 @@ config :sejfguru, Sejfguru.Repo,
port: System.get_env("DB_PORT"),
pool_size: 10

config :sejfguru, SejfguruWeb.Guardian,
secret_key: System.get_env("GUARDIAN_SECRET_KEY_BASE")
config :sejfguru, SejfguruWeb.Guardian, secret_key: System.get_env("GUARDIAN_SECRET_KEY_BASE")

config :ueberauth, Ueberauth,
providers: [
google: {Ueberauth.Strategy.Google, [
request_path: "/auth", callback_path: "/auth-callback", default_scope: "email profile",
hd: System.get_env("UEBERAUTH_GOOGLE_DOMAIN")
]}
google:
{Ueberauth.Strategy.Google,
[
request_path: "/auth",
callback_path: "/auth-callback",
default_scope: "email profile",
hd: System.get_env("UEBERAUTH_GOOGLE_DOMAIN")
]}
]

config :ueberauth, Ueberauth.Strategy.Google.OAuth,
client_id: System.get_env("UEBERAUTH_GOOGLE_CLIENT_ID"),
client_secret: System.get_env("UEBERAUTH_GOOGLE_CLIENT_SECRET")

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
import_config "#{Mix.env()}.exs"
10 changes: 8 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ config :sejfguru, SejfguruWeb.Endpoint,
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
cd: Path.expand("../assets", __DIR__)]]
watchers: [
node: [
"node_modules/brunch/bin/brunch",
"watch",
"--stdin",
cd: Path.expand("../assets", __DIR__)
]
]

# ## SSL Support
#
Expand Down
9 changes: 8 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ config :sejfguru, SejfguruWeb.Guardian,

config :ueberauth, Ueberauth,
providers: [
google: {Ueberauth.Strategy.Google, [request_path: "/auth", callback_path: "/auth-callback", default_scope: "email", hd: "example.com"]}
google:
{Ueberauth.Strategy.Google,
[
request_path: "/auth",
callback_path: "/auth-callback",
default_scope: "email",
hd: "example.com"
]}
]

config :ueberauth, Ueberauth.Strategy.Google.OAuth,
Expand Down
Loading