hershel-theodore-layton/pragma
Composer 安装命令:
composer require hershel-theodore-layton/pragma
包简介
A structured way of embedding source analyzer metadata in Hack
README 文档
README
A structured way of embedding source analyzer metadata in Hack.
How to use
// You must use use statements in exactly this form. // `use namespace` or use statements with an `as` are not allowed. use type HTL\Pragma\Pragmas; use function HTL\Pragma\pragma; // Apply an effect to an entire file. <<file: Pragmas(vec['SourceAnalyzer', 'strict_mode=1'])>> // Apply an effect to a class. <<Pragmas(vec['PerfAnalyzer', 'hot_code=0'], vec['Ownership', 'maintainer=You'])>> final class Example implements Printable { public function print(): string { // Apply an effect to the next line. pragma('CodingStandards', 'refused_bequest=ignore'); throw new Exception(); } }
For details on the strings passed to pragma(...) and Pragmas(vec[...]),
read the documentation of the source analyzer.
For implementers
This package contains one class and one function:
- The
pragmafunction, also known as thepragmadirective. - The
Pragmasclass, also known as thePragmasattribute.
They are general replacements for structured comments.
// @lint-ignore[unused-pure-expression] 1 + 1;
@lint-ignore isn't a normal comment from the perspective of some tool.
It suppresses a lint error from being raised for an unused pure expression.
I subscribe wholehartedly to the following quote from the CppCoreGuidelines:
Compilers don’t read comments ... and neither do many programmers (consistently).
If over half of the comments in a project are to silence some tool, be it the Hack typechecker or a linter, programmers will be even more inclined to skip reading the comments. It will instill fear for removing useless comments, since some tool might rely on them.
The idea behind the pragma(...) directive is to eliminate these comments.
The following code block expersses the same intent.
pragma('LinterFramework', 'ignore:unused-pure-expression'); 1 + 1;
Q: Why would this string-based system be better than actual attributes?
- A: If your source code analyzer is a dev-dependency, you'd need to either:
- Publish the attributes in a different package, to make production code typecheck without the source analyzer in the vendor/ directory.
- Deploy the source analyzer code to production.
- The first user of this standard is PhaLinters
This is a dev-dependency with a single directive at the time of writing.
The
pragma(...)directive is preferred over thePragmasannotation. By shippingpragmaas standalone, PhaLinters can be a proper dev-dependency.
If you wish to accept pragma(...) directives and <<Pragmas(vec[...])>>
attributes in your own source analyzers, read pragma.hack
for the details for this informal standard.
hershel-theodore-layton/pragma 适用场景与选型建议
hershel-theodore-layton/pragma 是一款 基于 Hack 开发的 Composer 扩展包,目前已累计 14.31k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hershel-theodore-layton/pragma 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hershel-theodore-layton/pragma 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 14.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-14