diff mbox series

[v4,05/11] CODING-STYLE(tools/ocaml): add .editorconfig to clarify indentation uses spaces

Message ID bc7f3ab700525288938b84c9fbcc0f4ac6bd804c.1671214525.git.edwin.torok@cloud.com (mailing list archive)
State New, archived
Headers show
Series OCaml fixes | expand

Commit Message

Edwin Török Dec. 16, 2022, 6:25 p.m. UTC
Add an .editorconfig to make it easier to keep patches compatible with
Xen's coding style, and to reemphasize what Xen's coding style is.

I thought that Xen demands tabs rather than spaces (which is more
difficult with OCaml because indentation tools use spaces,
and the use of tabs requires changing editor settings),
however CODING-STYLE says it is spaces.

Document this explicitly by adding a .editorconfig file (see editorconfig.org),
which is an editor agnostic format for specifying basic style properties like
indentation, either with native support in editors or via plugins.

It is safer than modelines because it only supports controlling a
restricted set of editor properties and not arbitrary commands as Vim
modelines would have, and works with editors other than Vim too.
(Vim has a deny list for modeline sandboxing, which is error-prone
because every time a new command gets added it needs to be added to the
deny list, which has been the source of a few CVEs in the past
and I disable Vim modelines everywhere as a precaution).

This file is added as a convenience for those who might have an editor
that supports it, and its presence should have no impact on those that
do not (want to) use it.
It also won't cause re-indentation of existing files when edited, only
newly added lines would follow the convention.

No functional change.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Cc: Christian Lindig <christian.lindig@citrix.com>
---
 .editorconfig | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 .editorconfig

Comments

Christian Lindig Dec. 19, 2022, 9:59 a.m. UTC | #1
> On 16 Dec 2022, at 18:25, Edwin Török <edvin.torok@citrix.com> wrote:
> 
> Add an .editorconfig to make it easier to keep patches compatible with
> Xen's coding style, and to reemphasize what Xen's coding style is.
> 
> I thought that Xen demands tabs rather than spaces (which is more
> difficult with OCaml because indentation tools use spaces,
> and the use of tabs requires changing editor settings),
> however CODING-STYLE says it is spaces.
> 
> Document this explicitly by adding a .editorconfig file (see editorconfig.org),
> which is an editor agnostic format for specifying basic style properties like
> indentation, either with native support in editors or via plugins.
> 
> It is safer than modelines because it only supports controlling a
> restricted set of editor properties and not arbitrary commands as Vim
> modelines would have, and works with editors other than Vim too.
> (Vim has a deny list for modeline sandboxing, which is error-prone
> because every time a new command gets added it needs to be added to the
> deny list, which has been the source of a few CVEs in the past
> and I disable Vim modelines everywhere as a precaution).
> 
> This file is added as a convenience for those who might have an editor
> that supports it, and its presence should have no impact on those that
> do not (want to) use it.
> It also won't cause re-indentation of existing files when edited, only
> newly added lines would follow the convention.
> 
> No functional change.
> 
> Signed-off-by: Edwin Török <edvin.torok@citrix.com>
> Cc: Christian Lindig <christian.lindig@citrix.com>

Acked-by: Christian Lindig <christian.lindig@citrix.com>

I am agnostic about this change. Automatic code formatting should take care of this but I see no harm including this file. The number of developers contributing to the OCaml code base is minuscule and we should try to keep barriers as low as possible. The wrangling about all these minutiae is already too much.

- C
diff mbox series

Patch

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000000..cb2f27c581
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,20 @@ 
+# See ./CODING_STYLE
+root = true
+
+[*]
+end_of_line = lf
+indent_style = space
+charset = utf-8
+max_line_length = 79
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+# Makefiles must use tabs, otherwise they don't work
+[{Makefile,*.mk,Makefile.rules}]
+indent_style = tabs
+
+[*.{c,h}]
+indent_size = 4
+
+[*.{ml,mli}]
+indent_size = 2