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

Add Lint/UslessArraySplat #3072

Merged
merged 1 commit into from Apr 23, 2016
Merged

Conversation

owst
Copy link
Contributor

@owst owst commented Apr 23, 2016

This new cop will detect useless splats of array literals:

# bad:
x, y = *[1, 2, 3]
# good:
x, y = [1, 2, 3]

# bad: 
x, y = *%w(a b c)
# good:
x. y = %w(a b c)

Also means that #3069 is no longer an issue, since the splat is removed before freeze is added.

Before submitting a PR make sure the following are checked:

  • Wrote good commit messages.
  • Used the same coding conventions as the rest of the project.
  • Feature branch is up-to-date with master (if not - rebase it)
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • All tests are passing.
  • The new code doesn't generate RuboCop offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 23, 2016

Do people really write code like this? :-)

You've got a typo in your commit message.

@owst
Copy link
Contributor Author

owst commented Apr 23, 2016

Good spot on the typo! Re: writing this sort of code, I wouldn't :-) but I got the idea from the report of #3069. AFAICT, it's not possible to correct

FOO = *[1, 2, 3]

so that Style/MutableConstant doesn't trigger:

FOO = *[1, 2, 3].freeze

isn't right, and trying

(*[1, 2, 3]).freeze

is a syntax error (hence rubocop gets into a loop trying to fix the issue). However, with this new cop, the * is first removed, so that the code becomes

FOO = [1, 2, 3].freeze

@bbatsov bbatsov merged commit dac0a6d into rubocop:master Apr 23, 2016
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 23, 2016

Makes sense. Thanks!

Neodelf pushed a commit to Neodelf/rubocop that referenced this pull request Oct 15, 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.

None yet

2 participants