rubocop how do you fix Missing magic comment

american-ninja-warrior picture american-ninja-warrior · Oct 31, 2017 · Viewed 12.8k times · Source

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?

Answer

spickermann picture spickermann · Oct 31, 2017

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.