Shopify / erb_lint

Lint your ERB or HTML files
MIT License
642 stars 119 forks source link

Ability to run under rspec/test-unit #217

Closed tammersaleh closed 3 years ago

tammersaleh commented 3 years ago

Is it possible to run erb-lint against all templates during a test run? Something like what's provided by better-html:

# RAILS_ROOT/spec/views/erb_safety_spec.rb

require 'better_html/test_helper/safe_erb_tester'
require 'rails_helper'

ERB_GLOB = Rails.root.join('app/views/**/{*.htm,*.html,*.htm.erb,*.html.erb,*.html+*.erb}')

RSpec.describe 'safe_erb' do # rubocop:disable RSpec/DescribeClass
  include BetterHtml::TestHelper::SafeErbTester

  Dir[ERB_GLOB].each do |filename|
    pathname = Pathname.new(filename).relative_path_from(Rails.root)
    it "validates #{pathname}" do
      data = File.read(filename)
      BetterHtml::BetterErb::ErubiImplementation.new(data).validate!
      assert_erb_safety(data)
    end
  end
end
rafaelfranca commented 3 years ago

Thank you for the issue. It should be if you use the classes that exist in this tool.

For example this is the Runner class that is responsible for running all the linters against the config https://github.com/Shopify/erb-lint/blob/master/lib/erb_lint/runner.rb#L5.

We have no interest in support or document that use case though.