Class: RuboCop::Cop::Codeur::RailsAppPatterns

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/codeur/rails_app_patterns.rb

Overview

This cop makes sure that Rails app only uses patterns (app subdirectories) defined in Cop config.

Examples:

ForbiddenPatterns: [presenters, view_objects, uploaders, modules]

# bad
app/presenters/order_presenter.rb

# bad
app/modules/stuffy.rb

# good
app/view_components/order_component.rb

# good
app/models/concerns/stuffy.rb

AllowedPatterns: [assets, controllers, javascript, jobs, mailers, models, views]

# bad
app/controller/some_controller.rb

# good
app/controllers/some_controller.rb

Constant Summary collapse

MSG_FORBIDDEN =
'`%<pattern>s` are forbidden.'
MSG_NOT_ALLOWED =
'`%<pattern>s` are not allowed. Allowed patterns are: %<allowed_patterns>s.'

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



33
34
35
36
37
38
# File 'lib/rubocop/cop/codeur/rails_app_patterns.rb', line 33

def on_new_investigation
  file_path = processed_source.file_path
  return if config.file_to_exclude?(file_path)

  for_bad_patterns(file_path) { |msg| add_global_offense(msg, severity: :warning) }
end