Compare commits
2 Commits
master
...
margo/S658
Author | SHA1 | Date | |
---|---|---|---|
![]() |
be7ee51563 | ||
![]() |
90c5b23a5e |
@ -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[]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user