Sha256: d03d47b450286f70268da81106b96a2f5738d28bff0dd23b33689f7554f9d96a

Contents?: true

Size: 1002 Bytes

Versions: 16

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Sorbet
      # Ensures empty class/module definitions in RBI files are
      # done on a single line rather than being split across multiple lines.
      #
      # @example
      #
      #   # bad
      #   module SomeModule
      #   end
      #
      #   # good
      #   module SomeModule; end
      class SingleLineRbiClassModuleDefinitions < RuboCop::Cop::Base
        extend AutoCorrector

        MSG = "Empty class/module definitions in RBI files should be on a single line."

        def on_module(node)
          return if node.body
          return if node.single_line?

          add_offense(node) do |corrector|
            corrector.replace(node, convert_newlines_to_semicolons(node.source))
          end
        end
        alias_method :on_class, :on_module

        private

        def convert_newlines_to_semicolons(source)
          source.sub(/[\r\n]+\s*[\r\n]*/, "; ")
        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/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.8.6 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.8.5 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.8.4 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.8.3 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.8.2 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.8.1 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.8.0 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.8 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.7 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.6 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.5 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.4 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.3 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.2 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb
rubocop-sorbet-0.7.1 lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb