lavary / fixit
只需一个命令即可快速跟踪您的 Fixme 注释!
Requires
- symfony/config: ^3.1
- symfony/console: ^3.1
- symfony/finder: ^3.1
- symfony/yaml: ^3.0
Requires (Dev)
- phpunit/phpunit: ^4.8 || ^5.0
README
#Fixit
只需一个命令即可快速跟踪您的 "Fixme" 注释!
安装
composer global require lavary/fixit
安装包后,名为 fixit
的命令行工具会被复制到您的 ~/.composer/vendor/bin
目录,如果全局安装。
为了确保命令在任何地方都可以使用,请确保将 ~/.composer/vendor/bin
添加到您的 PATH
环境变量中。否则,您将不得不使用命令的完整路径。
您也可以为特定项目安装它;在这种情况下,它将被复制到项目的
vendor/bin
目录。
要查看可用的参数和选项,您可以运行以下命令
fixit --help
用法
Fixit 跟踪和收集配置文件中或作为命令选项设置的特定关键词标记的指定文件中的所有注释。
注释可以以下形式存在于代码库中。然而,这可以在配置文件中进行配置。
// KEYWORD some description about it
这里是一个基本用法
fixit scan --include /Path/to/your/code
默认情况下,以关键词 fixme
、fix-me
、todo
、to-do
开头的注释将被收集器收集。然而,这可以在配置文件(下面将详细介绍)或命令选项 --keyword
中进行配置。
fixit scan --include /Path/to/your/code --keyword fixme --keyword warning
如您所见,可以同时指定多个关键词。
输出可能如下所示
- File:/Path/to/CodeBase/src/Controller/AdminControllerProvider.php
Line Type Comment
37 fixme some thing wrong here
450 warning This part should be improved
-File:/Path/to/CodeBase/src/Controller/UserControllerProvider.php
Line Type Comment
59 fixme This block should be refactored soon
187 file(s) scanned.
3 issue(s) were found in 2 file(s).
注意:如果您为某个特定问题(fixme、bug、bottleneck 等)选择了一个关键词,请坚持使用它,以确保没有注释未被跟踪。
输出类型
默认情况下,输出以表格格式呈现。但是,您可以通过命令行或配置文件中的 output_type
选项来指定输出。默认支持三种类型:table
、json
和 list
。
vendor/bin/fixit scan include /Path/to/your/codebase --output_type json
哪种输出
[ { "file":"/Path/to/Codebase/src/AdminControllerProvider.php", "items":[ { "line":"37", "type":"warning", "comment":"some thing wrong here" } ] }, { "file":"/Path/to/Codebase/src/UserController.php", "items":[ { "line":"59", "type":"warning", "comment":"another one here" } ] } ]
或者作为一个列表
vendor/bin/fixit scan --include /Path/to/your/codebase --output_type list
- File:/Path/to/Codebase/src/Controller/AdminControllerProvider.php * 37 warning some thing wrong here * 59 warning This part should be improved - File:/Path/to/Codebase/src/FormApply/Controller/UserController.php * 59 warning another one here 187 file(s) scanned. 2 issue(s) were found in 2 file(s).
包含或排除特定目录或文件
可能将收集限制为有限数量的目录或文件(在这些目录中)。
要这样做,您可以使用 --include
、--exclude
、--include_file
和 --exclude_file
命令选项。
fixit scan --include path/to/code --exclude Controller --exclude Model
上述命令将扫描 path/to/code
目录内的所有文件和目录,但排除 Controller
和 Model
目录。
我们还可以排除某个特定文件
fixit scan --include path/to/code --exclude Controller --exclude_file Models/User.php
上述命令将扫描 path/to/code
目录内的所有文件,但排除 Controller
目录和 Model/User.php
文件。
您可以根据需要多次使用这些选项,以指定要扫描的目录和文件。
默认情况下
vendor
目录会被忽略。
所有这些选项也可以在配置文件中设置。
配置
上述所有选项都可以通过一个 YAML
配置文件进行设置,该文件与包一起提供。
配置文件看起来像这样
# Fixit configuration keyword: ['fixme', 'fix-me', 'todo', 'to-do'] pattern: '\/\/\s*@?(%keyword%):?\s+(.+)' titles: ['Line', 'Type', 'Comment'] include: ~ exclude: ['vendor'] include_file: ~ exclude_file: ~ output_type: table
keyword
选项是我们需要在扫描文件时获取的关键词列表。您可以根据团队约定放置任何关键词。
pattern
和 titles
将在本 README
文件的 高级用法
部分中介绍。
下一组选项非常直接,因为我们已经在命令行中使用过它们。选项 include
、exclude
、include_dir
、exclude_dir
都接受一个数组作为值。
# ... include: ['/Path/to/Code/Model', 'Path/to/Code/Controller'] include_file: ['User.php', 'UserController.php'] # ...
选项 output_type
指定了渲染类型,可以是 table
、json
或 list
。
注意 所有这些设置都将被它们对应的命令行选项覆盖。
编辑配置文件
要使用自己的配置文件,您需要复制自己的文件。
要复制,请运行以下命令
fixit config:publish Please input the destination directory
您需要指定保存配置文件的路径。它可以位于系统中的任何位置。最后,您可以前往指定目录,按需编辑设置。
要使用配置文件,只需通过 --configuration
选项将配置文件传递给 fixit scan
命令。
fixit scan --configuration path/to/config.yml
高级使用
您可能还记得,如果当前设置不能满足您的需求,您还可以使用配置文件中的其他选项。例如,如果您想为跟踪您的“待办”注释具有更复杂的注释结构,您可以相应地更改 pattern
和 titles
选项。
titles
指定显示结果时的列标题。
如果您需要帮助
请使用 GitHub issues 提交所有问题和疑问,我将尽力帮助您。
许可证
Fixit 是在 MIT 许可证条款下分发的免费软件。