unnecessary_ this_ alias
Learn about the unnecessary_this_alias linter rule.
Use 'this' directly instead of assigning it to a local variable.
Details
#DON'T assign this to a local variable to perform type promotion.
BAD:
class C {
void m() {
var self = this;
if (self is D) {}
}
}
class D extends C {}
GOOD:
class C {
void m() {
if (this is D) {}
}
}
class D extends C {}
Enable
#
To enable the unnecessary_this_alias rule, add unnecessary_this_alias under
linter > rules in your analysis_options.yaml
file:
linter:
rules:
- unnecessary_this_alias
If you're instead using the YAML map syntax to configure linter rules,
add unnecessary_this_alias: true under linter > rules:
linter:
rules:
unnecessary_this_alias: true
Unless stated otherwise, the documentation on this site reflects Dart 3.12.2. Report an issue.