Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 31b6062

Browse files
committed
Including strict warnings
1 parent be9bbb7 commit 31b6062

File tree

4 files changed

+110
-12
lines changed

4 files changed

+110
-12
lines changed

config/.credo.exs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# This file contains the configuration for Credo.
2+
#
3+
# If you find anything wrong or unclear in this file, please report an
4+
# issue on GitHub: https://github.com/rrrene/credo/issues
5+
%{
6+
#
7+
# You can have as many configs as you like in the `configs:` field.
8+
configs: [
9+
%{
10+
#
11+
# Run any config using `mix credo -C <name>`. If no config name is given
12+
# "default" is used.
13+
name: "default",
14+
#
15+
# these are the files included in the analysis
16+
files: %{
17+
#
18+
# you can give explicit globs or simply directories
19+
# in the latter case `**/*.{ex,exs}` will be used
20+
included: ["lib/", "src/", "web/", "apps/"],
21+
excluded: []
22+
},
23+
#
24+
# The `checks:` field contains all the checks that are run. You can
25+
# customize the parameters of any given check by adding a second element
26+
# to the tuple.
27+
#
28+
# There are two ways of deactivating a check:
29+
# 1. deleting the check from this list
30+
# 2. putting `false` as second element (to quickly "comment it out"):
31+
#
32+
# {Credo.Check.Consistency.ExceptionNames, false}
33+
#
34+
checks: [
35+
{Credo.Check.Consistency.ExceptionNames},
36+
{Credo.Check.Consistency.LineEndings},
37+
{Credo.Check.Consistency.SpaceAroundOperators},
38+
{Credo.Check.Consistency.SpaceInParentheses},
39+
{Credo.Check.Consistency.TabsOrSpaces},
40+
41+
# For some checks, like AliasUsage, you can only customize the priority
42+
# Priority values are: `low, normal, high, higher`
43+
{Credo.Check.Design.AliasUsage, priority: :low},
44+
# For others you can set parameters
45+
{Credo.Check.Design.DuplicatedCode, mass_threshold: 16, nodes_threshold: 2},
46+
47+
# You can also customize the exit_status of each check.
48+
# If you don't want TODO comments to cause `mix credo` to fail, just
49+
# set this value to 0 (zero).
50+
{Credo.Check.Design.TagTODO, false},
51+
{Credo.Check.Design.TagFIXME},
52+
53+
{Credo.Check.Readability.FunctionNames},
54+
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 120},
55+
{Credo.Check.Readability.ModuleAttributeNames},
56+
{Credo.Check.Readability.ModuleDoc},
57+
{Credo.Check.Readability.ModuleNames},
58+
{Credo.Check.Readability.PredicateFunctionNames},
59+
{Credo.Check.Readability.TrailingBlankLine},
60+
{Credo.Check.Readability.TrailingWhiteSpace},
61+
{Credo.Check.Readability.VariableNames},
62+
63+
{Credo.Check.Refactor.ABCSize},
64+
{Credo.Check.Refactor.CaseTrivialMatches},
65+
{Credo.Check.Refactor.CondStatements},
66+
{Credo.Check.Refactor.FunctionArity},
67+
{Credo.Check.Refactor.MatchInCondition},
68+
{Credo.Check.Refactor.PipeChainStart},
69+
{Credo.Check.Refactor.CyclomaticComplexity},
70+
{Credo.Check.Refactor.NegatedConditionsInUnless},
71+
{Credo.Check.Refactor.NegatedConditionsWithElse},
72+
{Credo.Check.Refactor.Nesting},
73+
{Credo.Check.Refactor.UnlessWithElse},
74+
75+
{Credo.Check.Warning.IExPry},
76+
{Credo.Check.Warning.IoInspect},
77+
{Credo.Check.Warning.NameRedeclarationByAssignment},
78+
{Credo.Check.Warning.NameRedeclarationByCase},
79+
{Credo.Check.Warning.NameRedeclarationByDef},
80+
{Credo.Check.Warning.NameRedeclarationByFn},
81+
{Credo.Check.Warning.OperationOnSameValues},
82+
{Credo.Check.Warning.UnusedEnumOperation},
83+
{Credo.Check.Warning.UnusedKeywordOperation},
84+
{Credo.Check.Warning.UnusedListOperation},
85+
{Credo.Check.Warning.UnusedStringOperation},
86+
{Credo.Check.Warning.UnusedTupleOperation},
87+
{Credo.Check.Warning.OperationWithConstantResult},
88+
]
89+
}
90+
]
91+
}

lib/graphql/plug.ex

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,28 @@ defmodule GraphQL.Plug do
1818
"""
1919

2020
use Plug.Builder
21+
alias GraphQL.Schema
22+
alias GraphQL.Plug.{GraphiQL, Endpoint}
23+
alias Plug.Parsers
2124

2225
require Logger
2326

24-
plug Plug.Parsers,
27+
plug Parsers,
2528
parsers: [:graphql, :urlencoded, :multipart, :json],
2629
pass: ["*/*"],
2730
json_decoder: Poison
2831

2932
@type init :: %{
30-
schema: GraphQL.Schema.t,
33+
schema: Schema.t,
3134
root_value: ConfigurableValue.t,
3235
query: ConfigurableValue.t,
3336
allow_graphiql?: true | false
3437
}
3538

3639
@spec init(Map) :: init
3740
def init(opts) do
38-
graphiql = GraphQL.Plug.GraphiQL.init(opts)
39-
endpoint = GraphQL.Plug.Endpoint.init(opts)
41+
graphiql = GraphiQL.init(opts)
42+
endpoint = Endpoint.init(opts)
4043

4144
opts = Keyword.merge(graphiql, endpoint)
4245
Enum.dedup(opts)
@@ -45,10 +48,10 @@ defmodule GraphQL.Plug do
4548
def call(conn, opts) do
4649
conn = super(conn, opts)
4750

48-
conn = if GraphQL.Plug.GraphiQL.use_graphiql?(conn, opts) do
49-
GraphQL.Plug.GraphiQL.call(conn, opts)
51+
conn = if GraphiQL.use_graphiql?(conn, opts) do
52+
GraphiQL.call(conn, opts)
5053
else
51-
GraphQL.Plug.Endpoint.call(conn, opts)
54+
Endpoint.call(conn, opts)
5255
end
5356

5457
# TODO consider not logging instrospection queries

lib/graphql/plug/configurable_value.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ defmodule GraphQL.Plug.ConfigurableValue do
99
an arity of 1 accepting a `Plug.Conn`.
1010
"""
1111

12-
@type t :: {module, atom} | (Plug.Conn.t -> Map) | Map | nil
13-
@spec evaluate(Plug.Conn.t, t, any) :: Map
12+
alias Plug.Conn
13+
14+
@type t :: {module, atom} | (Conn.t -> Map) | Map | nil
15+
@spec evaluate(Conn.t, t, any) :: Map
1416

1517
@error_msg "Configured function must only be arity of 1 that accepts a value of Plug.Conn"
1618

lib/graphql/plug/parameter.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ defmodule GraphQL.Plug.Parameter do
44
value from `Plug.Conn`
55
"""
66

7-
@spec operation_name(Plug.Conn.t) :: String.t
7+
alias Plug.Conn
8+
9+
@spec operation_name(Conn.t) :: String.t
810
def operation_name(conn) do
911
conn
1012
|> operation_name_params
1113
|> cleanup_string
1214
end
1315

14-
@spec query(Plug.Conn.t) :: String.t | nil
16+
@spec query(Conn.t) :: String.t | nil
1517
def query(conn) do
1618
conn.params
1719
|> Map.get("query")
1820
|> cleanup_string
1921
end
2022

21-
@spec variables(Plug.Conn.t) :: Map
23+
@spec variables(Conn.t) :: Map
2224
def variables(conn) do
2325
decode_variables(Map.get(conn.params, "variables", %{}))
2426
end

0 commit comments

Comments
 (0)