Sha256: cb9696f52d7027c2dbfd5f11a7b7212895b8b6563624ea85f4d0b5c81b912d0c
Contents?: true
Size: 1.03 KB
Versions: 6
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true require "rubocop" # :nocov: module RuboCop module Cop module Ariadne # This cop ensures that tags are not set with ||= # # bad # @attributes[:tag] ||= :h1 # # good # @attributes[:tag] = fetch_or_raise(TAG_OPTIONS, tag) # # good # @attributes[:tag] = :h2 class NoTagMemoize < RuboCop::Cop::Cop INVALID_MESSAGE = <<~STR Avoid `[:tag] ||=`. Instead, try one of the following: - Don't allow consumers to update the tag by having a fixed tag (e.g. `attributes[:tag] = :div`) - Use the `fetch_or_raise` helper to only allow a tag from a restricted list. STR def_node_search :tag_memoized?, <<~PATTERN (or-asgn (send _ _ (sym :tag) ) _ ) PATTERN def on_or_asgn(node) add_offense(node, message: INVALID_MESSAGE) if tag_memoized?(node) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems