Skip to content

Commit

Permalink
Add Styler as a new formatter (#437)
Browse files Browse the repository at this point in the history
Add a new formatter to the project. The credo config was changed since some of the formatting will be done by Styler instead of Credo.
  • Loading branch information
MathieuLegault1 authored Nov 14, 2023
1 parent 419a1c5 commit 7faa13f
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 30 deletions.
38 changes: 21 additions & 17 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# 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, []},
Expand All @@ -27,46 +26,30 @@
{Credo.Check.Design.TagFIXME, []},

# Readability Checks
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 200]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, false},
{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.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: 40},
{Credo.Check.Refactor.Apply, []},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{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.PipeChainStart, [excluded_argument_types: ~w(atom binary fn keyword)a, excluded_functions: ~w(from)]},
{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, []},
Expand Down Expand Up @@ -97,30 +80,51 @@
],
disabled: [
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.UnusedVariableNames, []},
{Credo.Check.Design.DuplicatedCode, []},
{Credo.Check.Design.SkipTestWithoutComment, []},
{Credo.Check.Readability.AliasAs, []},
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.BlockPipe, []},
{Credo.Check.Readability.ImplTrue, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.ModuleDoc, false},
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.NestedFunctionCalls, []},
{Credo.Check.Readability.OneArityFunctionInPipe, false},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{Credo.Check.Readability.WithSingleClause, []},
{Credo.Check.Refactor.ABCSize, []},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.CaseTrivialMatches, false},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.FilterCount, false},
{Credo.Check.Refactor.FilterReject, []},
{Credo.Check.Refactor.IoPuts, []},
{Credo.Check.Refactor.MapInto, false},
{Credo.Check.Refactor.MapJoin, []},
{Credo.Check.Refactor.MapMap, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PipeChainStart, [excluded_argument_types: ~w(atom binary fn keyword)a, excluded_functions: ~w(from)]},
{Credo.Check.Refactor.RedundantWithClauseResult, []},
{Credo.Check.Refactor.RejectFilter, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.VariableRebinding, []},
{Credo.Check.Refactor.WithClauses, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
Expand Down
3 changes: 2 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
inputs: ["*.exs", "{config,lib,priv,rel,test}/**/*.{ex,exs}"],
line_length: 180
line_length: 180,
plugins: [Styler]
]
1 change: 1 addition & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Config

defmodule TestEnvironment do
@moduledoc false
@database_name_suffix "_test"

def get_database_url do
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate/release.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplate.Release do
@moduledoc false
alias Ecto.Migrator

@app :elixir_boilerplate
Expand Down
4 changes: 3 additions & 1 deletion lib/elixir_boilerplate/schema.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
defmodule ElixirBoilerplate.Schema do
@moduledoc false
defmacro __using__(_) do
quote do
use Ecto.Schema

import Ecto.Changeset

alias Ecto.{Schema, UUID}
alias Ecto.Schema
alias Ecto.UUID

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_graphql/application/types.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateGraphQL.Application.Types do
@moduledoc false
use Absinthe.Schema.Notation

object :application do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateGraphQL do
@moduledoc false
alias Absinthe.Phase.Document.Result
alias ElixirBoilerplateGraphQL.Middleware

Expand Down
2 changes: 2 additions & 0 deletions lib/elixir_boilerplate_graphql/middleware/error_reporting.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defmodule ElixirBoilerplateGraphQL.Middleware.ErrorReporting do
@moduledoc false
defmodule Error do
@moduledoc false
defexception [:message]
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateGraphQL.Middleware.OperationNameLogger do
@moduledoc false
def run(blueprint, _opts) do
operation_name = Absinthe.Blueprint.current_operation(blueprint).name || "#NULL"
Logger.metadata(graphql_operation_name: operation_name)
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_graphql/plugs/context.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateGraphQL.Plugs.Context do
@moduledoc false
@behaviour Plug

import Plug.Conn
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_graphql/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule ElixirBoilerplateGraphQL.Router do
use Plug.Router

defmodule GraphQL do
@moduledoc false
use Plug.Router

plug(:match)
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_graphql/schema.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateGraphQL.Schema do
@moduledoc false
use Absinthe.Schema

import_types(Absinthe.Type.Custom)
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_health/elixir_boilerplate_health.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateHealth do
@moduledoc false
@health_check_error_code 422

def checks do
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_health/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule ElixirBoilerplateHealth.Router do
use Plug.Router

defmodule Health do
@moduledoc false
use Plug.Router

plug(:match)
Expand Down
5 changes: 3 additions & 2 deletions lib/elixir_boilerplate_web/errors/errors.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
defmodule ElixirBoilerplateWeb.Errors do
alias Ecto.Changeset

@moduledoc false
import Phoenix.Template, only: [embed_templates: 1]

alias Ecto.Changeset

embed_templates("templates/*")

@doc """
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_web/home/live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateWeb.Home.Live do
@moduledoc false
use Phoenix.LiveView, layout: {ElixirBoilerplateWeb.Layouts, :live}

def mount(_, _, socket) do
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_web/layouts/layouts.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateWeb.Layouts do
@moduledoc false
use Phoenix.Component

alias ElixirBoilerplateWeb.Router.Helpers, as: Routes
Expand Down
9 changes: 5 additions & 4 deletions lib/elixir_boilerplate_web/plugs/security.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
defmodule ElixirBoilerplateWeb.Plugs.Security do
@moduledoc false
@behaviour Plug

import Phoenix.Controller, only: [put_secure_browser_headers: 2]

@doc """
This plug adds Phoenix secure HTTP headers including a
“Content-Security-Policy” header to responses.You will need to customize each
policy directive to fit your application needs.
"""

@behaviour Plug

import Phoenix.Controller, only: [put_secure_browser_headers: 2]

def init(opts), do: opts

def call(conn, _) do
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_web/router.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule ElixirBoilerplateWeb.Router do
use Phoenix.Router

import Phoenix.LiveView.Router

pipeline :browser do
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_boilerplate_web/session.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplateWeb.Session do
@moduledoc false
def config do
[
store: :cookie,
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ defmodule ElixirBoilerplate.Mixfile do
{:credo, "~> 1.7", only: [:dev, :test], override: true},
{:credo_envvar, "~> 0.1", only: [:dev, :test], runtime: false},
{:credo_naming, "~> 2.0", only: [:dev, :test], runtime: false},
{:styler, "~> 0.10", only: [:dev, :test], runtime: false},

# Security check
{:sobelow, "~> 0.12", only: [:dev, :test], runtime: true},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"sentry": {:hex, :sentry, "9.1.0", "8689b85774003ddcebfd9d48a93bc3f3bf72223983514521aa30645c6f204f86", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, "~> 2.3", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm", "d70c88ab0c6a511594856ae2244d1bd70b8b7a4a42201a3569880f1dd2a3adec"},
"sobelow": {:hex, :sobelow, "0.13.0", "218afe9075904793f5c64b8837cc356e493d88fddde126a463839351870b8d1e", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cd6e9026b85fc35d7529da14f95e85a078d9dd1907a9097b3ba6ac7ebbe34a0d"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"styler": {:hex, :styler, "0.10.1", "f39d632c6474023c5e65434db3c0007405d1262cf45f9f886ce251372aaea294", [:mix], [], "hexpm", "e341d7d11b749d05e277b7971dad931c7eb6718f8b14a54fde728e8296791870"},
"table": {:hex, :table, "0.1.2", "87ad1125f5b70c5dea0307aa633194083eb5182ec537efc94e96af08937e14a8", [:mix], [], "hexpm", "7e99bc7efef806315c7e65640724bf165c3061cdc5d854060f74468367065029"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
Expand Down
1 change: 1 addition & 0 deletions test/elixir_boilerplate/gettext_interpolation_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplate.GettextInterpolationTest do
use ExUnit.Case, async: true

doctest ElixirBoilerplate.GettextInterpolation, import: true
end
2 changes: 2 additions & 0 deletions test/elixir_boilerplate_web/errors_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule ElixirBoilerplateWeb.ErrorsTest do
alias ElixirBoilerplateWeb.Errors

defmodule UserRole do
@moduledoc false
use Ecto.Schema

import Ecto.Changeset
Expand All @@ -23,6 +24,7 @@ defmodule ElixirBoilerplateWeb.ErrorsTest do
end

defmodule User do
@moduledoc false
use Ecto.Schema

import Ecto.Changeset
Expand Down
5 changes: 2 additions & 3 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ defmodule ElixirBoilerplateWeb.ConnCase do
using do
quote do
# Import conveniences for testing with connections
import Plug.Conn
import Phoenix.ConnTest

import ElixirBoilerplateWeb.Router.Helpers
import Phoenix.ConnTest
import Plug.Conn

# The default endpoint for testing
@endpoint Endpoint
Expand Down
4 changes: 2 additions & 2 deletions test/support/data_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ defmodule ElixirBoilerplate.DataCase do

using do
quote do
alias ElixirBoilerplate.Repo

import Ecto
import Ecto.Changeset
import Ecto.Query
import ElixirBoilerplate.DataCase

alias ElixirBoilerplate.Repo
end
end

Expand Down
1 change: 1 addition & 0 deletions test/support/factory.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ElixirBoilerplate.Factory do
@moduledoc false
use ExMachina.Ecto, repo: ElixirBoilerplate.Repo

# This is a sample factory to make sure our setup is working correctly.
Expand Down

0 comments on commit 7faa13f

Please sign in to comment.