Skip to main content

.flowconfig [ignore]

.flowconfig 文件中的 [ignore] 部分告诉 Flow 在对代码进行类型检查时忽略与指定正则表达式匹配的文件。默认情况下,不会忽略任何内容。

¥The [ignore] section in a .flowconfig file tells Flow to ignore files matching the specified regular expressions when type checking your code. By default, nothing is ignored.

要记住的事情:

¥Things to keep in mind:

  1. 这些是 OCaml 正则表达式

    ¥These are OCaml regular expressions.

  2. 这些正则表达式与绝对路径匹配。他们可能应该从 .* 开始

    ¥These regular expressions match against absolute paths. They probably should start with .*

  3. 忽略在包含之后进行处理。如果你同时包含并忽略一个文件,该文件将被忽略。

    ¥Ignores are processed AFTER includes. If you both include and ignore a file it will be ignored.

[ignore] 部分的示例可能如下所示:

¥An example [ignore] section might look like:

[ignore]
.*/__tests__/.*
.*/src/\(foo\|bar\)/.*
.*\.ignore\.js

[ignore] 部分将忽略:

¥This [ignore] section will ignore:

  1. 名为 __tests__ 的目录下的任何文件或目录

    ¥Any file or directory under a directory named __tests__

  2. .*/src/foo.*/src/bar 下的任何文件或目录

    ¥Any file or directory under .*/src/foo or under .*/src/bar

  3. 任何以扩展名 .ignore.js 结尾的文件

    ¥Any file that ends with the extension .ignore.js

你可以在正则表达式中使用 <PROJECT_ROOT> 占位符。在运行时,Flow 会将占位符视为项目根目录的绝对路径。这对于编写相对而不是绝对的正则表达式很有用。

¥You may use the <PROJECT_ROOT> placeholder in your regular expressions. At runtime, Flow will treat the placeholder as if it were the absolute path to the project's root directory. This is useful for writing regular expressions that are relative rather than absolute.

例如,你可以写:

¥For example, you can write:

[ignore]
<PROJECT_ROOT>/__tests__/.*

这将忽略项目根目录中名为 __tests__/ 的目录下的任何文件或目录。但是,与前面示例的 .*/__tests__/.* 不同,它不会忽略名为 __tests__/ 的其他目录(例如 src/__tests__/)下的文件或目录。

¥Which would ignore any file or directory under the directory named __tests__/ within the project root. However, unlike the previous example's .*/__tests__/.*, it would NOT ignore files or directories under other directories named __tests__/, like src/__tests__/.

排除

¥Exclusions

有时你可能想忽略目录中除少数文件之外的所有文件。否定该模式的可选前缀 "!" 可能会有所帮助。这样,先前模式排除的任何匹配文件都将再次包含在内。

¥Sometimes you may want to ignore all files inside a directory with the exception of a few. An optional prefix "!" which negates the pattern may help. With this, any matching file excluded by a previous pattern will become included again.

[ignore]
<PROJECT_ROOT>/node_modules/.*
!<PROJECT_ROOT>/node_modules/not-ignored-package-A/.*
!<PROJECT_ROOT>/node_modules/not-ignored-package-B/.*