hershel-theodore-layton / portable-hack-ast-linters-server
PhaLinters 的非 Hack 发行版,允许 HTL 包在无需循环依赖的情况下使用 portable-hack-ast-linters。
Requires
- hhvm: ^4.128
README
PhaLinters 的非 Hack 发行版,允许 HTL 包在无需循环依赖的情况下使用 portable-hack-ast-linters。
使用方法
- 可选安装 VSCode 扩展1 并在
.vscode/settings.json
中配置。https://:10641?format=json&action=lint-input
是一个良好的默认值。
- 使用以下 CLI 指令启动服务器。
- 请确保在 Docker 中将端口暴露给主机网络。
- 使用
curl https://:10641
对整个项目进行代码审查。- 支持以下查询参数
format=text/vscode-json
text
(默认) 输出人类可读的文本。vscode-json
输出 json,用于与扩展一起使用。
directories=src,tests
- 一个以项目根目录为相对路径的目录名称的逗号分隔列表。
- 仅当
action
是lint-all
时有效
action=lint-all/lint-input
lint-all
(默认) 扫描所有directories
中的代码审查错误lint-input
对请求体中发送的 Hack 源文本进行代码审查。
- 支持以下查询参数
- 通过在安装了扩展的 VSCode 中打开文件进行交互式代码审查。
CLI
此 PhaLinters 发行版可以使用 vendor/bin/pha-linters-server.sh
脚本来启动。在下面的示例中,$SERVER_SH
应扩展到上面的脚本路径。
# Print help text and exit $SERVER_SH -h # Interactive setup, scan for the bundle and prompts you to trust it. # Hosts the http server on port 10641, or the port specified with `-p`. $SERVER_SH # AFK setup which builds and runs the first portable-hack-ast-server-bundle.resource # Skips the trust prompt, should only be used if you trust every file in the directory. $SERVER_SH -t # AFK setup, point $SERVER_SH to a bundle, skips the prompt. # Recommended setup for CI pipelines $SERVER_SH -b "vendor/hershel-theodore-layton/portable-hack-ast-server/bin/portable-hack-ast-server-bundle.resource"
在交互式运行时,您可能会看到以下提示
Found the following resource file.
./path/to/portable-hack-ast-linters-server-bundled.resource
If you trust the resource above, type 'I trust this resource' to build and run it.
当您键入 I trust this resource
时,您了解编译和运行此资源的风险。
依赖性黑客攻击
此软件包在构建时依赖于 portable-hack-ast(-linters|-extras)
,但捆绑输出不依赖于它。此捆绑过程允许 portable-hack-ast
和 portable-hack-ast-extras
在无需循环依赖的情况下使用此软件包。这是通过发布一个空的 composer.json
文件来实现的。
在开发此捆绑包时,您必须选择具有依赖性的 composer 文件。将 COMPOSER
环境变量设置为 composer.dev.json
。
COMPOSER=composer.dev.json composer update
这将安装依赖项,而未设置环境变量的 composer update
将不会安装任何内容。
开发
由于捆绑包不能依赖于任何未捆绑的代码,例如 hhvm-autoload
,因此开发此软件包需要 ini 设置hhvm.autoload.enabled=true
。下游消费者不需要原生自动加载,因为捆绑包将所有依赖项包含在一个文件中。
当您在实时测试(不是捆绑包本身)时,可以使用以下命令启动服务器
hhvm -m server -p 8080 -vServer.AllowRunAsRoot=1 -dhhvm.server.global_document=src/main.hack
如果您想测试捆绑包,请使用以下命令
./build.sh && bin/pha-linters-server.sh -p 8080 \
-b bin/portable-hack-ast-linters-server-bundled.resource
这将重建、重新编译并启动代码审查服务器。