Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules for warning about seqbind #67

Merged
merged 3 commits into from
Oct 31, 2016
Merged

Conversation

gnuvince
Copy link

seqbind [1] is a parse transform for Erlang that allows the programmer to assign to "the same variable" multiples times, e.g.,

X@ = 10,
X@ = X@ + 1.

Although this transform can be useful at times, even its author recommends using it sparingly since it obscures the functional nature of Erlang, and can look quite ugly.

This PR adds:

an elvis_style rule warning the user when a module declares its intention to use seqbind;
an elvis_style rule warning the user when a module declares the seqbind parse transform, but never actually uses it (i.e., complete absence of Var@ in the module).

Issue ref.: inaka/elvis#413

Vincent Foley added 2 commits October 31, 2016 09:26
seqbind [1] is a parse transform for Erlang that allows the programmer
to assign to "the same variable" multiples times, e.g.,

```erlang
X@ = 10,
X@ = X@ + 1.
```

Although this transform can be useful at times, even its author
recommends using it sparingly since it obscures the functional nature of
Erlang, and can look quite ugly.

This commit adds an elvis_style rule to detect when a module declares
its intention to use seqbind.

[1] https://github.com/spawngrid/seqbind
Give a warning to the user if he has declared his module to use the
seqbind parse transform, yet no seq-bindings (i.e., VarName@) can be
found in the module.
@@ -25,6 +25,7 @@
{test, [
{deps, [ {katana_test, {git, "https://github.com/inaka/katana-test.git", {tag, "0.0.6"}}}
, {mixer, {git, "https://github.com/inaka/mixer.git", {tag, "0.1.5"}}}
, {seqbind, {git, "https://github.com/lpgauth/seqbind.git", {branch, "master"}}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use "master" branch, either choose a tag or use a commit SHA.

lists:last(ktn_code:attr(text, Node)) =:= $@
end,
Root),
case SeqBindings of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a case, you can do SeqBindings /= [] directly.

- Replace master branch for seqbind in rebar.config with explicit
  commit reference (seqbind doesn't have tags at the moment);
- Replace explicit pattern matching for checking empty list with
  comparison with the empty list.
@elbrujohalcon elbrujohalcon merged commit b65436d into inaka:master Oct 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants