rubyrubygemsrubocop

rubocop how do you fix Missing magic comment


I have a library of ruby code, and to look for defects I run

$ rubocop

And I get

$ rubocop
Inspecting 153 files
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCWCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCWCCCCCCCWWCCCCC

Offenses:

Gemfile:1:1: C: Missing magic comment # frozen_string_literal: true.
source "https://rubygems.org"

What modifications are required in my Gemfile to make rubocop not complain?


Solution

  • Just add

    # frozen_string_literal: true
    

    to the first line of each Ruby file. Or run

    rubocop -a
    

    to allow Rubocop to fix all offenses automatically that it is able to fix.

    Btw. I like Rubocop and use it myself, but I wouldn't call the things it finds defects. I see the list more like suggestions or reasons for a discussion with my co-workers.