reid-rigo
Code review request: codeowners package
Hello, I’m new to Elixir and created this package, which is the adaptation of some Ruby code I wrote, as a learning exercise: codeowners | Hex
I’m looking for feedback on:
- How to make this code more idiomatic
- More appropriate functions/modules to use
- Best practices for libraries
Feedback is welcome here or in Github
Most Liked
sodapopcan
For me it’s not about refactoring—a global rename is a global rename—it’s about ease of reading. When I see __MODULE__ I immediately think “local.” Seeing a fully-qualified self-referencing module name always causes a bit of a jarring pause where I have to go and confirm that it is indeed referencing itself. This is indeed on the minor end of readability issues and is not a hill I’d die on. I do, however, vehemently disagree with the advice in that guide to use an alias if you want “a prettier name”
If it weren’t for the few legitimate uses cases it has, I wouldn’t be upset if the :as option for alias were removed from the language.
RudManusachi
Hi, @reid-rigo
and welcome!
I’d point you to this style guide: GitHub - christopheradams/elixir_style_guide: A community driven style guide for Elixir
Use the
__MODULE__pseudo variable when a module refers to itself.
It might look weird at first (becuase of double underscores and all caps) but it’s very common to refer to the module itself.
RudManusachi
One of the point you were asking:
- How to make this code more idiomatic
So I just pointed to what seemed more idiomatic to me ![]()
Based on a suggestion in another thread I tried
#{__MODULE__}, but that outputsElixir.Codeownerswhen I run mix docs.
So it does with any module name, such as: #{Logger} would print "Elixir.Logger". If you want to nicely disregard the prefix Elixir. you could inspect/1 it:
"#{inspect(__MODULE__)}"
See example: elixir/lib/elixir/lib/kernel/utils.ex at c5816a227f5ad295ccbfcc5571308f76190d6bfe · elixir-lang/elixir · GitHub
al2o3cr
Some thoughts, in no particular order:
-
rule_for_pathcould be slightly more efficient if theEnum.reversewas moved intobuildto avoid doing the same computation more than once -
the typespec for
Codeowners.Ruleis not satisfied by the default values in thedefstruct.rule_for_pathcan return a struct containing unexpected types in the “no rule matched” case. -
the use of
File.cwd!inbuildis odd; consider allowing callers to either supply a root directly or as an override. To reduce the need for most callers to pass a root,loadcould do some guessing based on if the supplied file is in adocor.githubdirectory.







