-
Notifications
You must be signed in to change notification settings - Fork 123
linenumbers for validation #736
Comments
i like that idea. |
I also thought about having a search for the line after-the-fact. But I think this would lead to poor results. When the parser does not support it, I am afraid you simply cannot get the feature in a way so that is reliable and useful. (You easily could get confused e.g. by multi-line comments) For quite some plugins, however, the line numbers could be added easily. (e.g. for tcl https://gist.github.com/sehe/1425972) Another question is if we use start line/end line or even start column/end column, too? |
Btw. as global validation plugin you even lose the information in which file an option was (and obviously also won't know which storage plugin was involved). A similar issue would also happen with a multi-file plugin resolver. So we should even add the file names during parsing (next to line information). The file name only takes a pointer for every key, so it should not matter much. The line-number information would be something about 50 byte per key (depending on how much information we add and how well @mpranj can optimize keyNew for meta-data). Ini already adds about 3 meta-keys per key, so you would not notice the overhead of the line information. For some other plugins that currently do not add any meta-data at all, an option to disable the adding conffile-based information might be useful: to not cause overhead for people who do not edit files directly anyway. |
@bauhaus93 maybe this can be realized in the new TOML plugin? Maybe the order can directly be the line number? @sanssecours any new thoughts on that? |
For JSON (and YAML flow style) that will not work, since more that one key can appear on the same line. For example the code ["one", "two"] mapped to the namespace
, where the line number of both the key
Storing the line number should not be that hard, although we have to consider that keys, can also span multiple lines. For example, if we map the following YAML code root:
level1:
level2:
value to the namespace [clients]
data = [ ["gamma", "delta"], [1, 2] ] maps to the key set:
, if we mount it directly at the namespace |
Thank you for the detailed explanation! |
Won't be implemented soon. |
Currently, when validation fails you know which key is the problematic one. This is enough for most use-cases (e.g. when working with tools such as kdb), but not ideal when directly working with configuration files.
In a7544a5 I propose that storage plugins can add the line numbers where they found each key. This meta data should be added to validation errors (if available).
The downsides are that it increases memory footprint and, again, needs changes to every storage plugin that wants to support it. (Most parsers do not have this information available at all, so for them it won't work anyway).
@sanssecours @tom-wa What do you think?
Btw. Elektra seems to be one of the few tool that properly supports validation of multiple files at once. @tom-wa can you search for others as related work? See also discussion here
The text was updated successfully, but these errors were encountered: