自动创建文件注释,可以在团队开发中起到非常重要的作用,团队成员可以通过注释清晰的知道文件的创建时间作者等信息,方便后期维护和迭代。
我现在用的是 PhpStorm 做开发,理论上该方法适用于 IDEA、WebStorm 等 jetbrains 公司旗下所有的开发工具。
以 .js
为例,打开 File -> Settings... 打开设置窗口,找到 Editor -> File and Code Temlates
在右侧的 File 栏找到需要添加注释的文件类型,在右侧文本框中输入模板,保存后,下次新建该类型的文件时,就可在自动生成注释了。如下图所示:
/**
* Create by ${USER}
* E-mail: [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
* Description: ${NAME}
* Date: ${DATE} ${TIME}
* Update: ${DATE} ${TIME}
*/
或者:
/**
* Create by ${USER}
* E-mail: [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
* Description:${NAME}
* Date: ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}
* Update: ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}
*/
${NAME}
:当前文件 文件名称;
${USER}
:当前系统 登录用户名;
${DATE}
:当前系统 设定日期格式;
${TIME}
:当前系统 设定时间格式;
${YEAR}
:完整年份,如 2020;
${MONTH}
:完整月份,如 02;
${DAY}
:完整日期,如 11;
${HOUR}
:24小时制小时,如 16;
${MINUTE}
:完整分钟,如 32。
未经允许不得转载:w3h5 » Php/WebStorm配置创建文件时自动生成文件注释