美文网首页
不同IDE下编码风格统一(.editorconfig设置详解)

不同IDE下编码风格统一(.editorconfig设置详解)

作者: liuhuijuan | 来源:发表于2023-06-05 18:21 被阅读0次
    editorconfig作用
    • 各编辑器和IDE 保持一致编码风格
    • 多个开发人员 保持一致编码风格
    示例
    1. 项目根目录创建 .editorconfig 文件
    2. 把以下内容复制粘贴到.editorconfig内
    root = tue
    [*]
    charset = utf-8
    indent_style = space
    indent_size = 2
    end_of_line = lf
    insert_final_newline = true
    trim_trailing_whitespace = true
    
    1. 部分IDE需要下载插件,例如vscode需要安装插件EditorConfig for VS Code ,详见官网 https://editorconfig.org/
    2. 愉快的去体验吧~over
    配置项说明
    • root = true 控制 .editorconfig 是否生效的字段
    • [通配符]
    *               // 匹配除/之外的任意字符串
    **               //匹配任意字符串
    ?               // 匹配任意单个字符
    [name]          // 匹配name中的任意一个单一字符
    [!name]        //匹配不存在name中的任意一个单一字符
    {s1,s2,s3}     //  匹配给定的字符串中的任意一个(用逗号分隔) 
    {num1..num2}    //匹配num1到num2之间的任意一个整数, 这里的num1和num2可以为正整数也可以为负整数
    
    • charset 设置编码,值为latin1、utf-8、utf-8-bom、utf-16be和utf-16le
    • indent_style 设置缩进风格(tab是硬缩进,space为软缩进)
    • indent_size 用一个整数定义的列数来设置缩进的宽度,如果indent_style为tab,则此属性默认为tab_width
    • end_of_line 设置换行符,值为lf、cr和crlf
    lf  //全拼Line Feed,意思是换行,用符号 \n 表示
    cr  // 全拼Carriage Return, 意思是回车, 用符号 \r 表示
    crlf  //cr 和 lf的结合,回车换行,用符号 \r\n
    
    • insert_final_newline 设为true表示使文件以一个空白行结尾
    • trim_trailing_whitespace 设为true表示会去除换行行首的任意空白字符。

    相关文章

      网友评论

          本文标题:不同IDE下编码风格统一(.editorconfig设置详解)

          本文链接:https://www.haomeiwen.com/subject/nuhwedtx.html