useLiteralKeys
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/complexity/useLiteralKeys¥Diagnostic Category:
lint/complexity/useLiteralKeys -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
dot-notation相同¥Same as
dot-notation -
¥Same as
no-useless-computed-key -
与
@typescript-eslint/dot-notation相同¥Same as
@typescript-eslint/dot-notation
-
¥How to configure
{ "linter": { "rules": { "complexity": { "useLiteralKeys": "error" } } }}¥Description
强制使用文字访问属性而不是计算属性访问。
¥Enforce the usage of a literal access to properties over computed property access.
¥Examples
¥Invalid
a.b["c"];code-block.js:1:5 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The computed expression can be simplified without the use of a string literal.
> 1 │ a.b[“c”];
│ ^^^
2 │
ℹ Unsafe fix: Use a literal key instead.
1 │ - a.b[“c”];
1 │ + a.b.c;
2 2 │
a.c[`d`]code-block.js:1:5 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The computed expression can be simplified without the use of a string literal.
> 1 │ a.c[`d`]
│ ^^^
2 │
ℹ Unsafe fix: Use a literal key instead.
1 │ - a.c[`d`]
1 │ + a.c.d
2 2 │
a.c[`d`] = "something"code-block.js:1:5 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The computed expression can be simplified without the use of a string literal.
> 1 │ a.c[`d`] = “something”
│ ^^^
2 │
ℹ Unsafe fix: Use a literal key instead.
1 │ - a.c[`d`]·=·“something”
1 │ + a.c.d·=·“something”
2 2 │
a = { ['b']: d}code-block.js:2:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The computed expression can be simplified to a string literal.
1 │ a = {
> 2 │ [‘b’]: d
│ ^^^
3 │ }
4 │
ℹ Unsafe fix: Use a literal key instead.
1 1 │ a = {
2 │ - → [‘b’]:·d
2 │ + → “b”:·d
3 3 │ }
4 4 │
¥Valid
a["c" + "d"];a[d.c];¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号