Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 569
american-ninja-warrior Avatar asked Oct 31 '17 00:10

american-ninja-warrior


2 Answers

If you want to ignore it, add to your .rubocop.yml

Style/FrozenStringLiteralComment:
  Enabled: false

But may be you want to know what "Magic comment" is, especially if you're using Ruby 2.x

like image 61
Constantin De La Roche Avatar answered Nov 16 '22 00:11

Constantin De La Roche


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.

like image 25
spickermann Avatar answered Nov 15 '22 22:11

spickermann