From 18f4a058bf7e4b7eb32553b10fe3a37e1c22aa15 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 19 Aug 2024 14:18:04 -0700 Subject: [PATCH] mformat: correctly handle editorconfig files without the root setting Which happens when a .editorconfig is in a subdirectory, not the root. In this case we need Set the fallback value to `False`, which is what editorconfig expects. Closes: #13568 --- mesonbuild/mformat.py | 3 ++- test cases/format/3 editorconfig/meson.build | 1 + test cases/format/3 editorconfig/subdir/.editorconfig | 2 ++ test cases/format/3 editorconfig/subdir/sub.meson | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test cases/format/3 editorconfig/subdir/.editorconfig create mode 100644 test cases/format/3 editorconfig/subdir/sub.meson diff --git a/mesonbuild/mformat.py b/mesonbuild/mformat.py index bb93f47ef50c..2e403016811c 100644 --- a/mesonbuild/mformat.py +++ b/mesonbuild/mformat.py @@ -823,7 +823,8 @@ def load_editor_config(self, source_file: Path) -> EditorConfig: if value is not None: setattr(config, f.name, value) - if cp.getboolean(cp.default_section, 'root'): + # Root is not required except in the top level .editorconfig. + if cp.getboolean(cp.default_section, 'root', fallback=False): break return config diff --git a/test cases/format/3 editorconfig/meson.build b/test cases/format/3 editorconfig/meson.build index b32974cb9e8e..2468411493c3 100644 --- a/test cases/format/3 editorconfig/meson.build +++ b/test cases/format/3 editorconfig/meson.build @@ -7,6 +7,7 @@ meson_files = { 'self': files('meson.build'), 'comments': files('crazy_comments.meson'), 'indentation': files('indentation.meson'), + 'subdir editorconfig': files('subdir/sub.meson'), } foreach name, f : meson_files diff --git a/test cases/format/3 editorconfig/subdir/.editorconfig b/test cases/format/3 editorconfig/subdir/.editorconfig new file mode 100644 index 000000000000..fac7a92caaba --- /dev/null +++ b/test cases/format/3 editorconfig/subdir/.editorconfig @@ -0,0 +1,2 @@ +[*] +max_line_length = 120 diff --git a/test cases/format/3 editorconfig/subdir/sub.meson b/test cases/format/3 editorconfig/subdir/sub.meson new file mode 100644 index 000000000000..623ca2836a9c --- /dev/null +++ b/test cases/format/3 editorconfig/subdir/sub.meson @@ -0,0 +1,3 @@ +project('line') + +msg = 'this is a very long line, and it should be be wrapped because we have line length limit of 120, not 60'