Skip to content

Commit

Permalink
Merge pull request #79 from paulo-ferraz-oliveira/feature/minor-maint…
Browse files Browse the repository at this point in the history
…enance-updates

Minor maintenance updates
  • Loading branch information
elbrujohalcon authored Aug 4, 2023
2 parents 689d81d + 7e4ec84 commit 4de3a62
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 105 deletions.
12 changes: 8 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

## Bug Description

A clear and concise description of what the bug is.

## To Reproduce

Steps to reproduce the behavior

## Expected Behavior

A clear and concise description of what you expected to happen.

## `rebar3` Logs

If applicable, run `rebar3` with `DIAGNOSTIC=1` and attach all the logs to your report.

## Additional Context
- OS: [e.g. MacOS]
- Erlang version
- rebar3 version

- OS: [e.g. MacOS]
- Erlang version
- rebar3 version
13 changes: 9 additions & 4 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

## Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
## Is your feature request related to a problem? Please describe

A clear and concise description of what the problem is. Ex. I'm always frustrated
when [...]

## Describe the solution you'd like

A clear and concise description of what you want to happen.

## Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

A clear and concise description of any alternative solutions or features you've
considered.

## Additional Context

Add any other context or screenshots about the feature request here.
59 changes: 29 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
---
name: Erlang CI

on: [push, pull_request]
"on": [push, pull_request]

jobs:

build:

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

strategy:
matrix:
otp: ['23.3', '24.3', '25.0']
rebar: ['3.18.0']
otp: ['24', '25', '26']
rebar: ['3.22']

steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
id: setup-beam
with:
otp-version: ${{matrix.otp}}
rebar3-version: ${{matrix.rebar}}
- name: Restore _build
uses: actions/cache@v2
with:
path: _build
key: _build-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}}
- name: Restore rebar3's cache
uses: actions/cache@v2
with:
path: ~/.cache/rebar3
key: rebar3-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}}
- name: Compile
run: ERL_FLAGS="-enable-feature all" rebar3 compile
- name: Format check
run: ERL_FLAGS="-enable-feature all" rebar3 format --verify
- name: Run tests and verifications (features not enabled)
run: rebar3 test
- name: Run tests and verifications (features enabled)
run: ERL_FLAGS="-enable-feature all" rebar3 test

- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
id: setup-beam
with:
otp-version: ${{matrix.otp}}
rebar3-version: ${{matrix.rebar}}
- name: Restore _build
uses: actions/cache@v3
with:
path: _build
key: _build-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}}
- name: Restore rebar3's cache
uses: actions/cache@v3
with:
path: ~/.cache/rebar3
key: rebar3-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}}
- name: Compile
run: ERL_FLAGS="-enable-feature all" rebar3 compile
- name: Format check
run: ERL_FLAGS="-enable-feature all" rebar3 format --verify
- name: Run tests and verifications (features not enabled)
run: rebar3 test
- name: Run tests and verifications (features enabled)
run: ERL_FLAGS="-enable-feature all" rebar3 test
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
rebar3.crashdump
.rebar3
_*
.eunit
*.o
*.beam
*.plt
erl_crash.dump
rel/
_build
_checkouts
doc/
57 changes: 28 additions & 29 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
%% -*- mode: erlang;erlang-indent-level: 2;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
%% == Compiler and Profiles ==

{erl_opts,
[warn_unused_import, warn_export_vars, warnings_as_errors, verbose, report, debug_info]}.

{minimum_otp_vsn, "23"}.
{minimum_otp_vsn, "24"}.

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

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

%% == Dependencies and plugins ==

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

%% == Documentation ==

{ex_doc,
[{source_url, <<"https://github.com/inaka/katana-code">>},
Expand All @@ -12,34 +28,17 @@

{hex, [{doc, #{provider => ex_doc}}]}.

{project_plugins,
[{rebar3_hex, "~> 7.0.1"},
{rebar3_format, "~> 1.1.0"},
{rebar3_lint, "~> 1.0.2"},
{rebar3_ex_doc, "~> 0.2.9"}]}.

{dialyzer, [{warnings, [no_return, unmatched_returns, error_handling, underspecs]}]}.

{edoc_opts,
[{todo, true},
{title, "Hank"},
{packages, true},
{subpackages, true},
{source_path, "src"},
{application, rebar3_hank},
{new, true},
{report_missing_types, true}]}.
%% == Format ==

{xref_checks,
[undefined_function_calls,
locals_not_used,
deprecated_function_calls,
deprecated_functions]}.
{format, [{options, #{unquote_atoms => false}}]}.

{cover_enabled, true}.
%% == Dialyzer + XRef ==

{cover_opts, [verbose]}.
{dialyzer,
[{warnings, [no_return, unmatched_returns, error_handling, underspecs, unknown]},
{plt_extra_apps, [syntax_tools]}]}.

{format, [{options, #{unquote_atoms => false}}]}.
{xref_checks,
[undefined_function_calls, deprecated_function_calls, deprecated_functions]}.

{alias, [{test, [compile, format, lint, dialyzer, {ct, "--verbose"}, cover, edoc]}]}.
{xref_extra_paths, ["test/**"]}.
2 changes: 1 addition & 1 deletion src/katana_code.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
{modules, []},
{registered, []},
{licenses, ["Apache 2.0"]},
{links, [{"github", "https://github.com/inaka/katana-code"}]},
{links, [{"GitHub", "https://github.com/inaka/katana-code"}]},
{build_tools, ["rebar3"]}]}.
54 changes: 43 additions & 11 deletions src/ktn_code.erl
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ktn_code: functions useful for dealing with erlang code
%%% ktn_code: functions useful for dealing with Erlang code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-module(ktn_code).

-elvis([{elvis_style, dont_repeat_yourself, #{min_complexity => 25}}]).
-elvis([{elvis_style, no_throw, disable}]).

-export([beam_to_string/1, beam_to_erl/2, parse_tree/1, eval/1, consult/1, to_str/1]).
%% Getters
-export([type/1, attr/2, node_attr/2, content/1]).

-export_type([tree_node/0, tree_node_type/0]).
-export_type([tree_node/0, tree_node_type/0, beam_lib_beam/0]).

-type tree_node_type() ::
root | function | clause | match | tuple | atom | integer | float | string | char |
Expand All @@ -26,15 +27,31 @@
attrs => map(),
node_attrs => map(),
content => [tree_node()]}.
-type beam_lib_beam() :: file:filename() | binary().
% Should eventually become beam_lib:beam(), once that's exposed
% (https://github.com/erlang/otp/pull/7534)
-type erl_syntax_annotation_or_location() :: erl_anno:anno() | erl_anno:location().
% Should eventually become erl_syntax:annotation_or_location(), once that's exposed
% (https://github.com/erlang/otp/pull/7535)
-type erl_parse_foo() ::
{attribute,
Pos :: erl_syntax_annotation_or_location(),
Name :: erl_syntax:syntaxTree(),
Args :: none | [erl_syntax:syntaxTree()]} |
{macro,
Pos :: erl_syntax_annotation_or_location(),
Name :: erl_syntax:syntaxTree(),
Args :: none | [erl_syntax:syntaxTree()]} |
{atom, [{node, Node :: erl_syntax:syntaxTree()}], non_reversible_form}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Exported API
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% @doc If the beam was not compiled with debug_info
%% @doc If the beam was not compiled with `debug_info'
%% the code generated by this function will look really ugly
%% @end
-spec beam_to_string(beam_lib:beam()) -> {ok, string()} | {error, beam_lib, term()}.
-spec beam_to_string(beam_lib_beam()) -> {ok, string()} | {error, beam_lib, term()}.
beam_to_string(BeamPath) ->
case beam_lib:chunks(BeamPath, [abstract_code]) of
{ok, {_, [{abstract_code, {raw_abstract_v1, Forms}}]}} ->
Expand All @@ -45,10 +62,10 @@ beam_to_string(BeamPath) ->
Error
end.

%% @doc If the beam was not compiled with debug_info
%% @doc If the beam was not compiled with `debug_info'
%% the code generated by this function will look really ugly
%% @end
-spec beam_to_erl(beam_lib:beam(), string()) -> ok.
-spec beam_to_erl(beam_lib_beam(), string()) -> ok.
beam_to_erl(BeamPath, ErlPath) ->
case beam_to_string(BeamPath) of
{ok, Src} ->
Expand Down Expand Up @@ -87,7 +104,7 @@ is_comment({comment, _, _}) ->
is_comment(_) ->
false.

-spec revert(erl_syntax:syntaxTree()) -> erl_parse:foo().
-spec revert(erl_syntax:syntaxTree()) -> erl_parse_foo().
revert(Form) ->
MaybeReverted =
try
Expand All @@ -103,7 +120,7 @@ revert(Form) ->
MaybeReverted
end.

-spec revert(atom(), erl_syntax:syntaxTree()) -> erl_parse:foo().
-spec revert(atom(), erl_syntax:syntaxTree()) -> erl_parse_foo().
revert(attribute, Node0) ->
Subs = erl_syntax:subtrees(Node0),
Gs = [[erl_syntax:revert(X) || X <- L] || L <- Subs],
Expand Down Expand Up @@ -133,7 +150,7 @@ token_to_map({Type, Attrs, Value}) ->
Map = token_to_map({Type, Attrs}),
Map#{value => Value}.

%% @doc Evaluates the erlang expression in the string provided.
%% @doc Evaluates the Erlang expression in the string provided.
-spec eval(string() | binary()) -> term().
eval(Source) ->
eval(Source, []).
Expand All @@ -146,7 +163,7 @@ eval(Source, Bindings) ->
{value, Result, _} = erl_eval:exprs(Parsed, Bindings),
Result.

%% @doc Like file:consult/1 but for strings and binaries.
%% @doc Like `file:consult/1' but for strings and binaries.
-spec consult(string() | binary()) -> [term()].
consult(Source) ->
SourceStr = to_str(Source),
Expand Down Expand Up @@ -255,7 +272,7 @@ get_location(Attrs) when is_list(Attrs) ->
_ ->
{Line, Column}
end;
get_location(Location = {_Line, _Column}) ->
get_location({_Line, _Column} = Location) ->
Location;
get_location(_Attrs) ->
{-1, -1}.
Expand Down Expand Up @@ -529,6 +546,21 @@ to_map({bc_expr, Attrs, Expr}) ->
#{type => bc_expr,
attrs => #{location => get_location(Attrs), text => get_text(Attrs)},
content => [to_map(Expr)]};
%% Map Comprehension
to_map({mc, Anno, RepE0, RepQs}) ->
McExpr = to_map({mc_expr, Anno, RepE0}),
McGenerators = to_map(RepQs),
#{type => mc,
attrs => #{location => get_location(Anno), text => get_text(Anno)},
content => [McExpr | McGenerators]};
to_map({m_generate, Anno, Pattern, RepE0}) ->
#{type => m_generate,
attrs => #{location => get_location(Anno), text => get_text(Anno)},
node_attrs => #{pattern => to_map(Pattern), expression => to_map(RepE0)}};
to_map({mc_expr, Anno, RepE0}) ->
#{type => mc_expr,
attrs => #{location => get_location(Anno), text => get_text(Anno)},
content => [to_map(RepE0)]};
%% Operation
to_map({op, Attrs, Operation, Left, Right}) ->
#{type => op,
Expand Down
Loading

0 comments on commit 4de3a62

Please sign in to comment.