Compare commits

...

2 Commits

Author SHA1 Message Date
Marharyta Nedzelska
be7ee51563 Modify Rule S6582: Add link to the rule prefer_null_aware_method_calls 2024-08-05 15:45:15 +02:00
Marharyta Nedzelska
90c5b23a5e Modify Rule S6582: Update description for Dart 2024-08-05 15:01:27 +02:00

View File

@ -14,22 +14,55 @@ Replace with `?.` `null`-aware operator the logical expression that checks for `
[source,dart,diff-id=1,diff-type=noncompliant] [source,dart,diff-id=1,diff-type=noncompliant]
---- ----
void foo(a) { void foo(Bar? bar) {
if (a != null) { // Noncompliant var x = bar == null ? null : bar.value; // Noncompliant
var x = a.value;
}
} }
---- ----
[source,dart,diff-id=2,diff-type=noncompliant]
----
void foo(Function? function) {
if (function != null) function!(); // Noncompliant
}
----
==== Compliant solution ==== Compliant solution
[source,dart,diff-id=1,diff-type=compliant] [source,dart,diff-id=1,diff-type=compliant]
---- ----
void foo(a) { void foo(Bar? bar) {
var x = a?.value; var x = bar?.value;
}
----
[source,dart,diff-id=2,diff-type=compliant]
----
void foo(Function? function) {
function?.call();
} }
---- ----
== Resources == Resources
* https://dart.dev/tools/linter-rules/prefer_null_aware_operators[Dart Lint rule] * Dart Docs - https://dart.dev/tools/linter-rules/prefer_null_aware_operators[Dart Linter rule - prefer_null_aware_operators]
* Dart Docs - https://dart.dev/tools/linter-rules/prefer_null_aware_method_calls[Dart Linter rule - prefer_null_aware_method_calls]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* "Use the '??' operator rather than '?:' when testing for 'null'."
* Use a null-aware invocation of the 'call' method rather than explicitly testing for 'null'.
=== Highlighting
The whole ternary operator or if-statement
'''
endif::env-github,rspecator-view[]