Skip to content

Commit

Permalink
Modernize (#64)
Browse files Browse the repository at this point in the history
* Modernize the rebar.config and elvis.config

* Format and Lint

* Fix hank and dialyzer for ktn_meta_SUITE

* Update CI for plugins

* Format in OTP 23

* Add verify in CI
  • Loading branch information
vkatsuba authored Nov 1, 2021
1 parent 1c6f0b0 commit 80887ba
Show file tree
Hide file tree
Showing 22 changed files with 786 additions and 917 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
otp: [22.3, 23.3, 24.1]
otp: [23.3, 24.1]
fail-fast: false
container:
image: erlang:${{ matrix.otp }}
steps:
- uses: actions/checkout@v2
- name: Dialyzer
run: rebar3 dialyzer
- name: Format check
run: rebar3 format --verify
- name: Tests
run: rebar3 ct
run: rebar3 test
- name: prepare coverage report
run: rebar3 codecov analyze --lcov --json false
- name: report coverage
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ log/
doc/
codecov.json
rebar3
rebar3.crashdump
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Check [this](examples/README.md) out.

## Dependencies

- Erlang/OTP 22+
- Erlang/OTP 23+

<!-- Badges -->
[hexpm]: https://hex.pm/packages/sheldon
Expand All @@ -114,4 +114,4 @@ Check [this](examples/README.md) out.
[gh badge]: https://img.shields.io/github/workflow/status/inaka/sheldon/CI?style=flat-square
[coveralls]: https://coveralls.io/github/inaka/sheldon
[coveralls badge]: https://img.shields.io/coveralls/inaka/sheldon/master.svg?style=flat-square
[erlang version badge]: https://img.shields.io/badge/erlang-22.3%20to%2024.1-blue.svg?style=flat-square
[erlang version badge]: https://img.shields.io/badge/erlang-23.0%20to%2024.1-blue.svg?style=flat-square
39 changes: 12 additions & 27 deletions elvis.config
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
[
{
elvis,
[
{config,
[#{dirs => ["src", "test"],
filter => "*.erl",
ruleset => erl_files,
rules => [{elvis_style, line_length, #{limit => 100}}]
},
#{dirs => ["."],
filter => "Makefile",
ruleset => makefiles
},
#{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config
},
#{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config
}
]
}
]
}
].
[{elvis,
[{config,
[#{dirs => ["src", "test"],
filter => "*.erl",
ruleset => erl_files,
rules => [{elvis_style, state_record_and_type, disable}]},
#{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config},
#{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config}]}]}].
17 changes: 8 additions & 9 deletions examples/example.erl
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
-module(example).

-author("Felipe Ripoll <felipe@inakanetworks.com>").

-export([ check_file/1
, check_file/2
]).
-export([check_file/1, check_file/2]).

%%%===================================================================
%%% API
%%%===================================================================

-spec check_file(string()) -> sheldon_result:result().
check_file(Path) ->
{ok, Bin} = file:read_file(Path),
sheldon:check(Bin).
{ok, Bin} = file:read_file(Path),
sheldon:check(Bin).

-spec check_file(string(), sheldon_config:config()) -> sheldon_result:result().
check_file(Path, Config) ->
{ok, Bin} = file:read_file(Path),
sheldon:check(Bin, Config).
-spec check_file(string(), sheldon_config:config()) -> sheldon_result:result().
check_file(Path, Config) ->
{ok, Bin} = file:read_file(Path),
sheldon:check(Bin, Config).
86 changes: 47 additions & 39 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% == Erlang Compiler ==

{erl_opts, [
warn_unused_vars,
{erl_opts,
[warn_unused_vars,
warn_export_all,
warn_shadow_vars,
warn_unused_import,
Expand All @@ -15,34 +15,25 @@
warn_exported_vars,
warn_missing_spec,
warn_untyped_record,
debug_info
]}.
debug_info]}.

{minimum_otp_vsn, "21.0"}.
{minimum_otp_vsn, "23"}.

%% == Dependencies ==

{deps, [
{worker_pool, "4.0.0"},
{emarkdown, "0.1.0"}
]}.
{deps, [{worker_pool, "4.0.0"}, {emarkdown, "0.1.0"}]}.

%% == Profiles ==

{profiles, [
{test, [
{deps, [
{katana_test, "1.0.1"},
{mixer, "1.2.0", {pkg, inaka_mixer}},
{meck, "0.8.12"}
]}
]}
]}.
{profiles,
[{test,
[{deps,
[{katana_test, "1.0.1"}, {mixer, "1.2.0", {pkg, inaka_mixer}}, {meck, "0.8.12"}]}]}]}.

%% == Common Test ==

{ct_compile_opts, [
warn_unused_vars,
{ct_compile_opts,
[warn_unused_vars,
warn_export_all,
warn_shadow_vars,
warn_unused_import,
Expand All @@ -56,47 +47,64 @@
warn_exported_vars,
warn_missing_spec,
warn_untyped_record,
debug_info
]}.
debug_info]}.

{ct_opts, [
{sys_config, ["test/test.config"]}
]}.
{ct_opts, [{sys_config, ["test/test.config"]}]}.

%% == Cover ==
%% == Plugins ==

{project_plugins,
[{rebar3_hex, "~> 6.11.7"},
{rebar3_format, "~> 1.0.1"},
{rebar3_lint, "~> 1.0.1"},
{rebar3_hank, "~> 1.2.2"},
{coveralls, "~> 2.2.0"},
{rebar3_codecov, "0.2.0"}]}.

{project_plugins, [coveralls, {rebar3_codecov, "0.2.0"}]}.
%% == Cover ==

{cover_enabled, true}.

{cover_export_enabled, true}.
{provider_hooks,
[
{post, [{ct, {codecov, analyze}}]}
]}.

{provider_hooks, [{post, [{ct, {codecov, analyze}}]}]}.

{cover_opts, [verbose]}.

%% == EDoc ==

{edoc_opts, [
{report_missing_types, true},
{edoc_opts,
[{report_missing_types, true},
{source_path, ["src"]},
{report_missing_types, true},
{todo, true},
{packages, false},
{subpackages, false}
]}.
{subpackages, false}]}.

%% == Dialyzer ==

{dialyzer, [
{plt_apps, top_level_deps},
{dialyzer,
[{plt_apps, top_level_deps},
{plt_extra_apps, []},
{plt_location, local},
{plt_prefix, "sheldon"},
{base_plt_location, "."},
{base_plt_prefix, "sheldon"}
]}.
{base_plt_prefix, "sheldon"}]}.

{erl_first_files, ["src/adapter/sheldon_adapter.erl"]}.

%% == Alias ==

{alias,
[{test, [compile, format, lint, hank, dialyzer, {ct, "--verbose"}, cover, edoc]}]}.

%% == Format ==

{format,
[{files,
["*.config",
"src/adapter/*",
"src/*.erl",
"examples/*.erl",
"test/*.erl",
"test/*.config"]}]}.
34 changes: 17 additions & 17 deletions src/adapter/html_adapter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
%%% @copyright Erlang Solutions Ltd. <hello@inaka.net>
%%%
-module(html_adapter).

-author("Felipe Ripoll <felipe@inakanetworks.com>").

-behaviour(sheldon_adapter).
Expand All @@ -31,37 +32,36 @@

-spec adapt(binary()) -> iodata().
adapt(Line) ->
Line1 = escape_tags(Line),
replace_chars(Line1).
Line1 = escape_tags(Line),
replace_chars(Line1).

%%%===================================================================
%%% Internal Functions
%%%===================================================================

-spec replace_chars(binary()) -> iodata().
replace_chars(Line) ->
Chars = chars_to_replace(),
replace_chars(Line, Chars).
Chars = chars_to_replace(),
replace_chars(Line, Chars).

-spec replace_chars(iodata(), [{string(), string()}]) -> iodata().
replace_chars(Line, []) ->
Line;
Line;
replace_chars(Line, [{Pattern, ReplaceBy} | Rest]) ->
Result = re:replace(Line, Pattern, ReplaceBy, [global]),
replace_chars(Result, Rest).
Result = re:replace(Line, Pattern, ReplaceBy, [global]),
replace_chars(Result, Rest).

-spec escape_tags(iodata()) -> iodata().
escape_tags(Line) ->
Pattern = "<[^>]*>",
ReplaceBy = "",
re:replace(Line, Pattern, ReplaceBy, [global]).
Pattern = "<[^>]*>",
ReplaceBy = "",
re:replace(Line, Pattern, ReplaceBy, [global]).

-spec chars_to_replace() -> [{string(), string()}].
chars_to_replace() ->
[ {"&quot;", "\""}
, {"&amp;", "\\&"}
, {"&lt;", "<"}
, {"&gt;", ">"}
, {"&#39;", "'"}
, {"&#[0-9]*;", ""}
].
[{"&quot;", "\""},
{"&amp;", "\\&"},
{"&lt;", "<"},
{"&gt;", ">"},
{"&#39;", "'"},
{"&#[0-9]*;", ""}].
5 changes: 3 additions & 2 deletions src/adapter/markdown_adapter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
%%% @copyright Erlang Solutions Ltd. <hello@inaka.net>
%%%
-module(markdown_adapter).

-author("Felipe Ripoll <felipe@inakanetworks.com>").

-behaviour(sheldon_adapter).
Expand All @@ -30,5 +31,5 @@

-spec adapt(binary()) -> iodata().
adapt(Line) ->
Line1 = emarkdown:to_html(Line),
html_adapter:adapt(Line1).
Line1 = emarkdown:to_html(Line),
html_adapter:adapt(Line1).
3 changes: 3 additions & 0 deletions src/adapter/sheldon_adapter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
%%% @copyright Erlang Solutions Ltd. <hello@inaka.net>
%%%
-module(sheldon_adapter).

-author("Felipe Ripoll <felipe@inakanetworks.com>").

-hank([unused_callbacks]).

-callback adapt(Line :: binary()) -> iodata().
Loading

0 comments on commit 80887ba

Please sign in to comment.