null_safety_percentage
提供项目空安全百分比信息的命令行工具。跟踪您在不安全的空安全执行的混合版本程序中的迁移进度。
重要链接
动机
一个Dart程序可以包含一些是null安全和一些不是null安全的库。这些混合版本的程序以不安全的Null Safety模式执行。– Dart: Unsound null safety
对于小型项目,迁移到Null Safety可以在几分钟内完成。
不幸的是,如果您对自动迁移的代码不满意,并且想自己进行迁移,那么大型代码库的迁移可能需要一些时间。
这个命令行工具可以让你跟踪你的Null Safety迁移进度。
安装
全局安装或作为开发依赖安装null_safety_percentage命令行工具。
全局安装
如果您全局安装null_safety_percentage,您只需输入null_safety_percentage lib test即可执行它。
# Install globally
dart pub global activate null_safety_percentage
# or: flutter pub global activate null_safety_percentage
# Verify installation was successful
null_safety_percentage --help
作为开发依赖
您可以使用dart run或flutter run命令从您的依赖项运行Dart脚本。
Flutter项目
- 将
null_safety_percentage添加到您的dev_dependencies中:flutter pub add -d null_safety_percentage。 - 运行脚本
flutter run null_safety_percentage lib test。请参阅下面的“用法”部分中的更多示例。
Dart项目
- 将
null_safety_percentage添加到您的dev_dependencies中:dart pub add -d null_safety_percentage。 - 运行脚本
dart run null_safety_percentage lib test。请参阅下面的“用法”部分中的更多示例。
用法
请记住,如何调用null_safety_percentage取决于您如何安装它以及您是从Flutter项目还是Dart项目中使用它。
下面的用法示例假定您已全局安装该包。
# See usage and other info about the package
null_safety_percentage --help
null_safety_percentage -h
# One folder
null_safety_percentage lib
# Multiple folders
null_safety_percentage lib test
# Custom output format: JSON
null_safety_percentage --output-format=json lib test
null_safety_percentage --output-format json lib test
# Custom output format: ASCII (perfect with UNIX/Shell tools)
null_safety_percentage --output-format ascii lib test
# Get version info
null_safety_percentage --version
该工具支持多种输出格式,因此,如果您想在CI/CD工具中添加一个检查,以确保您的“Null Safety覆盖率百分比”指标没有变差,您可以使用“ascii”格式,然后获取您感兴趣的指标。
注意事项
该工具仍处于早期阶段,其编写方式是为了在我正在进行的项目上正确运行。
目前,该工具决定文件是否被视为已迁移的方式非常粗糙。
我相信一定有更好的方法来获取这些信息,但这种方法对我来说足够有效。
欢迎提出改进建议.
该工具无法处理完全未迁移的库。我不想为其添加安全防护措施,因此请确保“输入”项目至少已部分迁移。
示例
不要忘记项目中的示例文件夹,您可以在其中测试命令行工具。