rubocop-rspec
rubocop-rspec copied to clipboard
Cop idea: [Factory girl] Enforce consistent usage of parentheses in factory girl methods
I'm working on a code base where I have both styles of using factory:
create(:user, name: 'John') and create :user, name: 'John;
it will be good if one of those styles is required.
Note: parentheses may be required in nested associations no matter the style, like in:
create :account, user: create(:user, name 'John')
I feel this is more general style choice of whether method calls should use parentheses or not. Perhaps it would be better to be have this in RuboCop itself?
IMO it's OK to have different method call style for different DSLs. Syle/MethodCallWithArgsParentheses looks for such, but we disable it in the specs, as I can't imagine writting it('some description') or even allow(Foo).to(receive(:bar))
I would love a cop enforcing this. There is usually no standard when regarding factorybot DSL
I think this rule applies to FactoryGirl.
So if there's no such cop in RuboCop itself (couldn't find one quickly), it might be a good idea to implement it there.
I don't know if the rule accounts for this at all, but I usually use parentheses with a "dsl" unless it's in a class context / macro. So, for the validates example, I usually write it as the guide recommends, but for almost all the rspec methods that aren't describe, context, it, or to, for instance, i typically use parentheses. Like @Darhazer is saying, I don't think a universal rule necessarily matches all DSLs.
Personally, I always write factories with parentheses and that seems like the better default to me (disclaimer: i'm trending towards more parens in most places), but this could easily be configurable and I expect it will be somewhat controversial either way.
Any update with this?
@vmakoed Pull request is always welcome!
I guess this cop should have a style option whether to set parantheses or not.