Sha256: 791b1dd1d4e23888aeb76cdf6c399d7163837b21113488aa69c711e7e0875190

Contents?: true

Size: 941 Bytes

Versions: 16

Compression:

Stored size: 941 Bytes

Contents

# frozen_string_literal: true

require "rubocop"

module RuboCop
  module Cop
    module Sorbet
      # Ensures all constants used as `T.type_alias` are using CamelCase.
      #
      # @example
      #
      #   # bad
      #   FOO_OR_BAR = T.type_alias { T.any(Foo, Bar) }
      #
      #   # good
      #   FooOrBar = T.type_alias { T.any(Foo, Bar) }
      class TypeAliasName < RuboCop::Cop::Base
        MSG = "Type alias constant name should be in CamelCase"

        # @!method underscored_type_alias?(node)
        def_node_matcher(:underscored_type_alias?, <<-PATTERN)
          (casgn
            _
            /_/                                  # Name matches underscore
            (block
              (send (const nil? :T) :type_alias)
              ...
            )
          )
        PATTERN

        def on_casgn(node)
          add_offense(node) if underscored_type_alias?(node)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubocop-sorbet-0.8.7 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.8.6 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.8.5 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.8.4 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.8.3 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.8.2 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.8.1 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.8.0 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.8 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.7 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.6 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.5 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.4 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.3 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.2 lib/rubocop/cop/sorbet/type_alias_name.rb
rubocop-sorbet-0.7.1 lib/rubocop/cop/sorbet/type_alias_name.rb