Sha256: 93a2185c4049f129c6333b9da545177cf8ec38c1b43a0bda65c8d1769287c3f9
Contents?: true
Size: 1.38 KB
Versions: 80
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
80 entries across 80 versions & 2 rubygems