Sha256: 607166e78e4fb42ea0c39bc29efa66607a363feace4624e0dd7e21387dc253f4
Contents?: true
Size: 1.22 KB
Versions: 46
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true require "rubocop" module RuboCop module Cop module AnyCable # Checks for instance variable usage inside subscriptions. # # @example # # bad # class MyChannel < ApplicationCable::Channel # def subscribed # @post = Post.find(params[:id]) # stream_from @post # end # end # # # good # class MyChannel < ApplicationCable::Channel # def subscribed # post = Post.find(params[:id]) # stream_from post # end # end # class InstanceVars < RuboCop::Cop::Cop MSG = "Channel instance variables are not supported in AnyCable. Use `state_attr_accessor` instead" def on_class(node) find_nested_ivars(node) do |nested_ivar| add_offense(nested_ivar) end end private def find_nested_ivars(node, &block) node.each_child_node do |child| if child.ivasgn_type? || child.ivar_type? yield(child) elsif child.children.any? find_nested_ivars(child, &block) end end end end end end end
Version data entries
46 entries across 46 versions & 2 rubygems