Sha256: 7b8db84d0484f3fd2ec780e8af2b4d3621a1101639f4c59015626a130c032e2f
Contents?: true
Size: 1.38 KB
Versions: 99
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true require "rubocop" require "json" require "parser/current" require_relative "../../../primer/view_components/linters/helpers/deprecated_components_helpers" module RuboCop module Cop module Primer # This cop ensures that components marked as "deprecated" in `static/statuses.json` are discouraged from use. # # bad # Primer::BlankslateComponent.new(:foo) # # good # Primer::Beta::Blankslate.new(:foo) # # bad # Primer::Tooltip.new(:foo) # # good # Primer::Alpha::Tooltip.new(:foo) class DeprecatedComponents < BaseCop include ERBLint::Linters::Helpers::DeprecatedComponentsHelpers def on_send(node) return unless node.source.include?("Primer::") deprecated_components.each do |component| pattern = NodePattern.new("(send #{pattern(component)} :new ...)") add_offense(node, message: message(component)) if pattern.match(node) end end private # Converts a string to acceptable rubocop-ast pattern syntax def pattern(component) Parser::CurrentRuby.parse(component) .to_s .gsub("nil", "nil?") .delete("\n") .gsub(" ", " ") end end end end end
Version data entries
99 entries across 99 versions & 2 rubygems