[Mesa-dev] [PATCH mesa] Introduce .editorconfig

Eric Engestrom eric at engestrom.ch
Mon Aug 29 21:30:58 UTC 2016


A few weeks ago, Jose Fonseca suggested [0] we use .editorconfig files
to try and enforce the formatting of the code, to which Michel Dänzer
suggested [1] we start by importing the existing .dir-locals.el
settings. The first draft was discussed in the RFC [2].

These .editorconfig are a first step, one that has the advantage of
requiring little to no intervention from the devs once the settings
files are in place, but the settings are very limited. This does have
the advantage of applying while the code is being written.
This doesn't replace the need for more comprehensive formatting tools
such as clang-format & clang-tidy, but those reformat the code after
the fact.

[0] https://lists.freedesktop.org/archives/mesa-dev/2016-June/121545.html
[1] https://lists.freedesktop.org/archives/mesa-dev/2016-June/121639.html
[2] https://lists.freedesktop.org/archives/mesa-dev/2016-July/123431.html

Reviewed-by: Eric Anholt <eric at anholt.net> (for vc4)
Acked-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
Signed-off-by: Eric Engestrom <eric at engestrom.ch>
---

First off, sorry I took so long to follow up on this.
Here's the v1 with most of the changes suggested in the RFC/v0, except for the
couple following issues:

Jose thinks I should remove this line:
> +trim_trailing_whitespace = true

His reasoning is:
> I'm sure we have lots of files with trailing whitespace, and this means that
> people doing trivial one liner fixes might suddently cause the whole file to
> be munged and stripped.
>
> So I think we should remove this from the top level editorconfig.  It's fine
> to have it on specific subdirs, which are know to be trailing-whitespace free.

I don't think waiting for the rule to be followed before introducing it can
work, but I do understand that introducing it like this might result in people
sending a lot of whitespace changes in unrelated patches.
One solution I would prefer is to have a cleanup patch (in the same series) that
removes those trailing spaces, making the rule enforceable right away.
What do you guys think?

A couple of people have also suggested I add `tab_width`, but IMO this concept
should die: it comes from the confusion between indentation (a logic concept
meant to convey code structure) and alignment (an aesthetic concept).
If you need a specific size for your tabs, you're not indenting, you're
aligning, which makes no sense to do with a character that will have a varying
size in the first place.
There is a (pointless IMO, who cares?) war between tab and space indentation
with various arguments on each side, but I have yet to find anyone with a single
argument in favour of using varying-width characters to align code... yet I keep
seeing people doing it.
(OK, that's not true: I do have a preference for space indentation, because it
makes it harder for people to do the wrong thing when they get confused)
</rant> (sorry)
---
 .editorconfig                                    | 35 ++++++++++++++++++++++++
 bin/.editorconfig                                |  3 ++
 include/CL/.editorconfig                         |  3 ++
 include/D3D9/.editorconfig                       |  2 ++
 include/c11/.editorconfig                        |  3 ++
 include/d3dadapter/.editorconfig                 |  3 ++
 include/vulkan/.editorconfig                     |  3 ++
 src/egl/drivers/haiku/.editorconfig              |  2 ++
 src/egl/wayland/.editorconfig                    |  2 ++
 src/gallium/drivers/freedreno/.editorconfig      |  2 ++
 src/gallium/drivers/r300/.editorconfig           |  3 ++
 src/gallium/drivers/r600/.editorconfig           |  2 ++
 src/gallium/drivers/radeon/.editorconfig         |  2 ++
 src/gallium/drivers/radeonsi/.editorconfig       |  2 ++
 src/gallium/drivers/vc4/.editorconfig            |  3 ++
 src/gallium/drivers/vc4/kernel/.editorconfig     |  2 ++
 src/gallium/state_trackers/hgl/.editorconfig     |  2 ++
 src/gallium/state_trackers/nine/.editorconfig    |  3 ++
 src/gallium/state_trackers/xa/.editorconfig      |  3 ++
 src/gallium/targets/d3dadapter9/.editorconfig    |  3 ++
 src/gallium/targets/haiku-softpipe/.editorconfig |  2 ++
 src/gallium/winsys/freedreno/drm/.editorconfig   |  2 ++
 src/gallium/winsys/nouveau/drm/.editorconfig     |  2 ++
 src/gallium/winsys/radeon/drm/.editorconfig      |  3 ++
 src/gallium/winsys/sw/hgl/.editorconfig          |  2 ++
 src/getopt/.editorconfig                         |  2 ++
 src/gtest/.editorconfig                          |  3 ++
 src/hgl/.editorconfig                            |  2 ++
 src/mesa/drivers/dri/nouveau/.editorconfig       |  2 ++
 29 files changed, 103 insertions(+)
 create mode 100644 .editorconfig
 create mode 100644 bin/.editorconfig
 create mode 100644 include/CL/.editorconfig
 create mode 100644 include/D3D9/.editorconfig
 create mode 100644 include/c11/.editorconfig
 create mode 100644 include/d3dadapter/.editorconfig
 create mode 100644 include/vulkan/.editorconfig
 create mode 100644 src/egl/drivers/haiku/.editorconfig
 create mode 100644 src/egl/wayland/.editorconfig
 create mode 100644 src/gallium/drivers/freedreno/.editorconfig
 create mode 100644 src/gallium/drivers/r300/.editorconfig
 create mode 100644 src/gallium/drivers/r600/.editorconfig
 create mode 100644 src/gallium/drivers/radeon/.editorconfig
 create mode 100644 src/gallium/drivers/radeonsi/.editorconfig
 create mode 100644 src/gallium/drivers/vc4/.editorconfig
 create mode 100644 src/gallium/drivers/vc4/kernel/.editorconfig
 create mode 100644 src/gallium/state_trackers/hgl/.editorconfig
 create mode 100644 src/gallium/state_trackers/nine/.editorconfig
 create mode 100644 src/gallium/state_trackers/xa/.editorconfig
 create mode 100644 src/gallium/targets/d3dadapter9/.editorconfig
 create mode 100644 src/gallium/targets/haiku-softpipe/.editorconfig
 create mode 100644 src/gallium/winsys/freedreno/drm/.editorconfig
 create mode 100644 src/gallium/winsys/nouveau/drm/.editorconfig
 create mode 100644 src/gallium/winsys/radeon/drm/.editorconfig
 create mode 100644 src/gallium/winsys/sw/hgl/.editorconfig
 create mode 100644 src/getopt/.editorconfig
 create mode 100644 src/gtest/.editorconfig
 create mode 100644 src/hgl/.editorconfig
 create mode 100644 src/mesa/drivers/dri/nouveau/.editorconfig

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..b7cdc88
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,35 @@
+# To use this config on you editor, follow the instructions at:
+# http://editorconfig.org
+
+root = true
+
+[*]
+charset = utf-8
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[*.{c,h,cpp,hpp,cc,hh}]
+indent_style = space
+indent_size = 3
+
+[{Makefile*,*.mk}]
+indent_style = tab
+
+[{*.py,SCons*}]
+indent_style = space
+indent_size = 4
+
+[*.pl]
+indent_style = space
+indent_size = 4
+
+[*.m4]
+indent_style = space
+indent_size = 2
+
+[*.yml]
+indent_style = space
+indent_size = 2
+
+[*.patch]
+trim_trailing_whitespace = false
diff --git a/bin/.editorconfig b/bin/.editorconfig
new file mode 100644
index 0000000..b9a948f
--- /dev/null
+++ b/bin/.editorconfig
@@ -0,0 +1,3 @@
+[*.sh]
+indent_style = space
+indent_size = 2
diff --git a/include/CL/.editorconfig b/include/CL/.editorconfig
new file mode 100644
index 0000000..da2afc4
--- /dev/null
+++ b/include/CL/.editorconfig
@@ -0,0 +1,3 @@
+[*.{h,hpp}]
+indent_style = space
+indent_size = 4
diff --git a/include/D3D9/.editorconfig b/include/D3D9/.editorconfig
new file mode 100644
index 0000000..0dcc752
--- /dev/null
+++ b/include/D3D9/.editorconfig
@@ -0,0 +1,2 @@
+[*.h]
+indent_style = tab
diff --git a/include/c11/.editorconfig b/include/c11/.editorconfig
new file mode 100644
index 0000000..bdbea00
--- /dev/null
+++ b/include/c11/.editorconfig
@@ -0,0 +1,3 @@
+[*.h]
+indent_style = space
+indent_size = 4
diff --git a/include/d3dadapter/.editorconfig b/include/d3dadapter/.editorconfig
new file mode 100644
index 0000000..bdbea00
--- /dev/null
+++ b/include/d3dadapter/.editorconfig
@@ -0,0 +1,3 @@
+[*.h]
+indent_style = space
+indent_size = 4
diff --git a/include/vulkan/.editorconfig b/include/vulkan/.editorconfig
new file mode 100644
index 0000000..bdbea00
--- /dev/null
+++ b/include/vulkan/.editorconfig
@@ -0,0 +1,3 @@
+[*.h]
+indent_style = space
+indent_size = 4
diff --git a/src/egl/drivers/haiku/.editorconfig b/src/egl/drivers/haiku/.editorconfig
new file mode 100644
index 0000000..5ae8c6f
--- /dev/null
+++ b/src/egl/drivers/haiku/.editorconfig
@@ -0,0 +1,2 @@
+[*.cpp]
+indent_style = tab
diff --git a/src/egl/wayland/.editorconfig b/src/egl/wayland/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/egl/wayland/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/drivers/freedreno/.editorconfig b/src/gallium/drivers/freedreno/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/drivers/freedreno/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/drivers/r300/.editorconfig b/src/gallium/drivers/r300/.editorconfig
new file mode 100644
index 0000000..7b12a40
--- /dev/null
+++ b/src/gallium/drivers/r300/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+indent_style = space
+indent_size = 4
diff --git a/src/gallium/drivers/r600/.editorconfig b/src/gallium/drivers/r600/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/drivers/r600/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/drivers/radeon/.editorconfig b/src/gallium/drivers/radeon/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/drivers/radeon/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/drivers/radeonsi/.editorconfig b/src/gallium/drivers/radeonsi/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/drivers/radeonsi/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/drivers/vc4/.editorconfig b/src/gallium/drivers/vc4/.editorconfig
new file mode 100644
index 0000000..f3d8c47
--- /dev/null
+++ b/src/gallium/drivers/vc4/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+indent_style = space
+indent_size = 8
diff --git a/src/gallium/drivers/vc4/kernel/.editorconfig b/src/gallium/drivers/vc4/kernel/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/drivers/vc4/kernel/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/state_trackers/hgl/.editorconfig b/src/gallium/state_trackers/hgl/.editorconfig
new file mode 100644
index 0000000..f391def
--- /dev/null
+++ b/src/gallium/state_trackers/hgl/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h,cpp,hpp}]
+indent_style = tab
diff --git a/src/gallium/state_trackers/nine/.editorconfig b/src/gallium/state_trackers/nine/.editorconfig
new file mode 100644
index 0000000..7b12a40
--- /dev/null
+++ b/src/gallium/state_trackers/nine/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+indent_style = space
+indent_size = 4
diff --git a/src/gallium/state_trackers/xa/.editorconfig b/src/gallium/state_trackers/xa/.editorconfig
new file mode 100644
index 0000000..7b12a40
--- /dev/null
+++ b/src/gallium/state_trackers/xa/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+indent_style = space
+indent_size = 4
diff --git a/src/gallium/targets/d3dadapter9/.editorconfig b/src/gallium/targets/d3dadapter9/.editorconfig
new file mode 100644
index 0000000..7b12a40
--- /dev/null
+++ b/src/gallium/targets/d3dadapter9/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+indent_style = space
+indent_size = 4
diff --git a/src/gallium/targets/haiku-softpipe/.editorconfig b/src/gallium/targets/haiku-softpipe/.editorconfig
new file mode 100644
index 0000000..f391def
--- /dev/null
+++ b/src/gallium/targets/haiku-softpipe/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h,cpp,hpp}]
+indent_style = tab
diff --git a/src/gallium/winsys/freedreno/drm/.editorconfig b/src/gallium/winsys/freedreno/drm/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/winsys/freedreno/drm/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/winsys/nouveau/drm/.editorconfig b/src/gallium/winsys/nouveau/drm/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/winsys/nouveau/drm/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gallium/winsys/radeon/drm/.editorconfig b/src/gallium/winsys/radeon/drm/.editorconfig
new file mode 100644
index 0000000..7b12a40
--- /dev/null
+++ b/src/gallium/winsys/radeon/drm/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c,h}]
+indent_style = space
+indent_size = 4
diff --git a/src/gallium/winsys/sw/hgl/.editorconfig b/src/gallium/winsys/sw/hgl/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/gallium/winsys/sw/hgl/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/getopt/.editorconfig b/src/getopt/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/getopt/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
diff --git a/src/gtest/.editorconfig b/src/gtest/.editorconfig
new file mode 100644
index 0000000..0880bac
--- /dev/null
+++ b/src/gtest/.editorconfig
@@ -0,0 +1,3 @@
+[*.{cc,h}]
+indent_style = space
+indent_size = 2
diff --git a/src/hgl/.editorconfig b/src/hgl/.editorconfig
new file mode 100644
index 0000000..0a01d20
--- /dev/null
+++ b/src/hgl/.editorconfig
@@ -0,0 +1,2 @@
+[*.{cpp,h}]
+indent_style = tab
diff --git a/src/mesa/drivers/dri/nouveau/.editorconfig b/src/mesa/drivers/dri/nouveau/.editorconfig
new file mode 100644
index 0000000..cc8e11f
--- /dev/null
+++ b/src/mesa/drivers/dri/nouveau/.editorconfig
@@ -0,0 +1,2 @@
+[*.{c,h}]
+indent_style = tab
-- 
Cheers,
  Eric


More information about the mesa-dev mailing list