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

Cop idea: standardize on #then instead of #yield_self #10522

Closed
dgollahon opened this issue Apr 10, 2022 · 0 comments · Fixed by #10526
Closed

Cop idea: standardize on #then instead of #yield_self #10522

dgollahon opened this issue Apr 10, 2022 · 0 comments · Fixed by #10526

Comments

@dgollahon
Copy link
Contributor

dgollahon commented Apr 10, 2022

Is your feature request related to a problem? Please describe.

It seems like it would be nice to have a consistent style for then v.s. yield_self like there are cops for some Enumerable methods.

Describe the solution you'd like

A new cop with autocorrect (maybe configurable style?) that converts #yield_self to #then. It would be unsafe to autocorrect.

Describe alternatives you've considered

N/A

Additional context

Not sure this is a high priority/huge need, but I thought I would share the idea. Thanks!

ydah added a commit to ydah/rubocop that referenced this issue Apr 11, 2022
Resolve: rubocop#10522.

This cop enforces the use of consistent method names
from the Object class.

You can customize the mapping from undesired method
to desired method.
e.g. to use `yield_self` over `then`:

```yaml
Style/CollectionMethods:
  PreferredMethods:
    then: yield_self
```

## example

```ruby
# bad
obj.yield_self

# good
obj.then
```
ydah added a commit to ydah/rubocop that referenced this issue Apr 12, 2022
Resolve: rubocop#10522.

This cop enforces the use of consistent method names
`Object#yield_self` or `Object#then`.

## example

```ruby
# EnforcedStyle: then (default)

# bad
obj.yield_self { |x| x.do_something }

# good
obj.then { |x| x.do_something }
```

```ruby
# EnforcedStyle: yield_self

# bad
obj.then { |x| x.do_something }

# good
obj.yield_self { |x| x.do_something }
```
ydah added a commit to ydah/rubocop that referenced this issue Apr 12, 2022
Resolve: rubocop#10522.

This cop enforces the use of consistent method names
`Object#yield_self` or `Object#then`.

## example

```ruby
# EnforcedStyle: then (default)

# bad
obj.yield_self { |x| x.do_something }

# good
obj.then { |x| x.do_something }
```

```ruby
# EnforcedStyle: yield_self

# bad
obj.then { |x| x.do_something }

# good
obj.yield_self { |x| x.do_something }
```
ydah added a commit to ydah/rubocop that referenced this issue Apr 16, 2022
Resolve: rubocop#10522.

This cop enforces the use of consistent method names
`Object#yield_self` or `Object#then`.

## example

```ruby
# EnforcedStyle: then (default)

# bad
obj.yield_self { |x| x.do_something }

# good
obj.then { |x| x.do_something }
```

```ruby
# EnforcedStyle: yield_self

# bad
obj.then { |x| x.do_something }

# good
obj.yield_self { |x| x.do_something }
```
ydah added a commit to ydah/rubocop that referenced this issue Apr 19, 2022
Resolve: rubocop#10522.

This cop enforces the use of consistent method names
`Object#yield_self` or `Object#then`.

## example

```ruby
# EnforcedStyle: then (default)

# bad
obj.yield_self { |x| x.do_something }

# good
obj.then { |x| x.do_something }
```

```ruby
# EnforcedStyle: yield_self

# bad
obj.then { |x| x.do_something }

# good
obj.yield_self { |x| x.do_something }
```
ydah added a commit to ydah/rubocop that referenced this issue Apr 19, 2022
Resolve: rubocop#10522.

This cop enforces the use of consistent method names
`Object#yield_self` or `Object#then`.

## example

```ruby
# EnforcedStyle: then (default)

# bad
obj.yield_self { |x| x.do_something }

# good
obj.then { |x| x.do_something }
```

```ruby
# EnforcedStyle: yield_self

# bad
obj.then { |x| x.do_something }

# good
obj.yield_self { |x| x.do_something }
```
bbatsov pushed a commit that referenced this issue Apr 20, 2022
Resolve: #10522.

This cop enforces the use of consistent method names
`Object#yield_self` or `Object#then`.

## example

```ruby
# EnforcedStyle: then (default)

# bad
obj.yield_self { |x| x.do_something }

# good
obj.then { |x| x.do_something }
```

```ruby
# EnforcedStyle: yield_self

# bad
obj.then { |x| x.do_something }

# good
obj.yield_self { |x| x.do_something }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants