Sha256: 2cd3d51871e887b3469c1037955ef9a688b5d9bf0b1f2c56c39f16e004e49e7b

Contents?: true

Size: 1.49 KB

Versions: 238

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

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

namespace :ariadne_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(".ariadne-view-components-report.json", "w") do |f|
      f.write(JSON.pretty_generate(stats))
      f.write($INPUT_RECORD_SEPARATOR)
    end
  end
end

Version data entries

238 entries across 238 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.12-x64-mingw-ucrt lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.12-arm64-darwin lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.12-aarch64-linux lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.11 lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.11-x86_64-linux lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.11-x86_64-darwin lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.11-x64-mingw32 lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.11-x64-mingw-ucrt lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.11-arm64-darwin lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.11-aarch64-linux lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.10 lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.10-x86_64-linux lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.10-x86_64-darwin lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.10-x64-mingw32 lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.10-x64-mingw-ucrt lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.10-arm64-darwin lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.10-aarch64-linux lib/tasks/ariadne_view_components.rake
ariadne_view_components-0.0.9 lib/tasks/ariadne_view_components.rake