Skip to content

Add frozen_string_literal pragma to generated files #2235

Open
@klyonrad

Description

@klyonrad

Up for discussion obviously

Is your feature request related to a problem? Please describe.

I'm always frustrated when the files from a generator are generated do result in linting tools (mostly rubocop) screaming at me.

I know obviously that completely adhering to one style is obviously a bit pointless. But the first one rubocop offense top of the file. String literals are not frozen. And a rspec test file completely full of string literals. This is not a Style issue, it is a technical issue.

I think it would help developer UX when that would not be necessary to change after the generator execution.

Describe the solution you'd like

Template files start with the now very common frozen_string_literal: true pragma.

Describe alternatives you've considered

  • Excluding the cop check from spec directory. Uncool
  • Freeze strings by default when executing the ruby interpreter? yeah, not happening. To cumbersome, too brittle.

Additional context

It was even decided that string literals will not be frozen by default with Ruby 3. So the problem will not go away automatically when the rails projects are getting updated to ruby 3

See: https://bugs.ruby-lang.org/issues/11473#note-53

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions