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

Var exposed from the scope without return #502

Closed
define-null opened this issue Jun 12, 2019 · 3 comments
Closed

Var exposed from the scope without return #502

define-null opened this issue Jun 12, 2019 · 3 comments
Labels

Comments

@define-null
Copy link
Contributor

define-null commented Jun 12, 2019

Just an idea - it would be nice to make elvis warn about the situations when variable is exposed from the scope without doing that explicitly, like this:

case some_function() of
    opt1 ->
         ... some code here ...
         Var = some_other_fun()
         ... some code here as well ..
    opt2 ->
         ... some code here ...
         Var = some_other_fun2()
         ... some code here as well ...
end,

other_function(Var)

Where the good code imho would do smth like:

{Var, Rest...} = case some_function() of
    opt1 ->
         ... some code here ...
         V = some_other_fun()
         ... some code here as well ..
         {V, R...}
    opt2 ->
         ... some code here ...
         V = some_other_fun2()
         ... some code here as well ...
         {V, R...}
end,

other_function(Var)
@elbrujohalcon
Copy link
Member

I love this rule idea!

@paulo-ferraz-oliveira
Copy link
Collaborator

I get a compilation warning if I attempt to "expose from scope".

variable 'V' exported from 'case'

I'm on Erlang/OTP 23, using rebar3 with erl_opts [warnings_as_errors, debug_info, warn_missing_spec_all, warn_export_vars, warn_unused_import].

@elbrujohalcon
Copy link
Member

Yeah, warn_export_vars does the trick :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants