Sha256: a57babdcb6891f3cf23d639e43eed19b9d8b7959e020aba5c52796f84b819675

Contents?: true

Size: 1.16 KB

Versions: 26

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Naming
      # Checks for class and module names with
      # an underscore in them.
      #
      # `AllowedNames` config takes an array of permitted names.
      # Its default value is `['module_parent']`.
      # These names can be full class/module names or part of the name.
      # eg. Adding `my_class` to the `AllowedNames` config will allow names like
      # `my_class`, `my_class::User`, `App::my_class`, `App::my_class::User`, etc.
      #
      # @example
      #   # bad
      #   class My_Class
      #   end
      #   module My_Module
      #   end
      #
      #   # good
      #   class MyClass
      #   end
      #   module MyModule
      #   end
      #   class module_parent::MyModule
      #   end
      class ClassAndModuleCamelCase < Base
        MSG = 'Use CamelCase for classes and modules.'

        def on_class(node)
          allowed = /#{cop_config['AllowedNames'].join('|')}/
          name = node.loc.name.source.gsub(allowed, '')
          return unless /_/.match?(name)

          add_offense(node.loc.name)
        end
        alias on_module on_class
      end
    end
  end
end

Version data entries

26 entries across 22 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/naming/class_and_module_camel_case.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/naming/class_and_module_camel_case.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/naming/class_and_module_camel_case.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/naming/class_and_module_camel_case.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/naming/class_and_module_camel_case.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/naming/class_and_module_camel_case.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/naming/class_and_module_camel_case.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/naming/class_and_module_camel_case.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.40.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.39.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.38.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.37.1 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.37.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.36.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.35.1 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.35.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.34.1 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.34.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb
rubocop-1.33.0 lib/rubocop/cop/naming/class_and_module_camel_case.rb