Flowlint 注释
你可以使用 flowlint
注释在文件中指定更精细的 lint 设置。这些注释来自三个方面:
¥You can use flowlint
comments to specify more granular lint settings within a file.
These comments come in three froms:
在所有形式中,单词之间的空格和星号都会被忽略,从而允许灵活的格式设置。
¥In all forms, whitespace and asterisks between words are ignored, allowing for flexible formatting.
flowlint
基本 flowlint
注释采用逗号分隔的 rule:severity
对列表,并将这些设置应用于源文件的其余部分,直到被覆盖。这样做有三个主要目的:对块应用设置、对文件应用设置以及对行的一部分应用设置。
¥The basic flowlint
comment takes a comma-delimited list of rule:severity
pairs and
applies those settings for the rest of the source file until overridden. This has
three primary purposes: applying settings over a block, applying settings over a file,
and applying settings over part of a line.
代码块上的设置:一对 flowlint
注释可用于对代码块应用特定设置。例如,要禁用类型导入块上的 untyped-type-import lint,如下所示:
¥settings over a block of code:
A pair of flowlint
comments can be used to apply a certain setting over a block of code.
For example, to disable the untyped-type-import lint over a block of type imports would look like this:
import type {
// flowlint untyped-type-import:off
Foo,
Bar,
Baz,
// flowlint untyped-type-import:error
} from './untyped.js';
对文件的设置:flowlint
注释不必有匹配的注释才能形成块。不匹配的注释只是将其设置应用于文件的其余部分。例如,你可以使用它来抑制特定文件中的所有粗略空检查 lint:
¥settings over a file:
A flowlint
comment doesn't have to have a matching comment to form a block.
An unmatched comment simply applies its settings to the rest of the file. You
could use this, for example, to suppress all sketchy-null-check lints in a particular file:
// flowlint sketchy-null:off
...
部分线路的设置:flowlint
应用的设置在注释本身处开始和结束。这意味着你可以做类似的事情
¥settings over part of a line:
The settings applied by flowlint
start and end right at the comment itself. This
means that you can do things like
function foo(a: ?boolean, b: ?boolean) {
if (/* flowlint sketchy-null-bool:off */a/* flowlint sketchy-null-bool:warn */ && b) {
...
} else {
...
}
}
如果你想要比基于行的注释获得更精细的控制。
¥if you want control at an even finer level than you get from the line-based comments.
flowlint-line
flowlint-line
注释的工作方式与 flowlint
注释类似,只不过它仅将其设置应用于当前行,而不是将其应用于文件的其余部分。flowlint-line
注释的主要用途是抑制特定行上的 lint:
¥A flowlint-line
comment works similarly to a flowlint
comment, except it only
applies its settings to the current line instead of applying them for the rest of the file.
The primary use for flowlint-line
comments is to suppress a lint on a particular line:
function foo(x: ?boolean) {
if (x) { // flowlint-line sketchy-null-bool:off
...
} else {
...
}
}
flowlint-next-line
flowlint-next-line
的工作方式与 flowlint-line
相同,只是它将其设置应用于下一行而不是当前行:
¥flowlint-next-line
works the same as flowlint-line
, except it applies its settings to the next line instead of the current line:
function foo(x: ?boolean) {
// flowlint-next-line sketchy-null-bool:off
if (x) {
...
} else {
...
}
}