关于清理「死代码」,我有一些好方法推荐给你

【CSDN 编者按】作为开发者的你平时工作时是怎么判断并清理死代码的?也许你猜到了这篇文章要讲什么,是的,我们是有一些清理死代码的好方法推荐给你……


Hank 与其他现有工具的区别

Hank 的功能

如何使用 rebar3_hank
{plugins, [rebar3_hank]}.rebar3 hank跳过规则
% ignoring all the rules for this module-hank ignore% or ignoring specific rules-hank [single_use_hrl_attributes]
{hank, [{ignore, [{"test/*.erl", unused_ignored_function_params}]}]}.
规则
unused_ignored_function_params
-module(my_module).-export([external_fun/1]).external_fun(X) ->multi_fun(X,rand:uniform(), undefined).%% A multi-clause function with unused 3rd parammulti_fun(undefined, _, _) ->ok;multi_fun(Arg1, Arg2, _Arg3) when is_binary(Arg1) ->Arg2;multi_fun(Arg1, _, _) ->Arg1.
$ rebar3 hank===> Looking for code to kill with fire...===> The following pieces of code are dead and should beremoved:src/my_module.erl:9: Param #3 is not used at 'multi_fun/3'
single_use_hrls
-define(APP_HEADER, "this is a header from an app that willbe used in just one module").-define(SOME_MACRO(A), A).-module(app_include_lib).-include("header.hrl").-export([my_function/0]).my_function() ->% those are only usedhere!?SOME_MACRO(?APP_HEADER).
$ rebar3 hank===> Looking for code to kill with fire...===> The following pieces of code are dead and should beremoved:header.hrl:0: This header file is only included at:src/app_include_lib.erl
single_use_hrl_attrs
-module(app_include_lib_2).-include("header.hrl").
$ rebar3 hank===> Looking for code to kill with fire...===> The following pieces of code are dead and should beremoved:include/header.hrl:2: ?SOME_MACRO/1 is used only at src/app_include_lib.erl
unused_hrls
$ rebar3 hank===> Looking for code to kill with fire...===> The following pieces of code are dead and should beremoved:include/header_2.hrl:0: This file is unused
unused_macros
unused_record_fields
可扩展性

测试 Hank 的威力
{hank, [{ignore,["**/test/**"]}, %% Just "production" code, no tests{rules, [unused_ignored_function_params,unused_hrls,unused_macros,unused_record_fields]}]}.
记录中未使用的字段
未使用的宏
未使用的参数

程序员如何避免陷入“内卷”、选择什么技术最有前景,中国开发者现状与技术趋势究竟是什么样?快来参与「2020 中国开发者大调查」,更有丰富奖品送不停!

☞我们差点就用不上 Java 了!
关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/
关注网络尖刀微信公众号随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 中法元首相会都江堰 7904306
- 2 中方不接受日方所谓交涉 已当场驳回 7808674
- 3 大闸蟹为何会在欧美泛滥成灾 7713999
- 4 国际机构看中国经济 关键词亮了 7617068
- 5 家长称婴儿被褥印不雅英文单词 7523163
- 6 日方军机滋扰擅闯或被视为训练靶标 7426224
- 7 12306出新功能了 7331232
- 8 国乒8比1击败日本队 11战全胜夺冠 7238086
- 9 罪犯被判死缓破口大骂被害人一家 7142439
- 10 千吨级“巨无霸”就位 7047853









CSDN
