-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Description
As per #5591, .arb
files are considered Ruby extensions
However, they work as templates like .erb
or .haml
In fact, they are being using in this way: https://github.com/activeadmin/arbre/blob/97da46273c0897aa5d695be56a055c74fb7e6085/lib/arbre/rails/template_handler.rb
Expected behavior
- Do not consider
.arb
Ruby files; or - Disable
Style/FrozenStringLiteralComment
by default for that extension
Actual behavior
$ cat index.html.arb
h1 'Hello World'
$ rubocop --debug index.html.arb
For ./: Default configuration from ~/.rvm/gems/ruby-3.4.1/gems/rubocop-1.70.0/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning ,/index.html.arb
Loading cache from ~/.cache/rubocop_cache/path/to/cache
C
Offenses:
index.html.arb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
h1 'Hello World'
^
1 file inspected, 1 offense detected, 1 offense autocorrectable
Finished in 0.06852099997922778 seconds
Steps to reproduce the problem
echo "h1 'Hello World'" > index.html.arb
rubocop index.html.arb
- Fix the issue
- Create a file
arbre_frozen.rb
with the following content:
# frozen_string_literal: true
require 'bundler/inline'
begin
gemfile(true) do
source 'https://rubygems.org'
gem 'arbre'
gem 'rails'
end
require 'arbre'
require 'arbre/railtie'
rescue Gem::LoadError => e
puts "\nMissing Dependency:\n#{e.backtrace.first} #{e.message}"
rescue LoadError => e
puts "\nError:\n#{e.backtrace.first} #{e.message}"
exit 1
end
class FileTemplate
attr_reader :source
def initialize(file_path)
@source = File.read(file_path)
end
end
def render_arb_file(file_path, assigns = {})
template = FileTemplate.new(file_path)
handler = Arbre::Rails::TemplateHandler.new
code = handler.call(template)
eval(code, binding)
end
render_arb_file 'index.html.arb'
- Run
$ RUBYOPT='-w' ruby arbre_frozen.rb
Check the output:
(eval at arbre_test.rb:36):2: warning: 'frozen_string_literal' is ignored after any tokens
RuboCop version
1.70.0 (using Parser 3.3.6.0, rubocop-ast 1.37.0, analyzing as Ruby 2.7, running on ruby 3.4.1) [x86_64-darwin24]
Metadata
Metadata
Assignees
Labels
No labels