当前位置: 首页 > news >正文

【代码格式化】linux代码格式化(Astyle)+wind格式转unix格式(Doc2Unix)----git提交代码前的处理...

 

乐鑫的git代码提交前的建议:值得学习

格式化代码

您在提交代码之前需要对代码进行格式化,ESP-MDF 使用的格式化式工具为:astyle 和 dos2unix。您需要先安装他们,在 Linux 安装命令如下:

sudo apt-get install astyle
sudo apt-get install doc2unix

运行如下代码格式化命令:

tools/format.sh new_file.c

API 文档生成

在编写代码注释时,请遵循 Doxygen 格式。您可以通过 Doxygen 按如下步骤自动生成 API 文档:

sudo apt-get install doxygen
export MDF_PATH=~/esp/esp-mdf
cd ~/esp/esp-mdf/docs
pip install -r requirements.txt
cd ~/esp/esp-mdf/docs/en
make html

dos2unix的使用

由于在DOS(windows系统)下,文本文件的换行符为CRLF,而在Linux下换行符为LF,使用git进行代码管理时,git会自动进行CRLF和LF之间的转换,这个我们不用操心。而有时候,我们需要将windows下的文件上传到linux上,例如shell脚本,执行的时候有时会出现奇怪的问题,这时候,就需要安装dos2unix软件。

在centos下安装dos2unix:

yum install -y dos2unix

安装完成后,对文件进行转换

dos2unix abc.sh

现在执行就不会出问题了

转自:https://www.cnblogs.com/lucky-heng/p/10679900.html

Astyle格式化代码

基本命令

astyle --style=ansi main.cs

astyle 使用说明和集成到 各种IDE平台:https://www.cnblogs.com/jiangxinnju/p/4908575.html

Astyle格式化代码-选项说明


官方文档 http://astyle.sourceforge.net/astyle.html
配置了最佳的教科书格式


astyle *.c *.cpp *.h --recursive  --style=bsd  --convert-tabs --indent=spaces=8 --attach-closing-while  --indent-switches  --indent-namespaces --indent-continuation=4 --indent-preproc-block --indent-preproc-define --indent-preproc-cond --indent-col1-comments --pad-oper   --pad-paren-in   --unpad-paren  --delete-empty-lines --align-pointer=name    --align-reference=name --break-elseifs  --add-braces 

--indent-switches 缩进case标签


switch (foo)
{
case 1:
    a += 1;
    break;

case 2:
{
    a += 2;
    break;
}
}
becomes:

switch (foo)
{
    case 1:
        a += 1;
        break;

    case 2:
    {
        a += 2;
        break;
    }
}


--indent=spaces=8  缩进8个空格

void Foo() 
{
........bar();
}

--indent-namespaces 缩进命名空间块

namespace foospace
{
class Foo
{
    public:
        Foo();
        virtual ~Foo();
};
}
becomes:

namespace foospace
{
    class Foo
    {
        public:
            Foo();
            virtual ~Foo();
    };
}


--indent-continuation=4 等号=或(结尾后续本语句符号插入空格,默认为1,可取1~4

isLongVariable =
    foo1 ||
    foo2;

isLongFunction(
    bar1,
    bar2);
becomes (with indent-continuation=3):

isLongVariable =
            foo1 ||
            foo2;

isLongFunction(
            bar1,
            bar2);

--style=bsd 大括号独占一行,上下对齐

int Foo(bool isBar)
{
    if (isBar)
    {
        bar();
        return 1;
    }
    else
        return 0;
}


--attach-closing-while (while紧贴)

do
{
    bar();
    ++x;
}
while x == 1;
becomes:

do
{
    bar();
    ++x;
} while x == 1;

--indent-preproc-block 缩进#开头的处理语句

#ifdef _WIN32
#include <windows.h>
#ifndef NO_EXPORT
#define EXPORT
#endif
#endif
becomes:

#ifdef _WIN32
    #include <windows.h>
    #ifndef NO_EXPORT
        #define EXPORT
    #endif
#endif


--indent-preproc-cond  预处理语句也缩进


        isFoo = true;
#ifdef UNICODE
        text = wideBuff;
#else
        text = buff;
#endif
becomes:

        isFoo = true;
        #ifdef UNICODE
        text = wideBuff;
        #else
        text = buff;
        #endif


--indent-col1-comments 注释也缩进

void Foo()\n"
{
// comment
    if (isFoo)
        bar();
}
becomes:

void Foo()\n"
{
    // comment
    if (isFoo)
        bar();
}

--pad-oper 操作符间插入空格


if (foo==2)
    a=bar((b-c)*a,d--);
becomes:

if (foo == 2)
    a = bar((b - c) * a, d--);

--pad-comma 逗号间插入空格(--pad-oper中已有此效果)


if (isFoo(a,b))
    bar(a,b);
becomes:

if (isFoo(a, b))
    bar(a, b);

--pad-paren-in 括号里内插入空格


if (isFoo((a+2), b))
    bar(a, b);
becomes:

if ( isFoo( ( a+2 ), b ) )
    bar( a, b );


--unpad-paren 紧凑括号内外

if ( isFoo( ( a+2 ), b ) )
    bar ( a, b );
becomes (with no padding option requested):

if(isFoo((a+2), b))
    bar(a, b);

--delete-empty-lines 清除函数间的空行


void Foo()
{

    foo1 = 1;

    foo2 = 2;

}
becomes:

void Foo()
{
    foo1 = 1;
    foo2 = 2;
}


  指针符号紧贴哪

char* foo1;
char & foo2;
string ^s1;


becomes (with --align-pointer=type):

char* foo1;
char& foo2;
string^ s1;
char* foo1;
char & foo2;
string ^s1;


becomes (with --align-pointer=middle):

char * foo1;
char & foo2;
string ^ s1;
char* foo1;
char & foo2;
string ^s1;


becomes (with --align-pointer=name):

char *foo1;
char &foo2;
string ^s1;

//引用符号紧贴哪
char &foo1;


becomes (with --align-reference=type):

char& foo1;
char& foo2;
becomes (with --align-reference=middle):

char & foo2;
char& foo3;
becomes (with --align-reference=name):

char &foo3;

char &foo1;
becomes (with --align-reference=type):

char& foo1;
char& foo2;
becomes (with --align-reference=middle):

char & foo2;
char& foo3;
becomes (with --align-reference=name):

char &foo3;

--attach-return-type-decl 返回类型紧贴符号名


void
Foo(bool isFoo);
becomes:

void Foo(bool isFoo);


--add-braces 在'if', 'for', 'while'等句块中只有一行也加入大括号

if (isFoo)
    isFoo = false;
becomes:

if (isFoo) {
    isFoo = false;
}

--convert-tabs 将TAB符转化成空格,由转化参数指定,引号内的不转化

--recursive 遍历目录,文件名要指定为带通配符(*)的名字,含有空格的文件名要加引号


原文链接:https://blog.csdn.net/wisepragma/article/details/80993437

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • gitlab-ci 持续集成完整实践---待学习
  • 【服务器】身份认证系统(三)什么是OAuth2 + oauth的权限系统(鉴权系统)
  • 【Vue.js】Vue 学习笔记
  • 【粘包和拆包】数据帧粘包和拆包处理方式
  • 【网关】什么是网关、网桥和交换机(集线器、网桥、交换机、路由器、网关大解析)...
  • 【软件设计】架构设计 分析组件化与模块化之间的区别
  • 【word】word 笔记
  • 【前端】webpack、npm、node、nodejs之间的关系
  • 【Vue】前端的单页面模式和多页面模式
  • 【软件架构】运用RUP 4+1视图软件架构设计(逻辑视图、实现视图、进程视图、物理视图和用例视图)...
  • 【软件架构】软件的设计图纸(用例图,类图,状态图,活动图,顺序图)
  • 【nginx】linux nginx 部署静态网页
  • 【servlet】servlet技术是否过时?
  • 【vue】vue.js不就是一个文件吗?安装vue是什么意思?
  • 【Vue】Vue引入bootstrap的方法
  • $translatePartialLoader加载失败及解决方式
  • [iOS]Core Data浅析一 -- 启用Core Data
  • 【node学习】协程
  • Angular js 常用指令ng-if、ng-class、ng-option、ng-value、ng-click是如何使用的?
  • angular2开源库收集
  • echarts的各种常用效果展示
  • java B2B2C 源码多租户电子商城系统-Kafka基本使用介绍
  • Java 内存分配及垃圾回收机制初探
  • JAVA_NIO系列——Channel和Buffer详解
  • JavaScript 基本功--面试宝典
  • Java-详解HashMap
  • js面向对象
  • JS数组方法汇总
  • PHP面试之三:MySQL数据库
  • php中curl和soap方式请求服务超时问题
  • 阿里云爬虫风险管理产品商业化,为云端流量保驾护航
  • 编写高质量JavaScript代码之并发
  • 二维平面内的碰撞检测【一】
  • 飞驰在Mesos的涡轮引擎上
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 记录一下第一次使用npm
  • 简单实现一个textarea自适应高度
  • 开源中国专访:Chameleon原理首发,其它跨多端统一框架都是假的?
  • 限制Java线程池运行线程以及等待线程数量的策略
  • 3月27日云栖精选夜读 | 从 “城市大脑”实践,瞭望未来城市源起 ...
  • elasticsearch-head插件安装
  • Spark2.4.0源码分析之WorldCount 默认shuffling并行度为200(九) ...
  • ​flutter 代码混淆
  • ​用户画像从0到100的构建思路
  • !!java web学习笔记(一到五)
  • # Redis 入门到精通(七)-- redis 删除策略
  • #etcd#安装时出错
  • #pragma 指令
  • #宝哥教你#查看jquery绑定的事件函数
  • #我与Java虚拟机的故事#连载14:挑战高薪面试必看
  • $HTTP_POST_VARS['']和$_POST['']的区别
  • $refs 、$nextTic、动态组件、name的使用
  • (21)起落架/可伸缩相机支架
  • (AngularJS)Angular 控制器之间通信初探
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...