Rubocop: Autocorrect reacts to EmptyLineAfterMagicComment config

Created on 6 Aug 2019  路  3Comments  路  Source: rubocop-hq/rubocop

Basic Problem

When running rubocop -a to fix auto-correctable offenses, # frozen_string_literal: true and a blank line are added to the top of every file. It would be desirable for this newline not to be present in the case of Layout/EmptyLineAfterMagicComment being disabled.

Solution

When running rubocop -a, do not place an empty line after # frozen_string_literal: true if Layout/EmptyLineAfterMagicComment is disabled for the given file or altogether.

enhancement

Most helpful comment

@Drenmi Thanks, I added a PR for this: https://github.com/rubocop-hq/rubocop/pull/7310

All 3 comments

I believe a cop should never change its behaviour because another cop is disabled.

I think there is a simpler solution: FrozenStringLiteralComment should only be concerned about inserting/removing the magic comment as necessary but not about its spacing. So it should never insert empty lines.

The spacing would then be the responsibility of EmptyLineAfterMagicComment.

I believe a cop should never change its behaviour because another cop is disabled.

This is the ideal scenario. We do have this kind of logic in parts of the codebase at the moment, though I'm not entirely sure it's needed.

I think there is a simpler solution: FrozenStringLiteralComment should only be concerned about inserting/removing the magic comment as necessary but not about its spacing. So it should never insert empty lines.

The spacing would then be the responsibility of EmptyLineAfterMagicComment

I think this sounds reasonable, and is in line with how many other cops work. It is the reason we have the concept of the "correction loop", where after an auto-correct, the file will be re-inspected by all cops, in case the correction caused another offence that can be corrected.

@Drenmi Thanks, I added a PR for this: https://github.com/rubocop-hq/rubocop/pull/7310

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbatsov picture bbatsov  路  3Comments

millisami picture millisami  路  3Comments

bquorning picture bquorning  路  3Comments

cabello picture cabello  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments