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

Rule idea: check map field updates #339

Closed
erszcz opened this issue Jan 28, 2016 · 2 comments
Closed

Rule idea: check map field updates #339

erszcz opened this issue Jan 28, 2016 · 2 comments
Labels

Comments

@erszcz
Copy link

erszcz commented Jan 28, 2016

In order to avoid a schema-less "data bag" situation when using maps, it seems to be a good practice to use #{a => A} only in one place when initially creating a map. Fields expected to be used in the future should be explicitly assigned undefined (or some other sentinel value) to mark that their presence is expected. After that only #{a := A'} should be used for updating values of existing fields and => should not be used again. That way for each "kind" of map there's one place in code defining what fields should be present in the map.

The Elvis rule would find all map update operations (i.e. M#{a := A'}) and ensure none of them use => for updating the map.

@erszcz erszcz added the rule label Jan 28, 2016
@erszcz erszcz changed the title Rule idea: map field access Rule idea: check map field updates Jan 28, 2016
@paulo-ferraz-oliveira
Copy link
Collaborator

It seems some of the things you refer can be dealt with by dialyzer already, namely the expected content/format of a map. If you want a compulsory field set as undefined, you can use notation #{ FieldName :: binary() := undefined | pos_integer()}, for example.

What kind of problem are we trying to solve here?

@elbrujohalcon
Copy link
Member

This was written before dialyzer had support for defining strict map types like…

-type my_particular_map() :: #{a := pos_integer(), b := string()}.

I'll close this one. @erszcz: feel free to reopen it if you still want an elvis rule for this.

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