Skip to content

Commit

Permalink
mformat: correctly handle editorconfig files without the root setting
Browse files Browse the repository at this point in the history
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: mesonbuild#13568
  • Loading branch information
dcbaker committed Aug 19, 2024
1 parent cdf646f commit d3e284d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mesonbuild/mformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test cases/format/3 editorconfig/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test cases/format/3 editorconfig/subdir/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*]
max_line_length = 120
3 changes: 3 additions & 0 deletions test cases/format/3 editorconfig/subdir/sub.meson
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit d3e284d

Please sign in to comment.