noUselessThisAlias
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/complexity/noUselessThisAlias¥Diagnostic Category:
lint/complexity/noUselessThisAlias -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
灵感来自
@typescript-eslint/no-this-alias¥Inspired from
@typescript-eslint/no-this-alias
-
¥How to configure
{ "linter": { "rules": { "complexity": { "noUselessThisAlias": "error" } } }}¥Description
禁止无用的 this 别名。
¥Disallow useless this aliasing.
箭头函数从其封闭范围继承 this;这使得 this 别名在这种情况下变得无用。
¥Arrow functions inherits this from their enclosing scope;
this makes this aliasing useless in this situation.
¥Examples
¥Invalid
class A { method() { const self = this; return () => { return self; } }}code-block.js:3:15 lint/complexity/noUselessThisAlias FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This aliasing of this is unnecessary.
1 │ class A {
2 │ method() {
> 3 │ const self = this;
│ ^^^^^^^^^^^
4 │ return () => {
5 │ return self;
ℹ Arrow functions inherits `this` from their enclosing scope.
ℹ Safe fix: Use this instead of an alias.
1 1 │ class A {
2 2 │ method() {
3 │ - ········const·self·=·this;
4 3 │ return () => {
5 │ - ············return·self;
4 │ + ············return·this;
6 5 │ }
7 6 │ }
¥Valid
class A { method() { const self = this; return function() { this.g(); return self; } }}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号