multiline-comment-style
在--fix命令行上的选项可以自动修复一些被这条规则反映的问题。
许多风格指南需要特定的风格来进行多行评论。例如,一些风格指南更喜欢使用单个块评论来进行多行评论,而其他风格指南则更喜欢连续的行评论。
规则细节
这条规则旨在强化多行评论的特定风格。
选项
此规则有一个字符串选项,它可以具有下列值之一:
"starred-block"(默认):不允许连续的行注释支持块注释。此外,要求块注释*在每行之前有一个对齐的字符。
"bare-block":不允许连续的行注释支持块注释,并且不允许块注释"*"在每行之前具有字符。
"separate-lines":不允许阻止评论以支持连续的评论
规则总是忽略指令注释,如/* eslint-disable */。另外,除非模式是"starred-block",规则忽略JSDoc评论。
此规则的默认代码错误代码示例"starred-block":
/* eslint multiline-comment-style: ["error", "starred-block"] */
// this line
// calls foo()
foo();
/* this line
calls foo() */
foo();
/* this comment
* is missing a newline after /*
*/
/*
* this comment
* is missing a newline at the end */
/*
* the star in this line should have a space before it
*/
/*
* the star on the following line should have a space before it
*/具有默认选项的此规则的正确代码示例"starred-block":
/* eslint multiline-comment-style: ["error", "starred-block"] */
/*
* this line
* calls foo()
*/
foo();
// single-line comment此规则的错误代码示例包含以下"bare-block"选项:
/* eslint multiline-comment-style: ["error", "bare-block"] */
// this line
// calls foo()
foo();
/*
* this line
* calls foo()
*/
foo();此规则的正确代码示例包含以下"bare-block"选项:
/* eslint multiline-comment-style: ["error", "bare-block"] */
/* this line
calls foo() */
foo();此规则的错误代码示例包含以下"separate-lines"选项:
/* eslint multiline-comment-style: ["error", "separate-lines"] */
/* This line
calls foo() */
foo();
/*
* This line
* calls foo()
*/
foo();此规则的正确代码示例包含以下"separate-lines"选项:
/* eslint multiline-comment-style: ["error", "separate-lines"] */
// This line
// calls foo()
foo();何时不使用它
如果您不想为多行注释强制执行特定样式,则可以禁用该规则。
版本
该规则在ESLint 4.10.0中引入。
资源
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

