Feature: Add EditorConfig #21092

issue kiminuo openend this issue on February 6, 2021
  1. kiminuo commented at 12:57 pm on February 6, 2021: contributor

    Motivation

    Developers are supposed to follow Coding style. However, from time to time a PR is created and then its author is asked to change tabs to spaces, for example.

    Introducing an .editorconfig file can mitigate these formatting issues:

    User story

    A contributor wants to create a new PR. She clones Bitcoin Core repo, opens her editor, the editor loads .editorconfig rules and writes her patch with correct formatting rules. Less Coding Style issues is then discovered in the PR review process and thus less CI runs are needed.

    What is EditorConfig file?

    https://editorconfig.org provides very well and concise explanation:

    What is EditorConfig?

    EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable and they work nicely with version control systems.

    Support

    .editorconfig is supported in many IDEs and text editors. Sometimes, the support is out-of-box and sometimes a plugin is needed. However, for example, VS Code detects .editorconfig presence and automatically offers you to install the missing plugin.

    See https://editorconfig.org/#pre-installed for details on support. Visual Studio is supported, VS Code and IntelliJ IDEA are supported and many others.

    My editor does not support .editorconfig

    Then nothing really changes for you.

    .editorconfig vs .clang-format

    As explained here:

    Note that Visual Studio also supports EditorConfig, which works in a similar way. ClangFormat, however, has a much larger variety of style options than EditorConfig, including some very C++ specific rules that can be set, and it is already used by C++ developers today.

    Having both .editorconfig and .clang-format in a project, may not always work correctly though, I think. As some editors may have a plugin for .editorconfig and a plugin for clang-formatter which may not work correctly in unison.

    Proposed .editorconfig

    This proposal is based on Developer Notes:

     0# This is the top-most EditorConfig file.
     1root = true
     2
     3# For all files.
     4[*]
     5charset = utf-8
     6end_of_line = lf
     7insert_final_newline = false
     8
     9# Shell scripts
    10[*.sh]
    11indent_size = 4
    12indent_style = space
    13trim_trailing_whitespace = true
    14
    15# C++ files
    16[*.{h,cpp}]
    17indent_size = 4
    18indent_style = space
    19trim_trailing_whitespace = true
    20
    21# Python files
    22[*.py]
    23indent_size = 4
    24indent_style = space
    25trim_trailing_whitespace = true
    26
    27# Makefiles
    28[Makefile,*.am]
    29indent_style = tab
    30trim_trailing_whitespace = true
    31
    32# Markdown files
    33[*.md]
    34trim_trailing_whitespace = true
    35
    36# .cirrus.yml, .appveyor.yml, .fuzzbuzz.yml, etc.
    37[*.yml]
    38indent_style = space
    39indent_size = 2
    40trim_trailing_whitespace = true
    

    Note that the syntax can be much shorter but it is not my goal here, I prefer clarity at this point.

    So what is this specifying:

    • charset: Use UTF-8 in all files.
    • end_of_line: Line endings should be LF by default in all files.
    • insert_final_newline: Do not add a blank line at the end of a file by default.

    And then there are rules for various types of files.

    The rules does not cover everything. One can see that there actually many different file types (meaning, unique file extensions) using this simple PowerShell script:

    0Get-ChildItem -Recurse | % {$_.Extension.ToLower()} | sort | unique
    

    with the following output:

      0.1
      1.ac
      2.adoc
      3.am
      4.bash-completion
      5.bat
      6.bmp
      7.c
      8.cc
      9.cert
     10.cfg
     11.clang_complete
     12.clang-format
     13.cmake
     14.cmd
     15.cnf
     16.com
     17.conf
     18.cpp
     19.css
     20.csv
     21.doxyfile
     22.dtd
     23.empty
     24.exe
     25.exp
     26.gci
     27.gitattributes
     28.github
     29.gitignore
     30.gitmodules
     31.guess
     32.h
     33.hex
     34.hpp
     35.html
     36.icns
     37.ico
     38.idb
     39.ilk
     40.in
     41.include
     42.ini
     43.init
     44.ipp
     45.jam
     46.js
     47.json
     48.lastbuildstate
     49.lib
     50.list
     51.log
     52.m
     53.m4
     54.md
     55.mk
     56.mm
     57.moc
     58.obj
     59.openrc
     60.openrcconf
     61.patch
     62.pc
     63.pdb
     64.pl
     65.plist
     66.png
     67.po
     68.pro
     69.py
     70.python-version
     71.qbk
     72.qm
     73.qml
     74.qrc
     75.raw
     76.rb
     77.rc
     78.recipe
     79.res
     80.s
     81.sage
     82.sass
     83.scm
     84.scss
     85.service
     86.sgml
     87.sh
     88.sln
     89.spec
     90.sub
     91.supp
     92.svg
     93.targets
     94.td
     95.tlog
     96.ts
     97.tx
     98.txt
     99.ui
    100.user
    101.v2
    102.vcxproj
    103.verbatim
    104.vscode
    105.xml
    106.xpm
    107.xsl
    108.y
    109.yapf
    110.yml
    111.yy
    

    What do you think?

  2. kiminuo added the label Feature on Feb 6, 2021
  3. laanwj commented at 7:06 pm on February 6, 2021: member

    Concept ACK, I think the editorconfig idea is quite elegant.

    I like that it works on a lower level than clang-format, it specifies basic formatting such as character set, indentation and newline use. So it also works for editors that don’t have language specific parsing. There seem to be plugins for a lot of editors that don’t have built-in support.

  4. practicalswift commented at 8:42 pm on February 6, 2021: contributor

    Concept ACK

    I think we should be very liberal with accepting editor dotfiles for obvious reasons:

    They help people using an editor which understands the dotfile in question, and everyone else can safely ignore them.

    We’re not in the business of dictating what tools people should use: that’s nanny state behaviour :)

  5. theStack commented at 11:15 pm on February 6, 2021: member
    Concept ACK Never heard of the EditorConfig project before but seems to be a very nice solution for a common problem. Although this is already one step further, but also specifying a soft limit for line lengths would be nice (soft in the sense that it is not enforced by the editor, but only visually shown e.g. as a colored column), if this ends up in the coding guidelines (as proposed in #20986).
  6. laanwj closed this on Feb 10, 2021

  7. sidhujag referenced this in commit 0cfee49446 on Feb 11, 2021
  8. PastaPastaPasta referenced this in commit 3cba474d6a on Jun 27, 2021
  9. PastaPastaPasta referenced this in commit 64efa9ee97 on Jun 28, 2021
  10. PastaPastaPasta referenced this in commit 4fcfb96261 on Jun 29, 2021
  11. PastaPastaPasta referenced this in commit b70e88b420 on Jul 1, 2021
  12. PastaPastaPasta referenced this in commit 54d505044d on Jul 1, 2021
  13. PastaPastaPasta referenced this in commit 33b761c4ec on Jul 15, 2021
  14. PastaPastaPasta referenced this in commit a9c314feba on Jul 16, 2021
  15. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-01-15 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me