noThenProperty
¥Summary
-
规则生效日期:
v1.5.0¥Rule available since:
v1.5.0 -
诊断类别:
lint/suspicious/noThenProperty¥Diagnostic Category:
lint/suspicious/noThenProperty -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
unicorn/no-thenable相同¥Same as
unicorn/no-thenable
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noThenProperty": "error" } } }}¥Description
禁止 then 属性。
¥Disallow then property.
当将具有 then 方法的对象(thenable 对象)与 await 表达式或动态导入组合时,需要小心谨慎。这些语法将对象的 then 方法解释为用于解决或拒绝承诺,这可能会导致意外行为或错误。
¥When combining objects with a then method (thenable objects) with await expressions or dynamic imports, caution is necessary.
These syntaxes interpret the object’s then method as intended for the resolution or rejection of a promise, which can lead to unexpected behavior or errors.
¥Examples
¥Invalid
export {then};code-block.js:1:9 lint/suspicious/noThenProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not export then.
> 1 │ export {then};
│ ^^^^
2 │
const foo = { then() {}};code-block.js:2:5 lint/suspicious/noThenProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not add then to an object.
1 │ const foo = {
> 2 │ then() {}
│ ^^^^
3 │ };
4 │
const foo = { get then() {}};code-block.js:2:9 lint/suspicious/noThenProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not add then to an object.
1 │ const foo = {
> 2 │ get then() {}
│ ^^^^
3 │ };
4 │
const foo = { get then() {}};code-block.js:2:8 lint/suspicious/noThenProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not add then to an object.
1 │ const foo = {
> 2 │ get then() {}
│ ^^^^
3 │ };
4 │
foo.then = function () {}code-block.js:1:1 lint/suspicious/noThenProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not add then to an object.
> 1 │ foo.then = function () {}
│ ^^^^^^^^
2 │
class Foo { then() {}}code-block.js:2:5 lint/suspicious/noThenProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not add then to a class.
1 │ class Foo {
> 2 │ then() {}
│ ^^^^
3 │ }
4 │
class Foo { static then() {}}code-block.js:2:12 lint/suspicious/noThenProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not add then to a class.
1 │ class Foo {
> 2 │ static then() {}
│ ^^^^
3 │ }
4 │
¥Valid
export {then as success};const foo = { success() {}};class Foo { success() {}}const foo = bar.then;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号