-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix parameter_assignments documentation for null safety and updated dart syntax #62191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8262,9 +8262,9 @@ LinterLintCode: | |||||
| deprecatedDetails: |- | ||||||
| **DON'T** assign new values to parameters of methods or functions. | ||||||
|
|
||||||
| Assigning new values to parameters is generally a bad practice unless an | ||||||
| operator such as `??=` is used. Otherwise, arbitrarily reassigning parameters | ||||||
| is usually a mistake. | ||||||
| Assigning new values to parameters is generally a bad practice, even when using | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive-by comment: I don't think the text should be changed here. The lint actually does not emit a diagnostic when it encounters var nonConstantDefault = 0;
void f([int? i]) {
i ??= ++nonConstantDefault; // OK.
i = 42; // LINT.
} |
||||||
| operators such as `??=`. Arbitrarily reassigning parameters is usually a | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With that, it makes sense to keep saying 'Otherwise, ...' as well. |
||||||
| mistake and can make code harder to reason about. | ||||||
|
|
||||||
| **BAD:** | ||||||
| ```dart | ||||||
|
|
@@ -8275,14 +8275,14 @@ LinterLintCode: | |||||
|
|
||||||
| **BAD:** | ||||||
| ```dart | ||||||
| void badFunction(int required, {int optional: 42}) { // LINT | ||||||
| void badFunction(int required, {int? optional}) { // LINT | ||||||
| optional ??= 8; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one does not give rise to a lint message, it is an example of the "GOOD" use of void badFunction(int? nonOptional) {
nonOptional ??= 8; // LINT
} |
||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| **BAD:** | ||||||
| ```dart | ||||||
| void badFunctionPositional(int required, [int optional = 42]) { // LINT | ||||||
| void badFunctionPositional(int required, [int? optional]) { // LINT | ||||||
| optional ??= 8; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should again be relabeled as a "GOOD" example, no lint is reported. |
||||||
| } | ||||||
| ``` | ||||||
|
|
@@ -8305,15 +8305,17 @@ LinterLintCode: | |||||
|
|
||||||
| **GOOD:** | ||||||
| ```dart | ||||||
| void actuallyGood(int required, {int optional}) { // OK | ||||||
| optional ??= ...; | ||||||
| void actuallyGood(int required, {int? optional}) { // OK | ||||||
| final value = optional ?? 8; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to show that
Suggested change
An example using a fresh local variable would be fine, too. |
||||||
| print(value); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| **GOOD:** | ||||||
| ```dart | ||||||
| void actuallyGoodPositional(int required, [int optional]) { // OK | ||||||
| optional ??= ...; | ||||||
| void actuallyGoodPositional(int required, [int? optional]) { // OK | ||||||
| final value = optional ?? 8; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The situation is similar here:
Suggested change
|
||||||
| print(value); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.