Skip to content

Commit

Permalink
Maintenance updates (#53)
Browse files Browse the repository at this point in the history
* Preemptively accept format results

Before starting to change files in the scope of this branch

* Remove dead code

* Ease maintenance of .gitignore

Only keep generated stuff + _* (e.g. for _build and _checkouts)

* Add a CHANGELOG (even if it's just a reference to our Releases page)

* Ease a fork's pre-pull request CI

* Tweak ci.yml: bump versions and add format constraints

* Accept further format results

* Tweak rebar.config

* Fix as per CI results: rebar3 functions not found "in scope"

* Fix as per CI results: rebar.config not properly formatted

* Fix as per CI results: OTP 26's dialyzer is unknown-enabled, by default

* Act on self-review: remove pre-OTP 24 -specific code
  • Loading branch information
paulo-ferraz-oliveira authored Aug 7, 2023
1 parent d4e8264 commit 814081a
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 126 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
---
name: build
on:
push:
branches:
- master
pull_request:
branches:
- master
on: [push, pull_request]
jobs:
ci:
name: Run checks and tests over ${{matrix.otp_vsn}} and ${{matrix.os}}
runs-on: ${{matrix.os}}
name: Run checks and tests over ${{matrix.otp_vsn}}
runs-on: ubuntu-22.04
strategy:
matrix:
otp_vsn: [23, 24, 25]
os: [ubuntu-20.04]
otp_vsn: ['24', '25', '26']
rebar3_vsn: ['3.22']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp_vsn}}
rebar3-version: '3.18'
rebar3-version: ${{matrix.rebar3_vsn}}
- name: Format check
run: rebar3 format --verify
- env:
ERL_FLAGS: "-enable-feature all"
run: rebar3 test
Expand Down
20 changes: 3 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
.rebar3
_*
.eunit
*.o
*.beam
*.plt
*.swp
*.swo
.erlang.cookie
ebin
log
erl_crash.dump
.rebar
_rel
_deps
_plugins
_tdeps
logs
_build
rebar3.crashdump
_*
doc/
logs
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog

See the [Releases](../../releases) page.
65 changes: 30 additions & 35 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
{minimum_otp_vsn, "21"}.
%% == Compiler and Profiles ==

%% == Erlang Compiler ==
{erl_opts,
[warn_unused_import, warn_export_vars, warnings_as_errors, verbose, report, debug_info]}.

{erl_opts, [
debug_info
]}.
{minimum_otp_vsn, "23"}.

{profiles,
[{test, [{ct_opts, [{verbose, true}]}, {cover_enabled, true}, {cover_opts, [verbose]}]}]}.

{alias, [{test, [compile, format, hank, xref, dialyzer, ct, cover, ex_doc]}]}.

%% == Dependencies and plugins ==

{deps, [
{elvis_core, "3.0.1"}
]}.
{deps, [{elvis_core, "3.0.1"}]}.

{project_plugins,
[{rebar3_hank, "~> 1.4.0"},
{rebar3_hex, "~> 7.0.7"},
{rebar3_format, "~> 1.3.0"},
{rebar3_ex_doc, "0.2.18"}]}.

{project_plugins, [
rebar3_hex,
rebar3_hank
]}.
%% == Documentation ==

%% == Dialyzer ==
{ex_doc,
[{source_url, <<"https://github.com/project-fifo/rebar3_lint">>},
{extras, [<<"README.md">>, <<"LICENSE">>]},
{main, <<"readme">>}]}.

{dialyzer, [
{warnings, [
error_handling,
underspecs,
unmatched_returns
]}
]}.
{hex, [{doc, #{provider => ex_doc}}]}.

{xref_checks, [
deprecated_function_calls,
exports_not_used,
locals_not_used
]}.
%% == Format ==

%% == Profiles ==
{format, [{files, ["*.config", "src/*", "test/*"]}]}.

{profiles, [
{test, [
{cover_enabled, true},
{cover_opts, [verbose]}
]}
]}.
%% == Dialyzer + XRef ==

%% == Aliases ==
{dialyzer,
[{warnings, [no_return, error_handling, underspecs, unmatched_returns, no_unknown]},
{plt_extra_apps, [common_test]}]}.

{alias, [{test, [xref, dialyzer, hank, ct, cover, edoc]}]}.
{xref_checks, [deprecated_function_calls, deprecated_functions]}.

{hex, [{doc, edoc}]}.
{xref_extra_paths, ["test/**"]}.
20 changes: 10 additions & 10 deletions src/rebar3_lint.app.src
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{application,rebar3_lint,
[{description,"Erlang linter - rebar3 plugin"},
{vsn,git},
{registered,[]},
{applications,[kernel,stdlib,elvis_core]},
{env,[]},
{modules,[]},
{licenses,["MIT"]},
{links,[{"GitHub",
"https://github.com/project-fifo/rebar3_lint"}]}]}.
{application,
rebar3_lint,
[{description, "Erlang linter - rebar3 plugin"},
{vsn, git},
{registered, []},
{applications, [kernel, stdlib, elvis_core]},
{env, []},
{modules, []},
{licenses, ["MIT"]},
{links, [{"GitHub", "https://github.com/project-fifo/rebar3_lint"}]}]}.
10 changes: 3 additions & 7 deletions src/rebar3_lint.erl
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
-module('rebar3_lint').
-module(rebar3_lint).

-export([init/1]).

-ignore_xref([init/1]).

%% for eating our own dogfood
-export([main/1]).

-ignore_xref([main/1]).

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
{ok, State1} = rebar3_lint_prv:init(State),
Expand All @@ -18,4 +13,5 @@ init(State) ->
-spec main([]) -> ok | {fail, [elvis_result:file()]}.
main([]) ->
ok = application:load(elvis_core),
elvis_core:rock(rebar3_lint_prv:default_config()).
elvis_core:rock(
rebar3_lint_prv:default_config()).
70 changes: 34 additions & 36 deletions src/rebar3_lint_prv.erl
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
-module('rebar3_lint_prv').
-module(rebar3_lint_prv).

-export([init/1, do/1, format_error/1]).
-export([default_config/0]).

-ignore_xref([do/1]).
-ignore_xref([format_error/1]).

-define(PROVIDER, 'lint').
-define(PROVIDER, lint).
-define(DEPS, [compile, app_discovery]).

%% ===================================================================
Expand All @@ -15,20 +12,16 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
Provider =
providers:create(
[
{name, ?PROVIDER},
{module, ?MODULE},
{bare, true},
{deps, ?DEPS},
{example, "rebar3 lint"},
{opts, []},
{short_desc, "A rebar plugin for elvis"},
{desc, "A rebar linter plugin based on elvis"}
]),
providers:create([{name, ?PROVIDER},
{module, ?MODULE},
{bare, true},
{deps, ?DEPS},
{example, "rebar3 lint"},
{opts, []},
{short_desc, "A rebar plugin for elvis"},
{desc, "A rebar linter plugin based on elvis"}]),
{ok, rebar_state:add_provider(State, Provider)}.


-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
Elvis = get_elvis_config(State),
Expand All @@ -38,11 +31,12 @@ do(State) ->
{ok, State};
{fail, _} ->
{error, "Linting failed"}
catch throw:Error ->
rebar_api:abort("elvis_core threw an exception: ~p", [Error])
catch
Error ->
rebar_api:abort("elvis_core threw an exception: ~p", [Error])
end.

-spec format_error(any()) -> iolist().
-spec format_error(any()) -> iolist().
format_error(Reason) ->
io_lib:format("~p", [Reason]).

Expand All @@ -64,7 +58,8 @@ try_elvis_config_rebar(State) ->
-spec handle_output_format(rebar_state:t()) -> ok.
handle_output_format(State) ->
case rebar_state:get(State, elvis_output_format, no_config) of
no_config -> ok;
no_config ->
ok;
plain ->
application:set_env(elvis_core, output_format, plain);
colors ->
Expand All @@ -73,32 +68,35 @@ handle_output_format(State) ->
application:set_env(elvis_core, output_format, parsable);
Other ->
rebar_api:abort("~p is not a valid elvis output format. Must be either plain, colors or"
"parsable", [Other])
"parsable",
[Other])
end.

-spec try_elvis_config_file(rebar_state:t()) -> elvis_config:configs().
try_elvis_config_file(State) ->
Filename = filename:join(rebar_dir:root_dir(State), "elvis.config"),
Filename =
filename:join(
rebar_dir:root_dir(State), "elvis.config"),
rebar_api:debug("Looking for Elvis in ~s", [Filename]),
try elvis_config:from_file(Filename) of
[] ->
rebar_api:debug("Using default Elvis configuration", []),
default_config();
Config -> Config
Config ->
Config
catch
throw:Error ->
rebar_api:abort("Error reading Elvis config from ~s: ~p",
[Filename, Error])
Error ->
rebar_api:abort("Error reading Elvis config from ~s: ~p", [Filename, Error])
end.

-spec default_config() -> elvis_config:configs().
default_config() ->
[#{ dirs => ["apps/*/src/**", "src/**"],
filter => "*.erl",
ruleset => erl_files },
#{ dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config },
#{ dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config }].
[#{dirs => ["apps/*/src/**", "src/**"],
filter => "*.erl",
ruleset => erl_files},
#{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config},
#{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config}].
16 changes: 8 additions & 8 deletions test/test_app_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

-export([all/0, test_app/1]).

-if(?OTP_RELEASE >= 23).
-behaviour(ct_suite).
-endif.

all() ->
[test_app].

test_app(_Config) ->
ok = file:set_cwd("../../../../"),
{ok, GoodState} = rebar3_lint_prv:init(rebar_state:new()),
{ok, GoodState} =
rebar3_lint_prv:init(
rebar_state:new()),
{ok, _} = rebar3_lint_prv:do(GoodState),
BadState =
rebar_state:set(GoodState, elvis, [#{
dirs => ["src"],
filter => "*.erl",
rules => [{elvis_style, max_function_length, #{max_length => 1}}]
}]),
rebar_state:set(GoodState,
elvis,
[#{dirs => ["src"],
filter => "*.erl",
rules => [{elvis_style, max_function_length, #{max_length => 1}}]}]),
{error, "Linting failed"} = rebar3_lint_prv:do(BadState).

0 comments on commit 814081a

Please sign in to comment.