Skip to content

Considering .arb a ruby file leads to 'frozen_string_literal' warnings #13684

@tagliala

Description

@tagliala

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

  1. echo "h1 'Hello World'" > index.html.arb
  2. rubocop index.html.arb
  3. Fix the issue
  4. 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'
  1. 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]

Ref: activeadmin/activeadmin#8600

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy