Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-correct should not introduce new offenses #744

Closed
sferik opened this issue Jan 18, 2014 · 1 comment
Closed

Auto-correct should not introduce new offenses #744

sferik opened this issue Jan 18, 2014 · 1 comment
Assignees

Comments

@sferik
Copy link
Contributor

sferik commented Jan 18, 2014

When I run rubocop --auto-correct on a project for the first time, it normally fixes dozens of offenses but then, if I run rubocop --auto-correct again (immediately, without making any other changes) it finds additional offenses that it didn’t catch the first time.

I think what’s happening is that one cop is making corrections in a way that introduces new offenses for a different cop. Adding auto-correct to more cops may make this problem even worse.

Here is a concrete example:

def call
  raise NotImplementedError,
        'Method #call should be overridden in child classes'
end

If I run rubycop --auto-correct on this code, the following offense will be automatically fixed:

SignalException: Use `fail` instead of `raise` to signal exceptions.

This will result in a method that looks like this:

def call
  fail NotImplementedError,
        'Method #call should be overridden in child classes'
end

This method now contains a new offense, which didn’t exist before auto-correcting:

AlignParameters: Align the parameters of a method call if they span more than one line.

If I run, rubycop --auto-correct again, this offense will be fixed:

def call
  fail NotImplementedError,
       'Method #call should be overriden in child classes'
end

This is the correct outcome but it shouldn’t require running rubocop --auto-correct twice.

I believe this is happening because fail is one letter shorter than raise and the SignalException cop only changes the keyword itself, not the alignment of parameters that span multiple lines.

Arguably, this is just a defect in the autocorrect method of the SignalException cop but I believe there are other examples of this as well. I will update this issue as I find them.

@jonas054
Copy link
Collaborator

I'll try to fix this.

@ghost ghost assigned jonas054 Jan 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants