-
Notifications
You must be signed in to change notification settings - Fork 57
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
Fix #162: New Rule: No Types #270
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[{elvis, | ||
[{config, | ||
[#{dirs => ["../../_build/test/lib/elvis_core/test/examples/"], | ||
filter => "*.hrl", | ||
filter => "test-*.hrl", | ||
ruleset => hrl_files}]}]}]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# No Types | ||
|
||
(since [2.1.0](https://github.com/inaka/elvis_core/releases/tag/2.1.0)) | ||
|
||
Avoid `-type` attributes. | ||
|
||
This rule is meant to be used on header files only. | ||
Defining types in public header files (especially those intended for inclusion via -include_lib()) | ||
might lead to type name clashes between projects and even modules of a single big project. | ||
Instead, types should be defined in the modules which they correspond to | ||
(using `-export_type()` appropriately) and, in this way, take advantage of the namespacing offered | ||
by module names. | ||
In other words, this rule means that we will always need to use `some_mod:some_type()` unless | ||
we're referring to a type defined in the same module. | ||
|
||
> Works on `.beam` file? Yes, but it's not useful there. This rule is meant to be used for header files. | ||
|
||
## Options | ||
|
||
- None. | ||
|
||
## Example | ||
|
||
```erlang | ||
{elvis_style, no_types} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-type bad_type() :: no | types | should | be | defined | in | header | files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
-module hrl_usage. | ||
|
||
-include("good.hrl"). | ||
-include("bad.hrl"). | ||
-include("test-good.hrl"). | ||
-include("test-bad.hrl"). | ||
-include("fail_no_types.hrl"). | ||
-include("pass_no_types.hrl"). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
-module more_hrl_usage. | ||
|
||
-include("good.hrl"). | ||
-include("bad.hrl"). | ||
-include("test-good.hrl"). | ||
-include("test-bad.hrl"). | ||
-include("fail_no_types.hrl"). | ||
-include("pass_no_types.hrl"). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-define(THIS_FILE, {has, no, types}). |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be restricted by code, right? Or does Erlang accept, for header files, anything other than
.hrl
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erlang accepts anything. You can 100% write this and it will work…
Why on Earth will you want to do that is a mystery to me, but it's 100% valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant when we're listing the files for analysis we can restrict certain rules to certain file types (not sure if desired).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But wait, our analysis already is scoped, right? If you use a
rebar.config
rule on an.erl
file it shouldn't work, should it? Not sure I've tried it or we test it, but pretty sure there's some restrictions in place.