A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rubocop/rubocop/commit/190a64de3358db1c9e9c86eae32665916c37535c below:

Cut 1.76 · rubocop/rubocop@190a64d · GitHub

@@ -2618,7 +2618,7 @@ end

2618 2618

| Yes

2619 2619

| Command-line only

2620 2620

| 0.20

2621 -

| 1.61

2621 +

| 1.76

2622 2622

|===

2623 2623 2624 2624

Checks for empty interpolation.

@@ -3189,9 +3189,11 @@ Prefer `equal?` over `==` when comparing `object_id`.

3189 3189

----

3190 3190

# bad

3191 3191

foo.object_id == bar.object_id

3192 +

foo.object_id != baz.object_id

3192 3193 3193 3194

# good

3194 3195

foo.equal?(bar)

3196 +

!foo.equal?(baz)

3195 3197

----

3196 3198 3197 3199

[#references-lintidentitycomparison]

@@ -6484,18 +6486,23 @@ end

6484 6486

|===

6485 6487

| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

6486 6488 6487 -

| Enabled

6489 +

| Disabled

6488 6490

| Yes

6489 6491

| No

6490 6492

| 0.9

6491 -

| -

6493 +

| 1.76

6492 6494

|===

6493 6495 6494 6496

Checks for the use of local variable names from an outer scope

6495 6497

in block arguments or block-local variables. This mirrors the warning

6496 6498

given by `ruby -cw` prior to Ruby 2.6:

6497 6499

"shadowing outer local variable - foo".

6498 6500 6501 +

The cop is now disabled by default to match the upstream Ruby behavior.

6502 +

It's useful, however, if you'd like to avoid shadowing variables from outer

6503 +

scopes, which some people consider an anti-pattern that makes it harder

6504 +

to keep track of what's going on in a program.

6505 + 6499 6506

NOTE: Shadowing of variables in block passed to `Ractor.new` is allowed

6500 6507

because `Ractor` should not access outer variables.

6501 6508

eg. following style is encouraged:

@@ -8221,6 +8228,83 @@ class Foo

8221 8228

end

8222 8229

----

8223 8230 8231 +

[#lintuselessdefaultvalueargument]

8232 +

== Lint/UselessDefaultValueArgument

8233 + 8234 +

|===

8235 +

| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

8236 + 8237 +

| Pending

8238 +

| No

8239 +

| Always (Unsafe)

8240 +

| 1.76

8241 +

| -

8242 +

|===

8243 + 8244 +

Checks for usage of method `fetch` or `Array.new` with default value argument

8245 +

and block. In such cases, block will always be used as default value.

8246 + 8247 +

This cop emulates Ruby warning "block supersedes default value argument" which

8248 +

applies to `Array.new`, `Array#fetch`, `Hash#fetch`, `ENV.fetch` and

8249 +

`Thread#fetch`.

8250 + 8251 +

[#safety-lintuselessdefaultvalueargument]

8252 +

=== Safety

8253 + 8254 +

This cop is unsafe because the receiver could have nonstandard implementation

8255 +

of `fetch`, or be a class other than the one listed above.

8256 + 8257 +

It is also unsafe because default value argument could have side effects:

8258 + 8259 +

[source,ruby]

8260 +

----

8261 +

def x(a) = puts "side effect"

8262 +

Array.new(5, x(1)) { 2 }

8263 +

----

8264 + 8265 +

so removing it would change behavior.

8266 + 8267 +

[#examples-lintuselessdefaultvalueargument]

8268 +

=== Examples

8269 + 8270 +

[source,ruby]

8271 +

----

8272 +

# bad

8273 +

x.fetch(key, default_value) { block_value }

8274 +

Array.new(size, default_value) { block_value }

8275 + 8276 +

# good

8277 +

x.fetch(key) { block_value }

8278 +

Array.new(size) { block_value }

8279 + 8280 +

# also good - in case default value argument is desired instead

8281 +

x.fetch(key, default_value)

8282 +

Array.new(size, default_value)

8283 + 8284 +

# good - keyword arguments aren't registered as offenses

8285 +

x.fetch(key, keyword: :arg) { block_value }

8286 +

----

8287 + 8288 +

[#allowedreceivers_-__rails_cache__-lintuselessdefaultvalueargument]

8289 +

==== AllowedReceivers: ['Rails.cache']

8290 + 8291 +

[source,ruby]

8292 +

----

8293 +

# good

8294 +

Rails.cache.fetch(name, options) { block }

8295 +

----

8296 + 8297 +

[#configurable-attributes-lintuselessdefaultvalueargument]

8298 +

=== Configurable attributes

8299 + 8300 +

|===

8301 +

| Name | Default value | Configurable values

8302 + 8303 +

| AllowedReceivers

8304 +

| `[]`

8305 +

| Array

8306 +

|===

8307 + 8224 8308

[#lintuselessdefined]

8225 8309

== Lint/UselessDefined

8226 8310

@@ -8411,6 +8495,83 @@ x **= 1

8411 8495

x = x

8412 8496

----

8413 8497 8498 +

[#lintuselessor]

8499 +

== Lint/UselessOr

8500 + 8501 +

|===

8502 +

| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed

8503 + 8504 +

| Pending

8505 +

| Yes

8506 +

| No

8507 +

| 1.76

8508 +

| -

8509 +

|===

8510 + 8511 +

Checks for useless OR (`||` and `or`) expressions.

8512 + 8513 +

Some methods always return a truthy value, even when called

8514 +

on `nil` (e.g. `nil.to_i` evaluates to `0`). Therefore, OR expressions

8515 +

appended after these methods will never evaluate.

8516 + 8517 +

[#examples-lintuselessor]

8518 +

=== Examples

8519 + 8520 +

[source,ruby]

8521 +

----

8522 +

# bad

8523 +

x.to_a || fallback

8524 +

x.to_c || fallback

8525 +

x.to_d || fallback

8526 +

x.to_i || fallback

8527 +

x.to_f || fallback

8528 +

x.to_h || fallback

8529 +

x.to_r || fallback

8530 +

x.to_s || fallback

8531 +

x.to_sym || fallback

8532 +

x.intern || fallback

8533 +

x.inspect || fallback

8534 +

x.hash || fallback

8535 +

x.object_id || fallback

8536 +

x.__id__ || fallback

8537 + 8538 +

x.to_s or fallback

8539 + 8540 +

# good - if fallback is same as return value of method called on nil

8541 +

x.to_a # nil.to_a returns []

8542 +

x.to_c # nil.to_c returns (0+0i)

8543 +

x.to_d # nil.to_d returns 0.0

8544 +

x.to_i # nil.to_i returns 0

8545 +

x.to_f # nil.to_f returns 0.0

8546 +

x.to_h # nil.to_h returns {}

8547 +

x.to_r # nil.to_r returns (0/1)

8548 +

x.to_s # nil.to_s returns ''

8549 +

x.to_sym # nil.to_sym raises an error

8550 +

x.intern # nil.intern raises an error

8551 +

x.inspect # nil.inspect returns "nil"

8552 +

x.hash # nil.hash returns an Integer

8553 +

x.object_id # nil.object_id returns an Integer

8554 +

x.__id__ # nil.object_id returns an Integer

8555 + 8556 +

# good - if the intention is not to call the method on nil

8557 +

x&.to_a || fallback

8558 +

x&.to_c || fallback

8559 +

x&.to_d || fallback

8560 +

x&.to_i || fallback

8561 +

x&.to_f || fallback

8562 +

x&.to_h || fallback

8563 +

x&.to_r || fallback

8564 +

x&.to_s || fallback

8565 +

x&.to_sym || fallback

8566 +

x&.intern || fallback

8567 +

x&.inspect || fallback

8568 +

x&.hash || fallback

8569 +

x&.object_id || fallback

8570 +

x&.__id__ || fallback

8571 + 8572 +

x&.to_s or fallback

8573 +

----

8574 + 8414 8575

[#lintuselessrescue]

8415 8576

== Lint/UselessRescue

8416 8577

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4