Merge #21123: code style: Add EditorConfig file

Merge #21123: code style: Add EditorConfig file

7a135d57b2ac17477b25d5046a3bec57eac3ab30 Add EditorConfig file. (Kiminuo)

Pull request description:

  ### 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? 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 by many IDEs and text editors. Sometimes, the support is out of the 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 for details on support. To name a few:

  * Visual Studio (out of the box)
  * VS Code (plugin)
  * JetBrains IDEs (IntelliJ IDEA, PyCharm, etc.) (out of the box)
  * Sublime Text (plugin)
  * Emacs (plugin)
  * Vim (plugin)

  Not supported (AFAIK):

  * [mcedit](

  ### 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. In VS Code & Visual Studio EditorConfig [takes precedence over other settings](

  ### Possible issues

  Your editor may change formatting for some 3rd party library if you edit the code. A solution for this would be to make EditorConfig rules more specific (include only certain paths). I'm not sure if it is an issue in practice.

  ### Testing

  Add some trailing whitespace to a Python file and save the file. You should see that the trailing whitespace is removed.

  ### Possible future work

  It would be great to define rules for Makefiles. This would be good start:

  # Makefiles
  indent_style = tab
  trim_trailing_whitespace = true

  I don't know makefiles in this project good enough to propose something reasonable. If this PR is well received, it would be great to add it in this PR.

  Also, there are actually many different file extensions and so the proposed `.editorconfig` file can be probably improved very much:

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

  <details><summary>Click to see the output</summary>



  Fixes #21092

ACKs for top commit:
    Tested re-ACK 7a135d57b2ac17477b25d5046a3bec57eac3ab30
    Approach ACK 7a135d57b2ac17477b25d5046a3bec57eac3ab30

Tree-SHA512: c36a3424ecc751fbdd66101463b0c470f5c7adcdb4795b1cd267ff718eb345a04615fc1182338adf5b7db724469dca00c64815a9ef77064734a6536fba41a2ba

情報元 - Merge #21123: code style: Add EditorConfig file · bitcoin/[email protected] · GitHub

Merge #21123: code style: Add EditorConfig file · bitcoin/bitcoin@b3dda0a · GitHub