Appearance
不允许在代码同一行上添加注释。
放在代码行末尾的注释会让代码更难阅读。 在纵向浏览时,它们很容易被忽略,而且会使行更长。 将注释放到单独的行上会让它们更显眼,并减少行长度。
以下是此规则的错误代码示例:
var a = 1; // 行内注释 var b = 2; /* 另一个行内注释 */
以下是此规则的正确代码示例:
// 单独一行的注释 var a = 1; /* 单独一行的块注释 */ var b = 2;
此规则接受一个包含以下属性的配置对象:
type: string
string
用于忽略某些行内注释的正则表达式模式。
匹配此模式的注释将不会被报告。
配置示例:
{ "no-inline-comments": [ "error", { "ignorePattern": "webpackChunkName" } ] }
To enable this rule using the config file or in the CLI, you can use:
{ "rules": { "no-inline-comments": "error" } }
import { defineConfig } from "oxlint"; export default defineConfig({ rules: { "no-inline-comments": "error", }, });
oxlint --deny no-inline-comments
此规则在 v1.34.0 中添加。
eslint/no-inline-comments Pedantic
作用
不允许在代码同一行上添加注释。
为什么这不好?
放在代码行末尾的注释会让代码更难阅读。 在纵向浏览时,它们很容易被忽略,而且会使行更长。 将注释放到单独的行上会让它们更显眼,并减少行长度。
示例
以下是此规则的错误代码示例:
以下是此规则的正确代码示例:
配置
此规则接受一个包含以下属性的配置对象:
ignorePattern
type:
string用于忽略某些行内注释的正则表达式模式。
匹配此模式的注释将不会被报告。
配置示例:
如何使用
To enable this rule using the config file or in the CLI, you can use:
版本
此规则在 v1.34.0 中添加。
参考