editorconfig: add consistent formatting rules for LTP
PATCH v2 1/1 editorconfig: add consistent formatting rules for LTP
Introduce .editorconfig to keep indentation and whitespace consistent across editors, preventing accidental reformatting and noisy diffs.
---
Changes since v1 (thanks Petr):
- License identifier: GPL-2.0 -> GPL-2.0-or-later
- Drop awk
- Treat Python/Perl special files
- indent_size=4 for *.{c,h,S,sh} and ver_linux
- Fix indent_size for .rst/.md to 4
.editorconfig | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .editorconfig
.editorconfig new file +39 -0
@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +root = true + +# Default for all files +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +# C/Assembly source files, headers, and shell files use tabs +[{*.{c,h,S,sh},ver_linux}] +indent_style = tab +indent_size = 4 + +[{Makefile,Makefile.*,*.{mk.in,mk}}] +indent_style = tab +indent_size = 8 + +# Python and Perl: default to tabs (most test files use tabs, checkpatch.pl which we modify) +[*.{py,pl}] +indent_style = tab +indent_size = 8 + +# Exceptions use spaces: Python (Sphinx, scripts), Perl (checkbashisms.pl vendored) +[{doc/conf.py,scripts/*.py,scripts/checkbashisms.pl}] +indent_style = space +indent_size = 4 + +# Documentation files +[*.{rst,md}] +indent_style = space +indent_size = 4 + +# JSON files +[*.json] +indent_style = space +indent_size = 4
--
2.53.0
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Jan,
Quoted 4 lines
# C/Assembly source files, headers, and shell files use tabs [{*.{c,h,S,sh},ver_linux}]
indent_style= tabindent_size= 4
LTP follows Linux kernel coding style, which uses 8-character-wide tabs. This should be indent_size = 8.
Quoted 4 lines
# Python and Perl: default to tabs (most test files use tabs, checkpatch.pl which we modify) [*.{py,pl}]
indent_style= tabindent_size= 8
Not 100% sure about this.
The Python test files in the tree (e.g. pm_sched_domain.py, pm_ilb_test.py) all use 4-space indentation, not tabs. The default for *.py should be indent_style = space / indent_size = 4. Perl (checkpatch.pl) does use tabs, so it should get its own section.
Also kirk uses 4 tabs indentation. So I guess we need to invert the two rules at this point.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 9 lines
Hi Jan,
Quoted 4 lines
# C/Assembly source files, headers, and shell files use tabs [{*.{c,h,S,sh},ver_linux}]
indent_style= tabindent_size= 4LTP follows Linux kernel coding style, which uses 8-character-wide tabs. This should be
indent_size= 8.
FYI I asked for 4 in v1 [1], Jan had originally 8 and I'm ok with following kernel. It's just my personal preference to display tab as 4 spaces and not 8 (IMHO editorconfig plugins don't allow certain setup to be overwritten).
Kind regards,
Petr
[1] https://lore.kernel.org/ltp/20260310132227.GC39882@pevik/
Quoted 16 lines
Quoted 4 lines
# Python and Perl: default to tabs (most test files use tabs, checkpatch.pl which we modify) [*.{py,pl}]
indent_style= tabindent_size= 8Not 100% sure about this.
The Python test files in the tree (e.g.
pm_sched_domain.py,pm_ilb_test.py) all use 4-space indentation, not tabs. The default for *.py should beindent_style= space /indent_size= 4. Perl (checkpatch.pl) does use tabs, so it should get its own section.Also kirk uses 4 tabs indentation. So I guess we need to invert the two rules at this point.
Regards,
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Petr,
Quoted 3 lines
FYI I asked for 4 in v1 [1], Jan had originally 8 and I'm ok with following kernel. It's just my personal preference to display tab as 4 spaces and not 8 (IMHO editorconfig plugins don't allow certain setup to be overwritten).
Sorry I missed that. I'm just wondering if editor configuration is applied only for visualization or also for typing. If it's applied for typing then we can't use 4 chars, otherwise we will have many issues with checkpatch.pl when verifying the source code.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 10 lines
Hi Petr,
Quoted 3 lines
FYI I asked for 4 in v1 [1], Jan had originally 8 and I'm ok with following kernel. It's just my personal preference to display tab as 4 spaces and not 8 (IMHO editorconfig plugins don't allow certain setup to be overwritten).
Sorry I missed that. I'm just wondering if editor configuration is applied only for visualization or also for typing. If it's applied for typing then we can't use 4 chars, otherwise we will have many issues with checkpatch.pl when verifying the source code.
To be honest I don't know (I haven't installed the plugin for my editor yet). But I'd suspect that on indent_style = tab it just adds a tab and indent_size = 8 is only the representation.
https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_size
Indentation Size (in single-spaced characters)
Possible Values
an integer
tab
If indent_size equals to tab, the indent_size will be set to the tab size, which should be tab_width if tab_width is specified, or the tab size set by editor if tab_width is not specified.
I wonder if it worked for us to set indent_size = unset for all indent_style = tab (of course not for indent_style = space).
For any property, a value of unset is to remove the effect of that property, even if it has been set before. For example, add indent_size = unset to undefine indent_size property (and use editor default).
@Jan?
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 33 lines · Petr Vorel
Quoted 10 lines
Hi Petr,
Quoted 3 lines
FYI I asked for 4 in v1 [1], Jan had originally 8 and I'm ok with following kernel. It's just my personal preference to display tab as 4 spaces and not 8 (IMHO editorconfig plugins don't allow certain setup to be overwritten).
Sorry I missed that. I'm just wondering if editor configuration is applied only for visualization or also for typing. If it's applied for typing then we can't use 4 chars, otherwise we will have many issues with checkpatch.pl when verifying the source code.
To be honest I don't know (I haven't installed the plugin for my editor yet). But I'd suspect that on
indent_style= tab it just adds a tab andindent_size= 8 is only the representation.https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_size
Indentation Size (in single-spaced characters)
Possible Values
an integer
tabIf
indent_sizeequals to tab, theindent_sizewill be set to the tab size, which should betab_widthiftab_widthis specified, or the tab size set by editor iftab_widthis not specified.I wonder if it worked for us to set
indent_size= unset for allindent_style= tab (of course not forindent_style= space).
Quoted 8 lines
For any property, a value of unset is to remove the effect of that property, even if it has been set before. For example, add
indent_size= unset to undefineindent_sizeproperty (and use editor default).@Jan?
Kind regards,
Petr
Hi Petr,
Good catch, the EditorConfig wiki is explicit here:
- indent_size can be an integer or tab.
- If indent_size = tab, then indent_size becomes the tab size:
tab_width if set, otherwise the editor’s default tab size.
- Any property can be set to unset to remove its effect (so the editor default is used).
So yes: we could do indent_style = tab together with indent_size = unset if the goal is “tabs, but don’t prescribe a width”.
If we want consistent visual width/alignment across editors, a more explicit setup would be indent_size = tab plus tab_width = 8.
Kind regards,
Jan
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 52 lines · Petr Vorel
Quoted 33 lines
Quoted 10 lines
Hi Petr,
Quoted 3 lines
FYI I asked for 4 in v1 [1], Jan had originally 8 and I'm ok with following kernel. It's just my personal preference to display tab as 4 spaces and not 8 (IMHO editorconfig plugins don't allow certain setup to be overwritten).
Sorry I missed that. I'm just wondering if editor configuration is applied only for visualization or also for typing. If it's applied for typing then we can't use 4 chars, otherwise we will have many issues with checkpatch.pl when verifying the source code.
To be honest I don't know (I haven't installed the plugin for my editor yet). But I'd suspect that on
indent_style= tab it just adds a tab andindent_size= 8 is only the representation.https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_size
Indentation Size (in single-spaced characters)
Possible Values
an integer
tabIf
indent_sizeequals to tab, theindent_sizewill be set to the tab size, which should betab_widthiftab_widthis specified, or the tab size set by editor iftab_widthis not specified.I wonder if it worked for us to set
indent_size= unset for allindent_style= tab (of course not forindent_style= space).Quoted 8 lines
For any property, a value of unset is to remove the effect of that property, even if it has been set before. For example, add
indent_size= unset to undefineindent_sizeproperty (and use editor default).@Jan?
Kind regards,
PetrHi Petr,
Good catch, the EditorConfig wiki is explicit here:
-
indent_sizecan be an integer or tab.
- Ifindent_size= tab, thenindent_sizebecomes the tab size:
tab_widthif set, otherwise the editor’s default tab size.
- Any property can be set to unset to remove its effect (so the editor default is used).
Quoted 5 lines
So yes: we could do
indent_style= tab together withindent_size= unset if the goal is “tabs, but don’t prescribe a width”.
If we want consistent visual width/alignment across editors, a more explicit setup would beindent_size= tab plustab_width= 8.
Hopefully all editors have meaningful default therefore I'd be for not setting it. But not a strong requirement if others want to have it specified.
Kind regards,
Petr
Quoted 2 lines
Kind regards,
Jan
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
...
Quoted 7 lines
Quoted 4 lines
# Python and Perl: default to tabs (most test files use tabs, checkpatch.pl which we modify) [*.{py,pl}]
indent_style= tabindent_size= 8Not 100% sure about this.
Quoted 7 lines
The Python test files in the tree (e.g.
pm_sched_domain.py,pm_ilb_test.py) all use 4-space indentation, not tabs. The default for *.py should beindent_style= space /indent_size= 4. Perl (checkpatch.pl) does use tabs, so it should get its own section.Also kirk uses 4 tabs indentation. So I guess we need to invert the two rules at this point.
Would it work if kirk has it's own .editorconfig? I mean, it should have anyway, but if it will be applied on it as a submodule.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 13 lines · Petr Vorel
...
Quoted 11 lines
Quoted 4 lines
# Python and Perl: default to tabs (most test files use tabs, checkpatch.pl which we modify) [*.{py,pl}]
indent_style= tabindent_size= 8Not 100% sure about this.
The Python test files in the tree (e.g.
pm_sched_domain.py,pm_ilb_test.py) all use 4-space indentation, not tabs. The default for *.py should beindent_style= space /indent_size= 4. Perl (checkpatch.pl) does use tabs, so it should get its own section.
Quoted 8 lines
Quoted 2 lines
Also kirk uses 4 tabs indentation. So I guess we need to invert the two rules at this point.
Would it work if kirk has it's own .editorconfig? I mean, it should have anyway, but if it will be applied on it as a submodule.
Kind regards,
Petr
Hi Petr,
In upstream LTP, kirk is actually included as a git submodule at tools/kirk (see .gitmodules), so having kirk carry its own .editorconfig is a natural fit.
EditorConfig is directory-hierarchical: editors look for .editorconfig files from the file’s directory upwards, and the closest matching settings override parent ones. If kirk’s .editorconfig sets root = true, the lookup stops at the submodule root, so LTP’s top-level rules won’t affect files inside tools/kirk.
Alternatively, if one prefer a single policy file, one could keep everything in LTP’s top-level .editorconfig and add a dedicated override section like [tools/kirk/**].
Kind regards,
Jan
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
...
Quoted 11 lines
Quoted 5 lines
Would it work if kirk has it's own .editorconfig? I mean, it should have anyway, but if it will be applied on it as a submodule.
Kind regards,
PetrHi Petr,
In upstream LTP, kirk is actually included as a git submodule at
tools/kirk(see.gitmodules), so having kirk carry its own.editorconfigis a natural fit.
Quoted 5 lines
EditorConfig is directory-hierarchical: editors look for
.editorconfigfiles from the file’s directory upwards, and the closest matching settings override parent ones. If kirk’s.editorconfigsetsroot = true, the lookup stops at the submodule root, so LTP’s top-level rules won’t affect files insidetools/kirk.
+1 (this was my question), thanks for info. Hopefully this is widely supported feature (I haven't found it on the wiki).
Quoted 3 lines
Alternatively, if one prefer a single policy file, one could keep everything in LTP’s top-level
.editorconfigand add a dedicated override section like[tools/kirk/**].
Thanks for info. That would not work because the primary development is in kirk repo, let's have the config there.
Kind regards,
Petr
Quoted 2 lines
Kind regards,
Jan
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 2 lines
Would it work if kirk has it's own .editorconfig? I mean, it should have anyway, but if it will be applied on it as a submodule.
There's no need, everything is handled by ruff that is auto-formatting and cleaning up python code. Its configuration is in pyproject.toml and it's de-facto standard for python development nowadays.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 11 lines · Andrea Cervesato
Quoted 2 lines
Would it work if kirk has it's own .editorconfig? I mean, it should have anyway, but if it will be applied on it as a submodule.
There's no need, everything is handled by
ruffthat is auto-formatting and cleaning up python code. Its configuration is inpyproject.tomland it's de-facto standard for python development nowadays.--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Hi Andrea, hi Petr,
thanks for the review!
I’m sending v3 addressing the comments:
Changes since v2:
- Use kernel-style tabs for C/ASM/shell (tab stop 8 via tab_width=8, indent_size=tab). (thx Andrea Cervesato, Petr Vorel)
- Split Python/Perl indentation: *.py uses 4 spaces; *.pl keeps tabs. (thx Andrea Cervesato)
Best regards,
Jan
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp