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

Style/SymbolProc-20220930233959 #793

Merged
merged 3 commits into from
Jan 2, 2023

Conversation

github-actions[bot]
Copy link
Contributor

Rubocop challenge!

Style/SymbolProc

Safe autocorrect: No
⚠️ The autocorrect a cop can yield false positives by design.

Description

Overview

Use symbols as procs when possible.

If you prefer a style that allows block for method with arguments,
please set true to AllowMethodsWithArguments.
respond_to , and define_method? methods are allowed by default.
These are customizable with AllowedMethods option.

Examples

# bad
something.map { |s| s.upcase }
something.map { _1.upcase }

# good
something.map(&:upcase)

AllowMethodsWithArguments: false (default)

# bad
something.do_something(foo) { |o| o.bar }

# good
something.do_something(foo, &:bar)

AllowMethodsWithArguments: true

# good
something.do_something(foo) { |o| o.bar }

AllowComments: false (default)

# bad
something.do_something do |s| # some comment
  # some comment
  s.upcase # some comment
  # some comment
end

AllowComments: true

# good  - if there are comment in either position
something.do_something do |s| # some comment
  # some comment
  s.upcase # some comment
  # some comment
end

AllowedMethods: [respond_to, define_method] (default)

# good
respond_to { |foo| foo.bar }
define_method(:foo) { |foo| foo.bar }

AllowedPatterns: [] (default)

# bad
something.map { |s| s.upcase }

AllowedPatterns: [/map/] (default)

# good
something.map { |s| s.upcase }

Auto generated by rubocop_challenger

@mathieujobin mathieujobin merged commit a31c4a1 into master Jan 2, 2023
@mathieujobin mathieujobin deleted the rubocop-challenge/20220930233959 branch January 2, 2023 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant