diff options
| author | Charles Brunet <charles.brunet@optelgroup.com> | 2024-08-20 17:09:57 -0400 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2024-09-06 14:14:44 -0400 |
| commit | d3ef02b2e4d312ac604c0045ec97bf35a121bab5 (patch) | |
| tree | cd4ad7d5a136022efa6009cbc93b8179cfe88d76 /mesonbuild/mformat.py | |
| parent | ce1602c1ee573f98ab409bcc645d9c7a07925836 (diff) | |
| download | meson-d3ef02b2e4d312ac604c0045ec97bf35a121bab5.tar.gz | |
mformat: detect invalid config
- detect unknown config keys in format config
- add test for detection of invalid config values
- detect invalid .editorconfig values
Fixes #13569
Diffstat (limited to 'mesonbuild/mformat.py')
| -rw-r--r-- | mesonbuild/mformat.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/mesonbuild/mformat.py b/mesonbuild/mformat.py index 6a28684d6..d87674bc7 100644 --- a/mesonbuild/mformat.py +++ b/mesonbuild/mformat.py @@ -839,7 +839,10 @@ class Formatter: getter = f.metadata['getter'] for section in sections: - value = getter(cp, section, f.name, fallback=None) + try: + value = getter(cp, section, f.name, fallback=None) + except ValueError as e: + raise MesonException(f'Invalid type for key "{f.name}" in "{editorconfig_file}" file:\n{e}') from e if value is not None: setattr(config, f.name, value) @@ -858,6 +861,10 @@ class Formatter: except ParsingError as e: raise MesonException(f'Unable to parse configuration file "{configuration_file}":\n{e}') from e + extra_keys = sorted(set(cp.defaults()).difference(f.name for f in fields(config))) + if extra_keys: + raise MesonException(f'Unknown config keys: "{", ".join(extra_keys)}" in configuration file "{configuration_file}"') + for f in fields(config): getter = f.metadata['getter'] try: @@ -992,9 +999,8 @@ def run(options: argparse.Namespace) -> int: # TODO: remove empty newlines when more than N (2...) # TODO: magic comment to prevent formatting -# TODO: handle meson.options ? # TODO: split long lines on binary operators -# TODO: align series of assignements +# TODO: align series of assignments # TODO: align comments # TODO: move comments on long lines |
