Sha256: 504e7fcf5b7832300fc82ca65f75329809590726c98932e0a8677aee550378e7

Contents?: true

Size: 1.28 KB

Versions: 127

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module ERBLint
  module Linters
    module Helpers
      # Helpers for writing rules
      module RuleHelpers
        def tags(processed_source)
          processed_source.parser.nodes_with_type(:tag).map { |tag_node| BetterHtml::Tree::Tag.from_node(tag_node) }
        end

        def generate_offense(klass, processed_source, tag, message = nil, replacement = nil)
          message ||= klass::MESSAGE
          klass_name = klass.name.demodulize
          offense = ["#{klass_name}:#{message}", tag.node.loc.source].join("\n")
          add_offense(processed_source.to_source_range(tag.loc), offense, replacement)
        end

        # Generate offense for ERB node tag
        def generate_node_offense(klass, processed_source, node, message = nil)
          message ||= klass::MESSAGE
          offense = ["#{klass.name}:#{message}", node.loc.source].join("\n")
          add_offense(processed_source.to_source_range(node.loc), offense)
        end

        def erb_nodes(processed_source)
          processed_source.parser.ast.descendants(:erb)
        end

        def extract_ruby_from_erb_node(erb_node)
          return unless erb_node.type == :erb

          _, _, code_node = *erb_node
          code_node.loc.source.strip
        end
      end
    end
  end
end

Version data entries

127 entries across 127 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.33.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
primer_view_components-0.25.1 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.32.1 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.32.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.29.1 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.29.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
primer_view_components-0.23.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.28.1 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.28.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.27.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.26.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.25.1 lib/primer/view_components/linters/helpers/rule_helpers.rb
primer_view_components-0.22.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
primer_view_components-0.21.1 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.25.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.24.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
primer_view_components-0.21.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
primer_view_components-0.20.1 lib/primer/view_components/linters/helpers/rule_helpers.rb
primer_view_components-0.20.0 lib/primer/view_components/linters/helpers/rule_helpers.rb
openproject-primer_view_components-0.23.0 lib/primer/view_components/linters/helpers/rule_helpers.rb