hardcodes 是一款用于搜索开发者在程序中硬编码的字符串的工具。它使用模块化分词器,能够处理注释、任意数量的反斜杠以及几乎所有你能扔给它的语法。
是的,它旨在处理任何语法,并且官方支持以下语言:
ada, applescript, c, c#, c++, coldfusion, golang, haskell, html, java, javascript,
jsp, lua, pascal, perl, php, powershell, python, ruby, scala, sql, swift, xml
pip3 install hardcodes
git clone https://github.com/s0md3v/hardcodes && cd hardcodes && python3 setup.py install
hardcodes 既可作为库使用,也可作为命令行程序使用。相关文档如下:
下面的示例程序演示了 hardcodes 库的使用方法
from hardcodes import search
string = "console.log('hello there')"
result = search(string, lang="common", comments="parse")
print(result)
Output: ['hello there']
参数 lang 和 comments 是可选的。它们的用法将在下面的用户文档部分解释。
cli.py 为 hardcodes 库提供了一个类似 grep 的命令行界面。你需要先安装该库才能使用它。
python cli.py /path/to/file.ext
python cli.py -r /path/to/dir
python cli.py -o /path/to/file.ext
指定语言是可选的,仅在已知道源代码的编程语言时使用。
python cli.py -l 'golang' /path/to/file.go
使用 -c 选项,你可以指定:
ignore 完全忽略注释parse 像解析代码一样解析注释string 将注释添加到硬编码字符串列表中python cli.py -o /path/to/file.ext