Message ID | SN4P221MB06823B0F7326D27ECD5E0FAEA0689@SN4P221MB0682.NAMP221.PROD.OUTLOOK.COM |
---|---|
State | Changes Requested |
Headers | show |
Series | support ignore-indent for check-package configs | expand |
Hello, Sorry the long delay. On Sat, Apr 29, 2023 at 03:12 PM, James Knight wrote: > from: James Knight <james.d.knight@live.com> > date: Sat, Apr 29 02:12 PM -04:00 2023 > to: buildroot@buildroot.org > cc: James Knight <james.d.knight@live.com>, Ricardo Martincoski <ricardo.martincoski@datacom.com.br> > subject: [Buildroot] [PATCH 3/4] utils/check-package: support ignore-indent flag for configurations > > This commit provides the ability for configuration scripts to hint at > ignoring linter checks for expected indentations. By adding the line to > a configuration file: > > # noqa: ignore-indent There is already support for comments in the form # check-package Indent to not run a CheckFunction named Indent for the next source code line It seems to me that using 'check-package' in the special comment does make sense because someone reading the source file, for instance a Config.in file, can immediately know it is something related to the check-package script, while a 'noqa' would need to be documented in the manual. Also, using 'check-package' in the comment would keep consistency with code that already exists. Finally, it seems to me more future-proof to keep the naming space of all flags/options inside each CheckFunction, so I would suggest a comment in the form: # check-package Indent_ignore-menu-indent-below that sets the flag named 'ignore-menu-indent-below' for the CheckFunction named 'Indent' in the library that parses the type of file that has the special comment, in the case of Config.in, lib_config.py. Regards, Ricardo
diff --git a/utils/checkpackagelib/lib_config.py b/utils/checkpackagelib/lib_config.py index 6e65eed66b490c6d477de67ff7589e9f05da4e28..52539d97ab60664d0466b42e28b3aac5577db5fb 100644 --- a/utils/checkpackagelib/lib_config.py +++ b/utils/checkpackagelib/lib_config.py @@ -224,6 +224,8 @@ class Indent(_CheckFunction): text] elif entry in entries_that_should_not_be_indented: if not text.startswith(entry): + if state and 'ignore-indent' in state.noqa_flags: + return # four Config.in files have a special but legitimate indentation rule if self.filename in ["package/Config.in", "package/Config.in.host", @@ -271,3 +273,19 @@ class RedefinedConfig(_CheckFunction): .format(self.filename, lineno, config, previous_line), text] self.configs[key] = lineno + + +class State: + def __init__(self): + self.noqa_flags = set() + + def process(self, line): + if not _empty_or_comment(line): + return + + # if `noqa:` token is detected, consider trailing options as noqa + # tokens assigned on the file + if "noqa:" in line: + flags = line.partition("noqa:")[2].lower().split() + if flags: + self.noqa_flags.update(flags)
This commit provides the ability for configuration scripts to hint at ignoring linter checks for expected indentations. By adding the line to a configuration file: # noqa: ignore-indent Calls to check-package will ignore any custom indentation the configuration script may have. This can be useful for "container" configurations which include packages or other sub-packages, without having to add explicit bypasses into the checkpackagelib library. This avoids maintaining special file lists inside `lib_config.py`, as well as allows br2-external tree to easily utilize the linter script without having to worry about indentation on container-like configuration definitions. Signed-off-by: James Knight <james.d.knight@live.com> --- utils/checkpackagelib/lib_config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)