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

EmptyLiteral autocorrector respects StringLiterals/EnforcedStyle config #2594

Merged
merged 1 commit into from
Jan 8, 2016

Conversation

DNNX
Copy link
Contributor

@DNNX DNNX commented Jan 6, 2016

Before this PR it would replace String.new with '' even if double-quoted string were preferred.

Fixes #2593

@jonas054
Copy link
Collaborator

jonas054 commented Jan 7, 2016

Looks correct, but do we need it? StringLiterals will auto-correct '' to "" in the same run, so from the user's perspective, there's no change. (Unless StringLiterals is disabled, in which case it wouldn't be wrong to respect that decision.)

You forgot to update CHANGELOG, by the way.

@DNNX
Copy link
Contributor Author

DNNX commented Jan 7, 2016

StringLiterals will auto-correct '' to "" in the same run

Hmm, is it because StringLiterals always runs after EmptyLiteral? What determines the order of the cops? Their position in the config file? Or they are always executed in alphabetical order?

@alexdowad
Copy link
Contributor

Hmm, is it because StringLiterals always runs after EmptyLiteral?

Auto-correction goes in a loop until there is nothing left to correct.

@alexdowad
Copy link
Contributor

Looks correct, but do we need it? StringLiterals will auto-correct '' to "" in the same run, so from the user's perspective, there's no change.

From a performance perspective, it's much better to avoid creating new offenses.

@DNNX
Copy link
Contributor Author

DNNX commented Jan 7, 2016

While we're at it. Do I need to check if StringLiterals is enabled here? Is it possible that config.for_cop('Style/StringLiterals') returns nil or raises an error?

@alexdowad
Copy link
Contributor

Is it possible that config.for_cop('Style/StringLiterals') returns nil or raises an error?

Shouldn't happen.

@jonas054
Copy link
Collaborator

jonas054 commented Jan 7, 2016

From a performance perspective, it's much better to avoid creating new offenses.

True, but performance isn't everything. There's also simplicity, clarity, and generality.

@alexdowad
Copy link
Contributor

True, but performance isn't everything. There's also simplicity, clarity, and generality.

Definitely, performance is not everything. But personally, I don't feel that this patch sacrifices anything in clarity. And we have a serious, serious problem with autocorrection performance right now. We have an open issue for this right now -- #2047.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 8, 2016

I'm ok with the proposed change, provided it gets a proper changelog entry. My only concern are the growing number of inter-cop deps. Maybe some preferences (like string literals, etc) should eventually be moved to a more generic location. At any rate - this is not very important right now.

…edStyle`

Before this commit it would replace `String.new` with `''` even if
double-quoted string are preferred.

Fixes rubocop#2593
@DNNX DNNX force-pushed the empty-string-fix branch from 71ea175 to 6385544 Compare January 8, 2016 12:56
@DNNX
Copy link
Contributor Author

DNNX commented Jan 8, 2016

CI green, no conflicts

bbatsov added a commit that referenced this pull request Jan 8, 2016
EmptyLiteral autocorrector respects StringLiterals/EnforcedStyle config
@bbatsov bbatsov merged commit 7eb824d into rubocop:master Jan 8, 2016
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

Successfully merging this pull request may close these issues.

4 participants