Skip to content

Commit cf69835

Browse files
feat: Add credo and mix_audit
1 parent 9b8c895 commit cf69835

File tree

7 files changed

+102
-9
lines changed

7 files changed

+102
-9
lines changed

.config/credo.exs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%{
2+
configs: [
3+
%{
4+
name: "default",
5+
files: %{
6+
included: ["lib/", "test/"],
7+
excluded: [~r"/_build/", ~r"/deps/"]
8+
},
9+
color: true
10+
}
11+
]
12+
}

.config/mix_audit.exs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
%{
2+
configs: [
3+
%{
4+
name: "default",
5+
ignore: [
6+
# Add any dependencies to ignore here
7+
# Example: {:package_name, "reason for ignoring"}
8+
],
9+
only: [
10+
# Add specific dependencies to check here
11+
# Example: {:package_name, "reason for checking"}
12+
]
13+
}
14+
]
15+
}

.github/workflows/ci.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ jobs:
6060
- name: Run tests
6161
run: mix test
6262

63-
format:
64-
name: Format code
63+
static-checks:
64+
name: Static checks
6565
runs-on: ubuntu-latest
6666
steps:
6767
- uses: actions/checkout@v3
@@ -88,3 +88,9 @@ jobs:
8888

8989
- name: Check formatting
9090
run: mix format --check-formatted
91+
92+
- name: Run static checks
93+
run: mix credo --strict
94+
95+
- name: Run audit
96+
run: mix deps.audit

README.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,48 @@ To persist this setting, add it to your shell configuration file (`~/.bashrc`, `
299299

300300
There's an example console project in `examples/feature_flag_demo` that shows how to use the client. Follow the instructions in [the README](examples/feature_flag_demo/README.md) to run it.
301301

302+
## Development Tools
303+
304+
This project uses several development tools to maintain code quality and security:
305+
306+
### Credo
307+
308+
Credo is a static code analysis tool that helps enforce coding standards and catch potential issues. Run it with:
309+
310+
```bash
311+
mix credo
312+
```
313+
314+
For more detailed output:
315+
316+
```bash
317+
mix credo --verbose
318+
```
319+
320+
### Mix Audit
321+
322+
Mix Audit helps identify security vulnerabilities in dependencies. Run it with:
323+
324+
```bash
325+
mix audit
326+
```
327+
328+
### Mix Unused
329+
330+
Mix Unused helps identify unused code in your project. Run it with:
331+
332+
```bash
333+
mix unused
334+
```
335+
302336
## Contributing
303337

304-
Contributions are welcome! Please feel free to submit a Pull Request.
338+
When contributing to this project, please ensure your code passes all the development tool checks:
339+
340+
1. Run Credo to ensure code style consistency
341+
2. Run Mix Audit to check for security vulnerabilities
342+
3. Run Mix Unused to identify any unused code
343+
4. Run the test suite with `mix test`
305344

306345
## License
307346

mix.exs

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ defmodule Posthog.MixProject do
5757
[
5858
{:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false},
5959
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
60-
{:hackney, "~> 1.20"},
60+
{:hackney, "~> 1.23"},
6161
{:uniq, "~> 0.6.1"},
6262
{:jason, "~> 1.4", optional: true},
6363
{:mimic, "~> 1.11", only: :test},
64-
{:cachex, "~> 4.0.4"}
64+
{:cachex, "~> 4.0.4"},
65+
# Development tools
66+
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
67+
{:mix_audit, "~> 2.0", only: [:dev, :test], runtime: false}
6568
]
6669
end
6770
end

mix.lock

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
%{
2+
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
23
"cachex": {:hex, :cachex, "4.0.4", "192b5a34ae7f2c866cf835d796005c31ccf65e50ee973fbbbda6c773c0f40322", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:ex_hash_ring, "~> 6.0", [hex: :ex_hash_ring, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "a0417593fcca4b6bd0330bb3bbd507c379d5287213ab990dbc0dd704cedede0a"},
3-
"certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
4+
"certifi": {:hex, :certifi, "2.14.0", "ed3bef654e69cde5e6c022df8070a579a79e8ba2368a00acf3d75b82d9aceeed", [:rebar3], [], "hexpm", "ea59d87ef89da429b8e905264fdec3419f84f2215bb3d81e07a18aac919026c3"},
5+
"credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
46
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
57
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
68
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
79
"eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"},
810
"ex_doc": {:hex, :ex_doc, "0.37.3", "f7816881a443cd77872b7d6118e8a55f547f49903aef8747dbcb345a75b462f9", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "e6aebca7156e7c29b5da4daa17f6361205b2ae5f26e5c7d8ca0d3f7e18972233"},
911
"ex_hash_ring": {:hex, :ex_hash_ring, "6.0.4", "bef9d2d796afbbe25ab5b5a7ed746e06b99c76604f558113c273466d52fa6d6b", [:mix], [], "hexpm", "89adabf31f7d3dfaa36802ce598ce918e9b5b33bae8909ac1a4d052e1e567d18"},
10-
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
12+
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
13+
"hackney": {:hex, :hackney, "1.23.0", "55cc09077112bcb4a69e54be46ed9bc55537763a96cd4a80a221663a7eafd767", [:rebar3], [{:certifi, "~> 2.14.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "6cd1c04cd15c81e5a493f167b226a15f0938a84fc8f0736ebe4ddcab65c0b44e"},
1114
"ham": {:hex, :ham, "0.3.0", "7cd031b4a55fba219c11553e7b13ba73bd86eab4034518445eff1e038cb9a44d", [:mix], [], "hexpm", "7d6c6b73d7a6a83233876cc1b06a4d9b5de05562b228effda4532f9a49852bf6"},
1215
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
1316
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
@@ -18,11 +21,14 @@
1821
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
1922
"mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},
2023
"mimic": {:hex, :mimic, "1.11.0", "49b126687520b6e179acab305068ad7d72bfea8abe94908a6c0c8ca0a5b7bdc7", [:mix], [{:ham, "~> 0.2", [hex: :ham, repo: "hexpm", optional: false]}], "hexpm", "8b16b1809ca947cffbaede146cd42da8c1c326af67a84b59b01c204d54e4f1a2"},
24+
"mix_audit": {:hex, :mix_audit, "2.1.4", "0a23d5b07350cdd69001c13882a4f5fb9f90fbd4cbf2ebc190a2ee0d187ea3e9", [:make, :mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.11", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "fd807653cc8c1cada2911129c7eb9e985e3cc76ebf26f4dd628bb25bbcaa7099"},
2125
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
2226
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
2327
"sleeplocks": {:hex, :sleeplocks, "1.1.3", "96a86460cc33b435c7310dbd27ec82ca2c1f24ae38e34f8edde97f756503441a", [:rebar3], [], "hexpm", "d3b3958552e6eb16f463921e70ae7c767519ef8f5be46d7696cc1ed649421321"},
2428
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
2529
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
26-
"unsafe": {:hex, :unsafe, "1.0.2", "23c6be12f6c1605364801f4b47007c0c159497d0446ad378b5cf05f1855c0581", [:mix], [], "hexpm", "b485231683c3ab01a9cd44cb4a79f152c6f3bb87358439c6f68791b85c2df675"},
2730
"uniq": {:hex, :uniq, "0.6.1", "369660ecbc19051be526df3aa85dc393af5f61f45209bce2fa6d7adb051ae03c", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "6426c34d677054b3056947125b22e0daafd10367b85f349e24ac60f44effb916"},
31+
"unsafe": {:hex, :unsafe, "1.0.2", "23c6be12f6c1605364801f4b47007c0c159497d0446ad378b5cf05f1855c0581", [:mix], [], "hexpm", "b485231683c3ab01a9cd44cb4a79f152c6f3bb87358439c6f68791b85c2df675"},
32+
"yamerl": {:hex, :yamerl, "0.10.0", "4ff81fee2f1f6a46f1700c0d880b24d193ddb74bd14ef42cb0bcf46e81ef2f8e", [:rebar3], [], "hexpm", "346adb2963f1051dc837a2364e4acf6eb7d80097c0f53cbdc3046ec8ec4b4e6e"},
33+
"yaml_elixir": {:hex, :yaml_elixir, "2.11.0", "9e9ccd134e861c66b84825a3542a1c22ba33f338d82c07282f4f1f52d847bd50", [:mix], [{:yamerl, "~> 0.10", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "53cc28357ee7eb952344995787f4bb8cc3cecbf189652236e9b163e8ce1bc242"},
2834
}

test/support/hackney_stub.ex

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
defmodule HackneyStub.State do
2+
@moduledoc """
3+
A GenServer module that manages the state for HackneyStub, allowing verification of HTTP requests.
4+
"""
25
use GenServer
36

47
def start_link(_opts) do
@@ -15,7 +18,7 @@ defmodule HackneyStub.State do
1518
GenServer.cast(name, {:set_verification, verification})
1619
end
1720

18-
def get_verification() do
21+
def get_verification do
1922
name = {:via, Registry, {:hackney_stub_registry, self()}}
2023
GenServer.call(name, :get_verification)
2124
end
@@ -30,6 +33,9 @@ defmodule HackneyStub.State do
3033
end
3134

3235
defmodule HackneyStub.Base do
36+
@moduledoc """
37+
A base module for creating Hackney stubs with predefined responses from fixture files.
38+
"""
3339
@fixtures_dir Path.join(__DIR__, "fixtures")
3440

3541
defmacro __using__(fixture) do
@@ -75,9 +81,15 @@ defmodule HackneyStub.Base do
7581
end
7682

7783
defmodule HackneyStub do
84+
@moduledoc """
85+
A stub implementation of Hackney that returns predefined responses from fixture files.
86+
"""
7887
use HackneyStub.Base, "decide.json"
7988
end
8089

8190
defmodule HackneyStubV3 do
91+
@moduledoc """
92+
A stub implementation of Hackney that returns predefined responses from fixture files for v3 API.
93+
"""
8294
use HackneyStub.Base, "decide-v3.json"
8395
end

0 commit comments

Comments
 (0)