noConsole
¥Summary
-
规则生效日期:
v1.6.0¥Rule available since:
v1.6.0 -
诊断类别:
lint/suspicious/noConsole¥Diagnostic Category:
lint/suspicious/noConsole -
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
与
no-console相同¥Same as
no-console
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noConsole": "error" } } }}¥Description
禁止使用 console。
¥Disallow the use of console.
在浏览器环境中,使用 console 记录消息被视为最佳实践。此类消息被视为用于调试目的,因此不适合发送给客户端。通常,在推送到生产之前,应删除使用 console 的调用。
¥In a browser environment, it’s considered a best practice to log messages using console.
Such messages are considered to be for debugging purposes and therefore not suitable to ship to the client.
In general, calls using console should be stripped before being pushed to production.
¥Examples
¥Invalid
console.error('hello world')code-block.js:1:1 lint/suspicious/noConsole FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Don’t use console.
> 1 │ console.error(‘hello world’)
│ ^^^^^^^^^^^^^
2 │
ℹ The use of console is often reserved for debugging.
ℹ Unsafe fix: Remove console.
1 │ console.error(‘hello·world’)
│ ----------------------------
¥Options
使用以下选项显式允许使用 console 方法的特定子集。
¥Use the options to explicitly allow a specific subset of console methods.
{ "linter": { "rules": { "suspicious": { "noConsole": { "options": { "allow": [ "assert", "error", "info", "warn" ] } } } } }}console.error("error message"); // Allowedconsole.warn("warning message"); // Allowedconsole.info("info message"); // Allowedconsole.log("log message");console.assert(true, "explanation"); // Allowedcode-block.js:4:1 lint/suspicious/noConsole FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Don’t use console.
2 │ console.warn(“warning message”); // Allowed
3 │ console.info(“info message”); // Allowed
> 4 │ console.log(“log message”);
│ ^^^^^^^^^^^
5 │ console.assert(true, “explanation”); // Allowed
6 │
ℹ The use of console is often reserved for debugging.
ℹ Unsafe fix: Remove console.
2 2 │ console.warn(“warning message”); // Allowed
3 3 │ console.info(“info message”); // Allowed
4 │ - console.log(“log·message”);
5 4 │ console.assert(true, “explanation”); // Allowed
6 5 │
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号