Sha256: baeb3da6e0c1be2573e05dedcb71b6cfe7386d1063ff1cf1a2b036c48500d043
Contents?: true
Size: 1.38 KB
Versions: 2
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true require "rubocop" require "json" require "parser/current" require_relative "./../../../yattho/view_components/linters/helpers/deprecated_components_helpers" module RuboCop module Cop module Yattho # This cop ensures that components marked as "deprecated" in `static/statuses.json` are discouraged from use. # # bad # Yattho::BlankslateComponent.new(:foo) # # good # Yattho::Beta::Blankslate.new(:foo) # # bad # Yattho::Tooltip.new(:foo) # # good # Yattho::Alpha::Tooltip.new(:foo) class DeprecatedComponents < BaseCop include ERBLint::Linters::Helpers::DeprecatedComponentsHelpers def on_send(node) return unless node.source.include?("Yattho::") 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yattho_view_components-0.1.1 | lib/rubocop/cop/yattho/deprecated_components.rb |
yattho_view_components-0.0.1 | lib/rubocop/cop/yattho/deprecated_components.rb |