From d41b77b62307dcaf333fe790af71d8d458a993b0 Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Wed, 19 Mar 2025 16:28:12 +0100 Subject: [PATCH] DART-213 Modify rules S1161, S7055: update descriptions and messages (#4799) * DART-213 Modify rule S1161: update message details * S7055: Update description * Update rule.adoc --- rules/S1161/dart/rule.adoc | 2 -- rules/S7055/dart/rule.adoc | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/rules/S1161/dart/rule.adoc b/rules/S1161/dart/rule.adoc index 4d8ff3cfc1..b6d155be67 100644 --- a/rules/S1161/dart/rule.adoc +++ b/rules/S1161/dart/rule.adoc @@ -47,8 +47,6 @@ ifdef::env-github,rspecator-view[] The member '' overrides an inherited member but isn't annotated with '@override'. -If the member is a setter, the method name will end with a `=` sign, to distinguish it from the corresponding getter. - === Highlighting The identifier of the method, property or operator. diff --git a/rules/S7055/dart/rule.adoc b/rules/S7055/dart/rule.adoc index 1e7523ff26..b4772d6ea4 100644 --- a/rules/S7055/dart/rule.adoc +++ b/rules/S7055/dart/rule.adoc @@ -1,6 +1,10 @@ == Why is this an issue? -In Dart, you can use wildcard names(names consisting on underscores only: `++_++`, `++__++`, `++___++`, ... ). Usually it should be used to name the variable/parameter that won't be directly used but needs to be declared. For example, as counter in the for-loop: +In Dart, you can use wildcard names, that are names consisting on underscores only: `++_++`, `++__++`, `++___++`, ... + +Usually, wildcard names should be used to name the variable/parameter that won't be directly used but needs to be declared. + +For example, as counter in the for-loop: `for (var _ in [1, 2, 3]) doSomething();` @@ -16,7 +20,18 @@ void sayHello(Person p) { } ---- -Currently, this is possible to read such wildcard variables, for example, `print(_);`. However, such behavior is supposed to change in the next versions of the Dart language, making such variables non-binding and breaking the code, where such variables are used. To avoid problems during upgrades, it's recommended to refactor the code, to not use wildcard variables. +In Dart 3.6 and below, it is possible to read `++_++` wildcard variables, for example, `print(_);`. + +However, such behavior has changed in Dart 3.7, making `++_++` variables non-binding and breaking the code, where those variables are used. + +[source,dart] +---- +void sayHello(String _) { + print('Hello, $_!'); // Compiler error in Dart 3.7 and above: _ is non-binding +} +---- + +To avoid problems during upgrades from Dart 3.6-, it's recommended to refactor the code, to not use wildcard variables. === What is the potential impact? @@ -33,7 +48,7 @@ If the variable/parameter are supposed to be read, then give them a proper name. [source,dart,diff-id=1,diff-type=noncompliant] ---- void sayHello(String __) { - print('Hello, $__!'); + print('Hello, $__!'); // Noncompliant in Dart 3.6 and below } ----