Shopify / ruby-style-guide

Shopify’s Ruby Style Guide

Home Page:https://ruby-style-guide.shopify.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

disable Style/ClassAndModuleChildren cop for tests

eljojo opened this issue · comments

Hello friends,
I'm opening this issue to request disabling the Style/ClassAndModuleChildren for files in a component's test folder.

do you think such cop makes sense?

screen shot 2018-01-15 at 17 05 22

The Style Guide enforces the nested syntax to define classes and modules: https://github.com/Shopify/ruby-style-guide#syntax

In minitest tests are classes like any other, therefore it wouldn't be consistent to not enforce the rule in test files. Maybe you're facing a problem that can be solved differently?

For more context about the decision, here's the original PR: #32

Here's my reasoning for why it'd be good to disable this cop:

  • a lot of our tests already break the cop (ag "::.+ < .+Test")
  • testing A::B::C::D would mean we have to indent 4 levels, wouldn't it? are we OK with that?
  • other than avoiding typing the module name for namespaced test helper modules, would we really benefit from having proper constant name lookup?
  • someone in the original PR also suggested disabling it for tests: #32 (comment)

a lot of our tests already break the cop (ag "::.+ < .+Test")

It's up to each maintainer to make sure that their codebase follows the style guide. The responsibilities in core are split in components and team. The Checkouts components, for instance, is the bigger and more complex component of all and at the same time is 100% compliant with Shopify's Ruby Style Guide. It's kinda boring to fix code style violations but you just do it once and you're done. Policial is a tool created to help us prevent new violations.

testing A::B::C::D would mean we have to indent 4 levels, wouldn't it? are we OK with that?

That's exactly the style enforced here: indentation instead of ::. However, regardless of the style adopted, we should avoid more than 2 levels of namespacing.

other than avoiding typing the module name for namespaced test helper modules, would we really benefit from having proper constant name lookup?

Consistency.

someone in the original PR also suggested disabling it for tests: #32 (comment)

In the end it didn't make sense not to enforce the rule for tests, as Shopify Core's CI has shown.

Closing this due to inactivity. Feel free to reopen it if you'd like to restart discussions.