editorconfig: Add automatic editor configuration file
Subsystems (2)
PATCH 1/1 editorconfig: Add automatic editor configuration file
EditorConfig is a standard for defining basic editor configuration in projects. There is support available for 47 code editors as of writing, including both built-in and extension support. Many notable projects have adopted the standard already, including zsh, htop, and qemu.
While this isn't a full-fledged C code style specifier, it does set some basic ground rules that make it more convenient for contributors to use any editor of their choice and not have to worry about indentation, line endings, encoding, final newlines, etc. This should make it significantly easier to conform to the kernel's general code style when used in combination with clang-format.
For more information, check the official EditorConfig website:
https://editorconfig.org/
--- .editorconfig | 16 ++++++++++++++++ .gitignore | 1 + Documentation/process/4.Coding.rst | 6 ++++++ 3 files changed, 23 insertions(+) create mode 100644 .editorconfig
.editorconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 +# Linux kernel EditorConfig file (https://editorconfig.org/) + +# Located at the project root +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true + +indent_style = tab +indent_size = 8 + +# This avoids introducing too many unnecessary changes in trivial commits +trim_trailing_whitespace = false
.gitignore +1 -0
@@ -89,6 +89,7 @@ modules.order # !.clang-format !.cocciconfig +!.editorconfig !.get_maintainer.ignore !.gitattributes !.gitignore
Documentation/process/4.Coding.rst +6 -0
@@ -66,6 +66,12 @@ for aligning variables/macros, for reflowing text and other similar tasks. See the file :ref:`Documentation/process/clang-format.rst <clangformat>` for more details. +Some basic editor settings, such as indentation and line endings, will be +set automatically if you are using an editor that is compatible with +EditorConfig. See the official EditorConfig website for more information: + +https://editorconfig.org/ + Abstraction layers ******************
Signature · 1 line
2.27.0
Hi Danny,
.editorconfig line 9
Quoted 4 lines · Danny Lin
+[*]
.editorconfig new file +2
-0+charset = utf-8 +end_of_line = lf
While UTF-8 and LF are probably OK for all files, I am not 100% sure about:
.editorconfig line 13
Quoted 3 lines
.editorconfig new file +3
-0+insert_final_newline = true +indent_style = tab +indent_size = 8
for other languages and non-code files we may have around. Perhaps it is best to avoid [*] unless we are sure?
Cheers,
Miguel
Quoted 8 lines · Miguel Ojeda
Hi Danny,
.editorconfig line 9
Quoted 3 lines · Danny Lin
+[*]
.editorconfig new file +2
-0+charset = utf-8 +end_of_line = lfWhile UTF-8 and LF are probably OK for all files, I am not 100% sure
about:
Quoted 6 lines
.editorconfig line 13
Quoted 3 lines
.editorconfig new file +3
-0+insert_final_newline = true +indent_style = tab +indent_size = 8for other languages and non-code files we may have around. Perhaps it is best to avoid
[*]unless we are sure?
Most of the other exceptions can be accomodated for with more specific rules below the base [*] section. I just went through most of the kernel's files and added rules for the vast majority of the exceptinos to the 8-column tab indent style, though there are still some that haven't been covered.
It looks like some types of files lack consistent indentation, e.g. arch/mips/*/Platform and some shell scripts in scripts/ tools/testing/ selftests/ftrace/test.d/kprobe/*.tc. There are also some files that were highly inconsistent even within themselves (e.g. drivers/gpu/drm/amd/ amdkfd/cwsr_trap_handler_gfx*.asm), so setting indentation settings to something sane by default doesn't make them any worse. After all, no automated code style tooling is perfect and there will be edge cases where it breaks down.
That being said, I think most of the exceptions should be taken care of now; please feel free to suggest a better way to deal with these.
Quoted 3 lines
Cheers,
Miguel
PATCH v2 1/1 editorconfig: Add automatic editor configuration file
EditorConfig is a standard for defining basic editor configuration in projects. There is support available for 47 code editors as of writing, including both built-in and extension support. Many notable projects have adopted the standard already, including zsh, htop, and qemu.
While this isn't a full-fledged C code style specifier, it does set some basic ground rules that make it more convenient for contributors to use any editor of their choice and not have to worry about indentation, line endings, encoding, final newlines, etc. This should make it significantly easier to conform to the kernel's general code style when used in combination with clang-format.
For more information, check the official EditorConfig website:
https://editorconfig.org/
---
v2:
- Added rules for most exceptions to the 8-column tab indent style
.editorconfig | 37 ++++++++++++++++++++++++++++++ .gitignore | 1 + Documentation/process/4.Coding.rst | 6 +++++ 3 files changed, 44 insertions(+) create mode 100644 .editorconfig
.editorconfig new file +37 -0
@@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0 +# Linux kernel EditorConfig file (https://editorconfig.org/) + +# Located at the project root +root = true + +# Base settings for most files +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true + +indent_style = tab +indent_size = 8 + +# This avoids introducing too many unnecessary changes in trivial commits +trim_trailing_whitespace = false + +# General 4-space files +[*.{pl,pm,py,tc,json,tc}] +indent_style = space +indent_size = 4 + +# General 2-space files +[*.{rb,rst,yaml,cocci,xsl,svg,bconf,clang-format}] +indent_style = space +indent_size = 2 + +# Perf script wrappers +[tools/perf/scripts/*/bin/*] +indent_style = space +indent_size = 4 + +# Man pages +[*.{1,2,3,4,5,6,7,8}] +indent_style = space +indent_size = 2
.gitignore +1 -0
@@ -89,6 +89,7 @@ modules.order # !.clang-format !.cocciconfig +!.editorconfig !.get_maintainer.ignore !.gitattributes !.gitignore
Documentation/process/4.Coding.rst +6 -0
@@ -66,6 +66,12 @@ for aligning variables/macros, for reflowing text and other similar tasks. See the file :ref:`Documentation/process/clang-format.rst <clangformat>` for more details. +Some basic editor settings, such as indentation and line endings, will be +set automatically if you are using an editor that is compatible with +EditorConfig. See the official EditorConfig website for more information: + +https://editorconfig.org/ + Abstraction layers ******************
Signature · 1 line
2.27.0
Jonathan Corbet
maintainerQuoted 12 lines · On Fri, 3 Jul 2020 00:31:43 -0700 Danny Lin <[email protected]> wrote:
EditorConfig is a standard for defining basic editor configuration in projects. There is support available for 47 code editors as of writing, including both built-in and extension support. Many notable projects have adopted the standard already, including zsh, htop, and qemu.
While this isn't a full-fledged C code style specifier, it does set some basic ground rules that make it more convenient for contributors to use any editor of their choice and not have to worry about indentation, line endings, encoding, final newlines, etc. This should make it significantly easier to conform to the kernel's general code style when used in combination with clang-format.
Quoted 5 lines
For more information, check the official EditorConfig website:
https://editorconfig.org/Signed-off-by Danny Lin <[email protected]>---
So I worry a bit that not everybody will welcome the addition of a dotfile that may be magically interpreted by their editor. I also worry that the file itself could become a battleground for people wanting to argue about style issues.
Perhaps I worry a bit too much...?
jon
On 03/07/2020 14.29, Jonathan Corbet wrote:
[doing a bit of necromancy here]
Quoted 15 lines
Quoted 12 lines · On Fri, 3 Jul 2020 00:31:43 -0700 Danny Lin <[email protected]> wrote:
EditorConfig is a standard for defining basic editor configuration in projects. There is support available for 47 code editors as of writing, including both built-in and extension support. Many notable projects have adopted the standard already, including zsh, htop, and qemu.
While this isn't a full-fledged C code style specifier, it does set some basic ground rules that make it more convenient for contributors to use any editor of their choice and not have to worry about indentation, line endings, encoding, final newlines, etc. This should make it significantly easier to conform to the kernel's general code style when used in combination with clang-format.
Quoted 8 lines
Quoted 5 lines
For more information, check the official EditorConfig website:
https://editorconfig.org/Signed-off-by Danny Lin <[email protected]>---
So I worry a bit that not everybody will welcome the addition of a dotfile that may be magically interpreted by their editor.
I would suppose that one would have to enable editorconfig support explicitly in one's editor, so this would have no effect for people that haven't done so (though there are almost certainly exceptions).
Quoted 3 lines
I also worry that the
file itself could become a battleground for people wanting to argue about style issues.
I don't think so, not any more than the coding-style document is, and that seems to be pretty solid (but as doc maintainer, you'd know better).
Quoted 2 lines
Perhaps I worry a bit too much...?
As someone who regularly needs to submit patches to random upstream projects to fix bugs or implement minor features, I for one would really welcome more widespread use of editorconfig. While I mostly work with the linux kernel (and other projects using the same C style), so my default C style setting is "linux", even for the kernel this would be helpful to me when I poke around in none-C files (shell scripts, for example).
Rasmus
Quoted 51 lines · Rasmus Villemoes
On 03/07/2020 14.29, Jonathan Corbet wrote:
[doing a bit of necromancy here]
Quoted 15 lines
Quoted 12 lines · On Fri, 3 Jul 2020 00:31:43 -0700 Danny Lin <[email protected]> wrote:
EditorConfig is a standard for defining basic editor configuration in projects. There is support available for 47 code editors as of writing, including both built-in and extension support. Many notable projects have adopted the standard already, including zsh, htop, and qemu.
While this isn't a full-fledged C code style specifier, it does set some basic ground rules that make it more convenient for contributors to use any editor of their choice and not have to worry about indentation, line endings, encoding, final newlines, etc. This should make it significantly easier to conform to the kernel's general code style when used in combination with clang-format.
Quoted 8 lines
Quoted 5 lines
For more information, check the official EditorConfig website:
https://editorconfig.org/Signed-off-by Danny Lin <[email protected]>---
So I worry a bit that not everybody will welcome the addition of a dotfile that may be magically interpreted by their editor.
I would suppose that one would have to enable editorconfig support explicitly in one's editor, so this would have no effect for people that haven't done so (though there are almost certainly exceptions).
Quoted 3 lines
I also worry that the
file itself could become a battleground for people wanting to argue about style issues.I don't think so, not any more than the coding-style document is, and that seems to be pretty solid (but as doc maintainer, you'd know better).
Quoted 2 lines
Perhaps I worry a bit too much...?
As someone who regularly needs to submit patches to random upstream projects to fix bugs or implement minor features, I for one would really welcome more widespread use of editorconfig. While I mostly work with the linux kernel (and other projects using the same C style), so my default C style setting is "linux", even for the kernel this would be helpful to me when I poke around in none-C files (shell scripts, for example).
Quoted 1 line
Rasmus
Just from my curiosity, I just checked the behavior when the language is specified by a shebang line.
For example, scripts/diffconfig has no file suffix, but specifies '#!/usr/bin/env python3'
at the very top line.
This is sensible for tools that interface to users. Users have no interest in which language is used internally.
As far as I test this patch on Emacs, it follows the rule of [*] rather than [*.{pl,pm,py,tc,json,tc}].
This is the correct behavior but not what we want in general.
I do not mean I am negative to this patch. Rather, I very much like this patch, but I just wondered how this case could be handled.
I found this:
https://github.com/editorconfig/editorconfig/issues/404
I did not read through it, though.
--
Best Regards
Masahiro Yamada
Quoted 4 lines · Masahiro Yamada
This is sensible for tools that interface to users. Users have no interest in which language is used internally.
Agreed in the general case (e.g. everyday tools). In the kernel's case, however, I think it is not as important.
And I guess most of us tab-autocomplete anyway... :-)
Quoted 2 lines
Rather, I very much like this patch, but I just
wondered how this case could be handled.
Symlinks might be a good way when there is an installer of some kind. But in the kernel's case, I would prefer to avoid having symlinks for every script (in particular if they are in the same folder).
Cheers,
Miguel
.editorconfig line 17
Quoted 2 lines · Danny Lin
.editorconfig new file +2
-0+# This avoids introducing too many unnecessary changes in trivial commits +trim_trailing_whitespace = false
I think we prefer trailing whitespace to be trimmed, even for trivial commits.
.editorconfig line 27
Quoted 9 lines
.editorconfig new file +9
-0+# General 4-space files +[*.{pl,pm,py,tc,json,tc}] +indent_style = space +indent_size = 4 + +# General 2-space files +[*.{rb,rst,yaml,cocci,xsl,svg,bconf,clang-format}] +indent_style = space +indent_size = 2
The rst files I've seen either use tabs or three spaces for indent. Where did this 2 come from?
Quoted 5 lines · Matthew Wilcox
.editorconfig line 17
Quoted 2 lines · Danny Lin
.editorconfig new file +2
-0+# This avoids introducing too many unnecessary changes in trivial commits +trim_trailing_whitespace = falseI think we prefer trailing whitespace to be trimmed, even for trivial commits.
I think so as well, but I also believe the flag will whitespace trim not just any modified lines in a patch, but all lines in the file.
That _might_ be an issue, but if it is, it's trivial.
There are ~50k files and ~26000k lines in the linux kernel source tree.
There are ~2k files and ~24k lines with trailing spaces in the code.
$ git grep -P --name-only "\s+$" -- '*.[ch]' | wc -l 2035
$ git grep -P "\s+$" -- '*.[ch]' | wc -l 24083
It's spread all over the kernel, mostly in old files so likely it doesn't matter much.
$ git grep -P --name-only "\s+$" -- '*.[ch]' | \
cut -f1,2 -d'/' | sort | uniq -c
108 arch/alpha
51 arch/arm
1 arch/arm64
18 arch/ia64
20 arch/m68k
1 arch/mips
90 arch/parisc
73 arch/powerpc
20 arch/s390
2 arch/sh
57 arch/sparc
32 arch/um
27 arch/x86
17 arch/xtensa
1 block/blk-mq.h
7 block/partitions
1 block/scsi_ioctl.c
1 crypto/khazad.c
1 crypto/md4.c
1 crypto/md5.c
1 crypto/proc.c
1 crypto/tea.c
1 crypto/tgr192.c
1 crypto/twofish_generic.c
4 drivers/acpi
1 drivers/ata
29 drivers/atm
1 drivers/base
31 drivers/block
1 drivers/bus
1 drivers/cdrom
20 drivers/char
2 drivers/clk
3 drivers/clocksource
1 drivers/connector
2 drivers/cpufreq
1 drivers/cpuidle
1 drivers/crypto
1 drivers/dio
1 drivers/dma
1 drivers/dma-buf
1 drivers/extcon
55 drivers/gpu
8 drivers/hid
3 drivers/hwmon
5 drivers/i2c
18 drivers/ide
3 drivers/iio
1 drivers/infiniband
6 drivers/input
1 drivers/irqchip
14 drivers/macintosh
1 drivers/memory
2 drivers/message
1 drivers/mfd
1 drivers/misc
2 drivers/mmc
7 drivers/mtd
85 drivers/net
3 drivers/nvme
17 drivers/parisc
10 drivers/parport
13 drivers/pcmcia
2 drivers/platform
2 drivers/pnp
1 drivers/power
1 drivers/regulator
10 drivers/s390
4 drivers/sbus
121 drivers/scsi
2 drivers/soc
1 drivers/spi
1 drivers/staging
1 drivers/target
30 drivers/tty
31 drivers/usb
1 drivers/vhost
70 drivers/video
2 drivers/xen
2 fs/adfs
1 fs/affs
1 fs/afs
1 fs/aio.c
1 fs/bad_inode.c
1 fs/bfs
1 fs/binfmt_aout.c
1 fs/binfmt_elf.c
1 fs/binfmt_em86.c
1 fs/block_dev.c
3 fs/btrfs
1 fs/buffer.c
2 fs/ceph
2 fs/cifs
11 fs/coda
1 fs/compat.c
1 fs/dcache.c
1 fs/dcookies.c
1 fs/direct-io.c
3 fs/dlm
1 fs/d_path.c
5 fs/efs
9 fs/ext2
4 fs/ext4
1 fs/fcntl.c
1 fs/filesystems.c
9 fs/freevxfs
1 fs/fscache
13 fs/gfs2
1 fs/hfs
11 fs/hpfs
4 fs/isofs
3 fs/jbd2
9 fs/jffs2
5 fs/lockd
1 fs/mpage.c
1 fs/namei.c
11 fs/nfs
16 fs/nfsd
37 fs/nls
8 fs/ntfs
4 fs/ocfs2
1 fs/omfs
1 fs/open.c
1 fs/openpromfs
1 fs/pnode.c
1 fs/posix_acl.c
5 fs/proc
1 fs/qnx4
1 fs/readdir.c
1 fs/read_write.c
2 fs/reiserfs
1 fs/select.c
5 fs/sysv
1 fs/timerfd.c
1 fs/ubifs
9 fs/ufs
9 fs/xfs
8 include/crypto
97 include/linux
6 include/math-emu
29 include/net
8 include/scsi
22 include/sound
1 include/trace
114 include/uapi
6 include/video
2 include/xen
1 init/do_mounts.c
1 kernel/audit.h
1 kernel/auditsc.c
1 kernel/nsproxy.c
1 kernel/power
1 kernel/signal.c
1 kernel/sysctl.c
3 kernel/trace
1 kernel/user.c
2 lib/fonts
1 lib/inflate.c
1 lib/libcrc32c.c
1 lib/textsearch.c
1 lib/ts_bm.c
1 lib/ts_kmp.c
3 lib/zlib_deflate
2 lib/zlib_inflate
1 mm/memory-failure.c
1 mm/oom_kill.c
1 mm/page_io.c
1 mm/rmap.c
1 mm/swap_state.c
1 net/ethtool
1 net/rxrpc
1 samples/connector
1 scripts/asn1_compiler.c
1 scripts/gcc-plugins
1 security/commoncap.c
1 security/device_cgroup.c
1 sound/aoa
45 sound/core
17 sound/drivers
5 sound/i2c
35 sound/isa
1 sound/last.c
2 sound/oss
1 sound/parisc
117 sound/pci
7 sound/pcmcia
4 sound/ppc
1 sound/sh
20 sound/soc
1 sound/sound_core.c
7 sound/synth
12 sound/usb
1 tools/iio
6 tools/include
2 tools/lib
6 tools/perf
3 tools/power
3 tools/testing
4 tools/virtio
1 usr/gen_init_cpio.c
1 virt/kvmQuoted 6 lines · Danny Lin
Most of the other exceptions can be accomodated for with more specific rules below the base [*] section. I just went through most of the kernel's files and added rules for the vast majority of the exceptinos to the 8-column tab indent style, though there are still some that haven't been covered.
Very good! That looks much better.
Are there too many file types that use tabs? If not, then I think it is best to add a section for "General tab" files like for the others, in order to be explicit and to have the list around.
Quoted 8 lines
It looks like some types of files lack consistent indentation, e.g.
arch/mips/*/Platformand some shell scripts inscripts/tools/testing/selftests/ftrace/test.d/kprobe/*.tc. There are also some files that were highly inconsistent even within themselves (e.g.drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler_gfx*.asm), so setting indentation settings to something sane by default doesn't make them any worse. After all, no automated code style tooling is perfect and there will be edge cases where it breaks down.
Yeah, do not worry about inconsistencies. For .clang-format, I picked the options based on 1) whether there was an official code style guideline and 2) if not, the one that minimizes the number of changes, i.e. the most popular one across files.
Cheers,
Miguel