Browse Source

Patch to let repo use Confex to get config.

jackyalcine 6 months ago
parent
commit
5fe409f3a0
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D
2 changed files with 13 additions and 97 deletions
  1. 9
    91
      .credo.exs
  2. 4
    6
      lib/repo.ex

+ 9
- 91
.credo.exs View File

@@ -1,91 +1,29 @@
1
-# This file contains the configuration for Credo and you are probably reading
2
-# this after creating it with `mix credo.gen.config`.
3
-#
4
-# If you find anything wrong or unclear in this file, please report an
5
-# issue on GitHub: https://github.com/rrrene/credo/issues
6
-#
7 1
 %{
8
-  #
9
-  # You can have as many configs as you like in the `configs:` field.
10 2
   configs: [
11 3
     %{
12
-      #
13
-      # Run any exec using `mix credo -C <name>`. If no exec name is given
14
-      # "default" is used.
15
-      #
16 4
       name: "default",
17
-      #
18
-      # These are the files included in the analysis:
19 5
       files: %{
20
-        #
21
-        # You can give explicit globs or simply directories.
22
-        # In the latter case `**/*.{ex,exs}` will be used.
23
-        #
24 6
         included: ["lib/", "src/", "test/", "web/", "apps/"],
25 7
         excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
26 8
       },
27
-      #
28
-      # If you create your own checks, you must specify the source files for
29
-      # them here, so they can be loaded by Credo before running the analysis.
30
-      #
31 9
       requires: [],
32
-      #
33
-      # If you want to enforce a style guide and need a more traditional linting
34
-      # experience, you can change `strict` to `true` below:
35
-      #
36
-      strict: false,
37
-      #
38
-      # If you want to use uncolored output by default, you can change `color`
39
-      # to `false` below:
40
-      #
10
+      strict: true,
41 11
       color: true,
42
-      #
43
-      # You can customize the parameters of any check by adding a second element
44
-      # to the tuple.
45
-      #
46
-      # To disable a check put `false` as second element:
47
-      #
48
-      #     {Credo.Check.Design.DuplicatedCode, false}
49
-      #
50 12
       checks: [
51
-        #
52
-        ## Consistency Checks
53
-        #
54 13
         {Credo.Check.Consistency.ExceptionNames, []},
55 14
         {Credo.Check.Consistency.LineEndings, []},
56 15
         {Credo.Check.Consistency.ParameterPatternMatching, []},
57 16
         {Credo.Check.Consistency.SpaceAroundOperators, []},
58 17
         {Credo.Check.Consistency.SpaceInParentheses, []},
59 18
         {Credo.Check.Consistency.TabsOrSpaces, []},
60
-
61
-        #
62
-        ## Design Checks
63
-        #
64
-        # You can customize the priority of any check
65
-        # Priority values are: `low, normal, high, higher`
66
-        #
67
-        {Credo.Check.Design.AliasUsage, [priority: :low]},
68
-        # For some checks, you can also set other parameters
69
-        #
70
-        # If you don't want the `setup` and `test` macro calls in ExUnit tests
71
-        # or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
72
-        # set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
73
-        #
19
+        {Credo.Check.Design.AliasUsage, [priority: :medium]},
74 20
         {Credo.Check.Design.DuplicatedCode, [excluded_macros: []]},
75
-        # You can also customize the exit_status of each check.
76
-        # If you don't want TODO comments to cause `mix credo` to fail, just
77
-        # set this value to 0 (zero).
78
-        #
79
-        {Credo.Check.Design.TagTODO, [exit_status: 2]},
80
-        {Credo.Check.Design.TagFIXME, []},
81
-
82
-        #
83
-        ## Readability Checks
84
-        #
21
+        {Credo.Check.Design.TagTODO, [exit_status: 0]},
22
+        {Credo.Check.Design.TagFIXME, [exit_status: 0]},
85 23
         {Credo.Check.Readability.AliasOrder, []},
86 24
         {Credo.Check.Readability.FunctionNames, []},
87 25
         {Credo.Check.Readability.LargeNumbers, []},
88
-        {Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
26
+        {Credo.Check.Readability.MaxLineLength, [priority: :high, max_length: 100]},
89 27
         {Credo.Check.Readability.ModuleAttributeNames, []},
90 28
         {Credo.Check.Readability.ModuleDoc, []},
91 29
         {Credo.Check.Readability.ModuleNames, []},
@@ -100,10 +38,6 @@
100 38
         {Credo.Check.Readability.VariableNames, []},
101 39
         {Credo.Check.Readability.Semicolons, []},
102 40
         {Credo.Check.Readability.SpaceAfterCommas, []},
103
-
104
-        #
105
-        ## Refactoring Opportunities
106
-        #
107 41
         {Credo.Check.Refactor.DoubleBooleanNegation, []},
108 42
         {Credo.Check.Refactor.CondStatements, []},
109 43
         {Credo.Check.Refactor.CyclomaticComplexity, []},
@@ -117,10 +51,6 @@
117 51
         {Credo.Check.Refactor.PipeChainStart,
118 52
          [excluded_argument_types: [:atom, :binary, :fn, :keyword], excluded_functions: []]},
119 53
         {Credo.Check.Refactor.UnlessWithElse, []},
120
-
121
-        #
122
-        ## Warnings
123
-        #
124 54
         {Credo.Check.Warning.BoolOperationOnSameValues, []},
125 55
         {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
126 56
         {Credo.Check.Warning.IExPry, []},
@@ -137,24 +67,12 @@
137 67
         {Credo.Check.Warning.UnusedStringOperation, []},
138 68
         {Credo.Check.Warning.UnusedTupleOperation, []},
139 69
         {Credo.Check.Warning.RaiseInsideRescue, []},
140
-
141
-        #
142
-        # Controversial and experimental checks (opt-in, just remove `, false`)
143
-        #
144
-        {Credo.Check.Refactor.ABCSize, false},
145
-        {Credo.Check.Refactor.AppendSingleItem, false},
146
-        {Credo.Check.Refactor.VariableRebinding, false},
70
+        {Credo.Check.Refactor.ABCSize, true},
71
+        {Credo.Check.Refactor.AppendSingleItem, true},
72
+        {Credo.Check.Refactor.VariableRebinding, true},
147 73
         {Credo.Check.Warning.MapGetUnsafePass, false},
148
-        {Credo.Check.Consistency.MultiAliasImportRequireUse, false},
149
-
150
-        #
151
-        # Deprecated checks (these will be deleted after a grace period)
152
-        #
74
+        {Credo.Check.Consistency.MultiAliasImportRequireUse, true},
153 75
         {Credo.Check.Readability.Specs, false}
154
-
155
-        #
156
-        # Custom checks can be created using `mix credo.gen.check`.
157
-        #
158 76
       ]
159 77
     }
160 78
   ]

+ 4
- 6
lib/repo.ex View File

@@ -20,14 +20,12 @@ defmodule Koype.Repo do
20 20
   use Ecto.Repo, otp_app: :koype, adapter: Sqlite.Ecto2
21 21
   use Scrivener, page_size: 10
22 22
   import Ecto.Query, only: [from: 2, order_by: 2]
23
+  require Logger
23 24
 
24 25
   def init(_type, config) do
25
-    case Confex.fetch_env(:koype, :database) do
26
-      {:ok, path} ->
27
-        {:ok, Keyword.put(config, :database, path)}
28
-
29
-      _ ->
30
-        {:ok, config}
26
+    case Confex.fetch_env(:koype, Koype.Repo) do
27
+      {:ok, resolved_config} -> {:ok, Keyword.merge(config, resolved_config)}
28
+      _ -> {:ok, config}
31 29
     end
32 30
   end
33 31
 

Loading…
Cancel
Save