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

New Rule: No Import Type #323

Open
paulo-ferraz-oliveira opened this issue Sep 28, 2023 · 0 comments
Open

New Rule: No Import Type #323

paulo-ferraz-oliveira opened this issue Sep 28, 2023 · 0 comments
Labels

Comments

@paulo-ferraz-oliveira
Copy link
Collaborator

paulo-ferraz-oliveira commented Sep 28, 2023

Name

no_import_type

Brief Description

It is possible that a new import_type directive (⚠️ a previous link was removed - though GitHub doesn't seem to update the target - so that this rule suggestion is not poorly interpreted as an "attack" on the functionality...) lands in OTP soon (27 or later, I imagine). While it may have uses in some specific cases, namely, as the proposer mentions, large code bases, it can easily be avoided in smaller code bases. elvis_core shall propose this rule as "enabled by default".

Reasoning

There seems to be some value in the use of the directive:

  • for large code bases, where the use of "externally-defined" types is done by means of an auxiliary (internal) type
  • for potential removal of boilerplate, also potentially at the expense of more "difficult to reason about" code: where does the type come from? (it might be Ok if you use a language server, but not all developers do, and some might actually prefer the clarify of having Module:<type>)

but it's probably best to start by avoiding it (as we propose avoiding import). elvis_core proposes, doesn't force, and one can always go about using disable to negative the effect of the new rule 😄.

Refactoring Proposal

Instead of -import_type(m, [t/0])., then t, simply use m:t().


This would potentially be a breaking change, depending on how we consider that to be (we're not changing the interface, but adding a rule, which may cause issues in flows with warnings_as_errors) but the MIGRATION.md file hasn't been updated in a while, either.

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

1 participant