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

Make Lint/RedundantWithIndex cop aware of offset argument #4977

Conversation

koic
Copy link
Member

@koic koic commented Nov 1, 2017

Follow up of #4796 (comment).

Actually, it is only with_index method that accepts an offset argument. with_with_index method doesn't accept offset argument.
However, I think that the same AST will be low maintenance cost.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • 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(rake spec) are passing.
  • The new code doesn't generate RuboCop offenses that are checked by rake internal_investigation.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Updated cop documentation with rake generate_cops_documentation (required only when you've added a new cop or changed the configuration/documentation of an existing cop).

Follow up of rubocop#4796 (comment).

Actually, it is only `with_index` method that accepts an offset argument.
`with_with_index` method doesn't accept offset argument.
However, I think that the same AST will be low maintenance cost.
@bbatsov bbatsov merged commit ec8f16b into rubocop:master Nov 1, 2017
@koic koic deleted the make_lint_redundant_with_index_cop_aware_of_offset_arg branch November 1, 2017 08:08
@@ -69,7 +69,7 @@ def message(node)
end

def with_index_range(send)
range_between(send.loc.selector.begin_pos, send.loc.selector.end_pos)
range_between(send.loc.selector.begin_pos, send.source.length)
Copy link
Collaborator

@Drenmi Drenmi Nov 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually only works incidentally because processed_source happens to start at the beginning of the node, which is kind of frail. Would probably use send.loc.expression.end_pos instead of send.source.length.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a PR #4983. Thanks!

@Drenmi
Copy link
Collaborator

Drenmi commented Nov 1, 2017

Actually, it is only with_index method that accepts an offset argument. with_with_index method doesn't accept offset argument.

I think it's perfectly fine, since ... is "zero or more", and #each_with_index has arity 0, so no false positives possible. 🙂

Hm. Except perhaps each_with_index(&block)? 🤔

koic added a commit to koic/rubocop that referenced this pull request Nov 2, 2017
Follow up of rubocop#4977 (comment).

This commit fixes the following potential problem.

> This actually only works incidentally because processed_source happens
> to start at the beginning of the node, which is kind of frail.
@koic
Copy link
Member Author

koic commented Nov 2, 2017

Hm. Except perhaps each_with_index(&block)?

Oh... I overlooked this case 💦 I'd like to open a PR sometime.

bbatsov pushed a commit that referenced this pull request Nov 2, 2017
Follow up of #4977 (comment).

This commit fixes the following potential problem.

> This actually only works incidentally because processed_source happens
> to start at the beginning of the node, which is kind of frail.
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.

3 participants