🌐 Ignore comments provide an escape hatch for exceptional cases where a rule is correct in general but needs to be suppressed in a small, well scoped section of code. Inline comments override configuration files.
Oxlint 支持行注释(//)和块注释(/* */)。注释必须以以下关键字之一开头。
🌐 Oxlint supports line comments (//) and block comments (/* */). Comments must start with one of the keywords below.
🌐 Disable one or more rules until the end of the file, or until they are re-enabled.
js
// Disable all Oxlint rules for the rest of the file/* oxlint-disable */// Disable a single rule in this file/* oxlint-disable no-console */// Disable multiple rules in this file/* oxlint-disable no-console, typescript/no-floating-promises */
🌐 Disable one or more rules on the line following the comment, then re-enables them for subsequent lines.
js
// oxlint-disable-next-line no-consoleconsole.log("Hello, world!"); // allowed because of the previous commentconsole.log(x++); // not allowed because the previous comment only applied to the previous line// oxlint-disable-next-line no-console, no-plusplusconsole.log("Hello, world!"); // allowed
🌐 For compatibility with existing ESLint codebases, the same keywords are supported with oxlint replaced by eslint, such as /* eslint-disable */ and // eslint-disable-next-line.
🌐 Reporting unused ignore comments is disabled by default. When enabled, Oxlint reports comments such as // oxlint-disable-line when no diagnostics would have been reported on that line.
行内忽略注释
🌐 Inline ignore comments
忽略注释为特殊情况提供了一个退出通道,即规则在一般情况下是正确的,但需要在代码的小范围内被抑制。内联注释会覆盖配置文件。
🌐 Ignore comments provide an escape hatch for exceptional cases where a rule is correct in general but needs to be suppressed in a small, well scoped section of code. Inline comments override configuration files.
Oxlint 支持行注释(
//)和块注释(/* */)。注释必须以以下关键字之一开头。🌐 Oxlint supports line comments (
//) and block comments (/* */). Comments must start with one of the keywords below.oxlint-disable
禁用一条或多条规则,直到文件末尾,或者直到它们被重新启用。
🌐 Disable one or more rules until the end of the file, or until they are re-enabled.
oxlint-enable
启用一个或多个规则,直到文件末尾,或直到它们再次被禁用。
🌐 Enable one or more rules until the end of the file, or until they are disabled again.
oxlint-disable-line
在当前行禁用一个或多个规则。
🌐 Disable one or more rules on the current line.
oxlint-disable-next-line
在注释后的行禁用一个或多个规则,然后重新启用它们以用于后续行。
🌐 Disable one or more rules on the line following the comment, then re-enables them for subsequent lines.
ESLint 兼容性
🌐 ESLint compatibility
为了与现有的 ESLint 代码库兼容,支持使用相同的关键字,只需将
oxlint替换为eslint,例如/* eslint-disable */和// eslint-disable-next-line。🌐 For compatibility with existing ESLint codebases, the same keywords are supported with
oxlintreplaced byeslint, such as/* eslint-disable */and// eslint-disable-next-line.推荐使用
oxlint-*表单。在迁移期间,对于 Oxlint 还不支持的规则,eslint-*表单很有用。🌐 The
oxlint-*form is recommended. Theeslint-*form is useful during migration for rules that Oxlint does not support yet.规则选项无法在内联中更改
🌐 Rule options cannot be changed inline
忽略注释可以启用或禁用规则,但无法更改规则选项。规则选项应放在配置文件中。
🌐 Ignore comments can enable or disable rules, but they cannot change rule options. Rule options belong in configuration files.
报告未使用的忽略注释
🌐 Report unused ignore comments
默认情况下,报告未使用的忽略注释是禁用的。启用后,当某行没有任何诊断需要报告时,Oxlint 会报告类似
// oxlint-disable-line的注释。🌐 Reporting unused ignore comments is disabled by default. When enabled, Oxlint reports comments such as
// oxlint-disable-linewhen no diagnostics would have been reported on that line.启用报告:
🌐 Enable reporting:
指定严重程度:
🌐 Specify the severity:
一次只能使用其中一个选项。
🌐 Only one of these options can be used at a time.