Components
Use this rule when the architecture decision is “this kind of code should not exist here at all.”
component(:services, in: "app/services/**/*.rb")
.must_be_empty(because: "behavior belongs on models")
Rule id: components.empty
Every file that lands in the component fails the check:
[error] services must stay empty [components.empty]
app/services/create_user.rb:1:1
→ 1 │ class CreateUser
│ ^
2 │ def perform
note: app/services/create_user.rb belongs to services
reason: behavior belongs on models
The because: reason is optional but recommended. It appears in the failure
and tells the reader where the code should go instead. Like every rule reason,
it stays outside the diagnostic fingerprint.
When To Use It
Use it when a convention bans a whole category of objects. Vanilla Rails in
the 37signals style has no service objects, form objects, or policy objects;
architecture :vanilla_rails uses this rule for those directories. See the
Vanilla Rails guide.
It also helps during migrations: once a legacy directory has been emptied,
must_be_empty keeps it empty.