Skip to content

Commit

Permalink
separate rubocop configuration for tests
Browse files Browse the repository at this point in the history
As stated in commits e423977, 33e373c, fddebc3:

> Ideally I would've configured the extra `AllowedMethods` to only apply
> to the tests, but I couldn't find a simple way to do that with the
> rubocop configuration. It might be worth extracting a separate rubocop
> configuration for the tests.

Here we do just that.
  • Loading branch information
nitishr authored and floehopper committed Mar 1, 2025
1 parent fbf023d commit fb6453e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
34 changes: 0 additions & 34 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,13 @@ Layout/LineLength:
Gemspec/RequiredRubyVersion:
Enabled: false

# It can be useful to violate this cop in tests in order to be more explicit
Lint/UselessTimes:
Exclude:
- 'test/**/*.rb'

# It can be useful to violate this cop in tests
Lint/EmptyClass:
Exclude:
- 'test/**/*.rb'

# It can be useful to violate this cop in tests when testing methods that accept a block
Lint/EmptyBlock:
Exclude:
- 'test/**/*.rb'

# There are a mix of styles in the tests and so I don't think it's worth enforcing for now
Naming/VariableNumber:
Exclude:
- 'test/**/*.rb'

# These methods from Ruby core are legitimately overridden in the tests
Style/OptionalBooleanParameter:
AllowedMethods:
- respond_to?
- public_methods
- protected_methods
- private_methods
- public_instance_methods
- protected_instance_methods
- private_instance_methods

# This cop is useful for required environment variables, but not for optional ones
Style/FetchEnvVar:
AllowedVars:
- MOCHA_RUN_INTEGRATION_TESTS

Naming/FileName:
ExpectMatchingDefinition: true
CheckDefinitionPathHierarchyRoots:
- test/unit
- test/acceptance
Exclude:
- lib/mocha/version.rb
- lib/mocha/minitest.rb
Expand Down
33 changes: 33 additions & 0 deletions test/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
inherit_from: ../.rubocop.yml # Inherit from the global configuration

# It can be useful to violate this cop in tests in order to be more explicit
Lint/UselessTimes:
Enabled: false

# It can be useful to violate this cop in tests
Lint/EmptyClass:
Enabled: false

# It can be useful to violate this cop in tests when testing methods that accept a block
Lint/EmptyBlock:
Enabled: false

# There are a mix of styles in the tests and so I don't think it's worth enforcing for now
Naming/VariableNumber:
Enabled: false

# These methods from Ruby core are legitimately overridden in the tests
Style/OptionalBooleanParameter:
AllowedMethods:
- respond_to?
- public_methods
- protected_methods
- private_methods
- public_instance_methods
- protected_instance_methods
- private_instance_methods

Naming/FileName:
CheckDefinitionPathHierarchyRoots:
- test/unit
- test/acceptance

0 comments on commit fb6453e

Please sign in to comment.