Sha256: 8ae572d3e8768c750f25bed1f2266f1effd67aa8760c45e1b5ce29b96af287b8

Contents?: true

Size: 1.49 KB

Versions: 73

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

ERB_GLOB = "**/*.html{+*,}.erb"
RB_GLOB = "**/*.rb"
BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/.freeze # copied from Rails: action_view/template/handlers/erb/erubi.rb

namespace :primer_view_components do
  desc "Report arguments used in each component"
  task :report, [:paths] do |_, args|
    require "rubocop"
    require "better_html"
    require "better_html/parser"
    require "erb_lint/processed_source"
    require_relative "helpers/ast_processor"

    paths = args[:paths].split
    stats = {}

    rb_files = paths.reduce([]) { |mem, path| mem + Dir[File.join(path, RB_GLOB)] }

    rb_files.each do |f|
      ast = RuboCop::AST::ProcessedSource.from_file(f, RUBY_VERSION.to_f).ast
      AstProcessor.process_ast(ast, stats)
    end

    erb_files = paths.reduce([]) { |mem, path| mem + Dir[File.join(path, ERB_GLOB)] }

    erb_files.each do |f|
      erb_ast = ERBLint::ProcessedSource.new(f, File.read(f)).ast

      erb_ast.descendants(:erb).each do |erb_node|
        indicator, _, code_node, = *erb_node

        next if indicator&.children&.first == "#" # don't analyze comments

        trimmed_source = code_node.loc.source.sub(BLOCK_EXPR, "").strip
        ast = RuboCop::AST::ProcessedSource.new(trimmed_source, RUBY_VERSION.to_f).ast
        AstProcessor.process_ast(ast, stats)
      end
    end

    File.open(".primer-view-components-report.json", "w") do |f|
      f.write(JSON.pretty_generate(stats))
      f.write($INPUT_RECORD_SEPARATOR)
    end
  end
end

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
primer_view_components-0.0.112 lib/tasks/primer_view_components.rake
primer_view_components-0.0.111 lib/tasks/primer_view_components.rake
primer_view_components-0.0.110 lib/tasks/primer_view_components.rake
primer_view_components-0.0.109 lib/tasks/primer_view_components.rake
primer_view_components-0.0.108 lib/tasks/primer_view_components.rake
primer_view_components-0.0.107 lib/tasks/primer_view_components.rake
primer_view_components-0.0.106 lib/tasks/primer_view_components.rake
primer_view_components-0.0.105 lib/tasks/primer_view_components.rake
primer_view_components-0.0.104 lib/tasks/primer_view_components.rake
primer_view_components-0.0.103 lib/tasks/primer_view_components.rake
primer_view_components-0.0.102 lib/tasks/primer_view_components.rake
primer_view_components-0.0.101 lib/tasks/primer_view_components.rake
primer_view_components-0.0.100 lib/tasks/primer_view_components.rake
primer_view_components-0.0.99 lib/tasks/primer_view_components.rake
primer_view_components-0.0.98 lib/tasks/primer_view_components.rake
primer_view_components-0.0.97 lib/tasks/primer_view_components.rake
primer_view_components-0.0.96 lib/tasks/primer_view_components.rake
primer_view_components-0.0.95 lib/tasks/primer_view_components.rake
primer_view_components-0.0.94 lib/tasks/primer_view_components.rake
primer_view_components-0.0.93 lib/tasks/primer_view_components.rake