ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120050] [Ruby master Feature#20922] Should not we omit parentheses in assert calls?
@ 2024-11-29  6:59 mame (Yusuke Endoh) via ruby-core
  2024-11-29  7:30 ` [ruby-core:120051] " mame (Yusuke Endoh) via ruby-core
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-11-29  6:59 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20922 has been reported by mame (Yusuke Endoh).

----------------------------------------
Feature #20922: Should not we omit parentheses in assert calls?
https://bugs.ruby-lang.org/issues/20922

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
I often see the style of omitting parentheses in assert calls, but it leads to annoying warnings in the following case:

```
assert_equal -1, val    #=> warning: ambiguous first argument; put parentheses or a space even after `-` operator
assert_match /foo/, str #=> warning: ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator
```

To deal with this warning, it is necessary to add parentheses only to *some* assert calls.

```
assert_equal 1, one
assert_equal 0, zero
assert_equal(-1, minus_one)
```

Obviously, this is not very cool.

I feel that by these warnings, Ruby says "we should not omit parentheses in assert calls". Is this what matz intended?

If it is the intent, I would like to add parentheses on all assert calls in tests of Ruby and default gems.
If it is not the intent, why don't we remove these warnings?

Note that, as far as I recall, I encountered this problem only with `assert_equal` and `assert_match`.
I don't write parentheses in `p`, `puts`, `attr_reader`, `include`, etc., but all of them rarely accept `-1` and `//` literally as the first argument in real code.
As a milder approach, I came up with an idea to stop the warning only when the method name starts with "assert". It is very ad-hoc, though.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:120051] [Ruby master Feature#20922] Should not we omit parentheses in assert calls?
  2024-11-29  6:59 [ruby-core:120050] [Ruby master Feature#20922] Should not we omit parentheses in assert calls? mame (Yusuke Endoh) via ruby-core
@ 2024-11-29  7:30 ` mame (Yusuke Endoh) via ruby-core
  2024-11-29 11:47 ` [ruby-core:120054] " byroot (Jean Boussier) via ruby-core
  2024-12-12 11:17 ` [ruby-core:120212] " mame (Yusuke Endoh) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-11-29  7:30 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20922 has been updated by mame (Yusuke Endoh).


FYI:

https://github.com/ruby/ruby/commit/6a39e6fc2d0db590ad605f7af9c99d32c64c6a22
https://github.com/ruby/ruby/commit/fc67091fc8dc4c7122499cd0d287cd34ff01bf30
https://github.com/ruby/ruby/commit/5b146eb5a15cce4c7a6ce279bd53e75a61d4a1f5

https://github.com/rubygems/rubygems/commit/e6a538b5c8104900e9a74f6a5fd154da319fb388
https://github.com/rubygems/rubygems/commit/984bb9b81574e778b3d40d039761d84259c1806d
https://github.com/rubygems/rubygems/commit/6ec39cd782d554127030ede12988f1720b08a2bf

https://github.com/rails/rails/commit/e69a7ee42dc09892477808f1243d029ce1abf311
https://github.com/rails/rails/commit/ac721c855203ac7570545c0e85fe086f8e94d94a
https://github.com/rails/rails/commit/951383bd9afa4a71c17e56d1d4eb5866da851483
https://github.com/rails/rails/commit/8a0f235fd3bd3f3c813fa7034c6d741831e55c3e
https://github.com/rails/rails/commit/99b48a5aebc0ff159a8102f2782eaee8ab5a32cd
https://github.com/rails/rails/commit/c33c03e80cbe9f27274b45fe55f93bad3af988fb
https://github.com/rails/rails/commit/f53f69bdc617d63587036cef84eb11ef2dfbc557
https://github.com/rails/rails/commit/7a65b463ab8d366db0cc49b9a49d37c59d4ce574
https://github.com/rails/rails/commit/82ba39202c9185af9060b70a8241cb41101364cf
https://github.com/rails/rails/commit/a2338c583349ebd48f3c9ec18f1df5c7cf21dfdb
...

----------------------------------------
Feature #20922: Should not we omit parentheses in assert calls?
https://bugs.ruby-lang.org/issues/20922#change-110786

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
I often see the style of omitting parentheses in assert calls, but it leads to annoying warnings in the following case:

```
assert_equal -1, val    #=> warning: ambiguous first argument; put parentheses or a space even after `-` operator
assert_match /foo/, str #=> warning: ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator
```

To deal with this warning, it is necessary to add parentheses only to *some* assert calls.

```
assert_equal 1, one
assert_equal 0, zero
assert_equal(-1, minus_one)
```

Obviously, this is not very cool.

I feel that by these warnings, Ruby says "we should not omit parentheses in assert calls". Is this what matz intended?

If it is the intent, I would like to add parentheses on all assert calls in tests of Ruby and default gems.
If it is not the intent, why don't we remove these warnings?

Note that, as far as I recall, I encountered this problem only with `assert_equal` and `assert_match`.
I don't write parentheses in `p`, `puts`, `attr_reader`, `include`, etc., but all of them rarely accept `-1` and `//` literally as the first argument in real code.
As a milder approach, I came up with an idea to stop the warning only when the method name starts with "assert". It is very ad-hoc, though.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:120054] [Ruby master Feature#20922] Should not we omit parentheses in assert calls?
  2024-11-29  6:59 [ruby-core:120050] [Ruby master Feature#20922] Should not we omit parentheses in assert calls? mame (Yusuke Endoh) via ruby-core
  2024-11-29  7:30 ` [ruby-core:120051] " mame (Yusuke Endoh) via ruby-core
@ 2024-11-29 11:47 ` byroot (Jean Boussier) via ruby-core
  2024-12-12 11:17 ` [ruby-core:120212] " mame (Yusuke Endoh) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2024-11-29 11:47 UTC (permalink / raw)
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #20922 has been updated by byroot (Jean Boussier).


I generally agree, and this change would be welcome, but there's still a common case that is an error:

```ruby
assert_equal {}, something
```


----------------------------------------
Feature #20922: Should not we omit parentheses in assert calls?
https://bugs.ruby-lang.org/issues/20922#change-110789

* Author: mame (Yusuke Endoh)
* Status: Open
----------------------------------------
I often see the style of omitting parentheses in assert calls, but it leads to annoying warnings in the following case:

```
assert_equal -1, val    #=> warning: ambiguous first argument; put parentheses or a space even after `-` operator
assert_match /foo/, str #=> warning: ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator
```

To deal with this warning, it is necessary to add parentheses only to *some* assert calls.

```
assert_equal 1, one
assert_equal 0, zero
assert_equal(-1, minus_one)
```

Obviously, this is not very cool.

I feel that by these warnings, Ruby says "we should not omit parentheses in assert calls". Is this what matz intended?

If it is the intent, I would like to add parentheses on all assert calls in tests of Ruby and default gems.
If it is not the intent, why don't we remove these warnings?

Note that, as far as I recall, I encountered this problem only with `assert_equal` and `assert_match`.
I don't write parentheses in `p`, `puts`, `attr_reader`, `include`, etc., but all of them rarely accept `-1` and `//` literally as the first argument in real code.
As a milder approach, I came up with an idea to stop the warning only when the method name starts with "assert". It is very ad-hoc, though.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:120212] [Ruby master Feature#20922] Should not we omit parentheses in assert calls?
  2024-11-29  6:59 [ruby-core:120050] [Ruby master Feature#20922] Should not we omit parentheses in assert calls? mame (Yusuke Endoh) via ruby-core
  2024-11-29  7:30 ` [ruby-core:120051] " mame (Yusuke Endoh) via ruby-core
  2024-11-29 11:47 ` [ruby-core:120054] " byroot (Jean Boussier) via ruby-core
@ 2024-12-12 11:17 ` mame (Yusuke Endoh) via ruby-core
  2 siblings, 0 replies; 4+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-12-12 11:17 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20922 has been updated by mame (Yusuke Endoh).

Status changed from Open to Rejected

Discussed at the dev meeting. 

@matz said he was not going to remove this warning.

Several ideas to prevent a warning were raised.

Parenthesizing only the first argument prevents the warning. This solution works today, and usable for `{}` as well.

```
assert_equal (-1), minus_one
assert_match (/foo/), str
```

Assigning the first argument to a varaible also works.

```
re = /foo/
assert_match re, str
```

A new idea is to prevent a warning when there are *two* spaces, but not accepted.

```
assert_equal  -1, minus_one
```

Finally, writing the method call parentheses only where necessary

```
assert_equal 1, one
assert_equal 0, zero
assert_equal(-1, minus_one)
```

is the most reasonable solution. :sad:

----------------------------------------
Feature #20922: Should not we omit parentheses in assert calls?
https://bugs.ruby-lang.org/issues/20922#change-110975

* Author: mame (Yusuke Endoh)
* Status: Rejected
----------------------------------------
I often see the style of omitting parentheses in assert calls, but it leads to annoying warnings in the following case:

```
assert_equal -1, val    #=> warning: ambiguous first argument; put parentheses or a space even after `-` operator
assert_match /foo/, str #=> warning: ambiguous `/`; wrap regexp in parentheses or add a space after `/` operator
```

To deal with this warning, it is necessary to add parentheses only to *some* assert calls.

```
assert_equal 1, one
assert_equal 0, zero
assert_equal(-1, minus_one)
```

Obviously, this is not very cool.

I feel that by these warnings, Ruby says "we should not omit parentheses in assert calls". Is this what matz intended?

If it is the intent, I would like to add parentheses on all assert calls in tests of Ruby and default gems.
If it is not the intent, why don't we remove these warnings?

Note that, as far as I recall, I encountered this problem only with `assert_equal` and `assert_match`.
I don't write parentheses in `p`, `puts`, `attr_reader`, `include`, etc., but all of them rarely accept `-1` and `//` literally as the first argument in real code.
As a milder approach, I came up with an idea to stop the warning only when the method name starts with "assert". It is very ad-hoc, though.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-12 11:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-29  6:59 [ruby-core:120050] [Ruby master Feature#20922] Should not we omit parentheses in assert calls? mame (Yusuke Endoh) via ruby-core
2024-11-29  7:30 ` [ruby-core:120051] " mame (Yusuke Endoh) via ruby-core
2024-11-29 11:47 ` [ruby-core:120054] " byroot (Jean Boussier) via ruby-core
2024-12-12 11:17 ` [ruby-core:120212] " mame (Yusuke Endoh) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).