jeremiah-c-leary / vhdl-style-guide

Style guide enforcement for VHDL
GNU General Public License v3.0
192 stars 39 forks source link

Options for merging config files #1184

Closed Benito-E closed 4 months ago

Benito-E commented 4 months ago

Something I noticed recently about how VSG uses multiple configuration files is how they overwrite each other. When I read that they did in the documentation, I understood it at face value, but in retrospect I didn't understand exactly to what extent that meant. Here's an example:

------------config1.json
{
    "rule" : {
        "group" : {
            "alignment" : {
                <alignment configs...>
            }
        }
    }
}
------------config2.json
{
    "rule" : {
        "group" : {
            "indent" : {
                <indent configs...>
            }
        }
    }
}

Part of my brain expected that since these files configured different things they could be put together. But when VSG reads these, it overwrites the entire group element with the last config to be loaded. So in this example if config2.json were loaded last, only config2.json configurations would be loaded.

As I said above, in retrospect I hadn't registered what 'overwrite' truly meant, and this is actually completely predictable behavior. But I was also wondering if there was a way that one might be able to mark certain json elements as "merge" instead of "overwrite". For example:

Disclaimer: I don't think I'm using proper json terminology, but hopefully the following still makes sense: A sort of pre-processor script could go through these files, parsing the data such that, after all configs are completely scanned, the information could be combined into a single large json file. While parsing, it would look for key elements marked with -- merge. When it found these (and the value of the key was a json object or list) it would only overwrite duplicate sub-keys (unless they too were marked with --merge. To clarify what I mean, if the following 2 json files were loaded in the order they're written, they'd be combined into the 3rd:

------------config1.json

{
    "rule" : {

        -- merge
        "group" : {
            "alignment" : {
                "key1" : "value 1"
                "key2" : {
                    "a" : "A",
                    "b" : "B"
                }
            }
        }
    }
}

------------config2.json

{
    "rule" : {

        -- merge
        "group" : {
            "alignment" : {
                "key1" : "new value 1"
                -- merge
                "key2" : {
                    "a" : "A",
                    "c" : "C"
                }
            },
            "indent" : {
                <indent configs>
            }
        }
    }
}

------------Combined.json

{
    "rule" : {

        "group" : {
            "alignment" : {
                "key1" : "new value 1"
                "key2" : {
                    "a" : "A",
                    "b" : "B"
                    "c" : "C"
                }
            },
            "indent" : {
                <indent configs>
            }
        }
    }
}

If config2.json was loaded before config1.json, then the resulting value of "key2" would be { "a" : "A" , "c" : "C" }

This could be implemented via a new command flag that routes the files its given to this preprocessor before sending the result to the list of configuration files.

However, This is another enhancement that can certainly be placed on the backburner and is more of an idea than anything else.

jeremiah-c-leary commented 4 months ago

Morning @Benito-E ,

The merging of configurations is one of those features that I probably should not have implemented. It worked well before indent, rule.group, and pragma were added. The difficulty in merging is knowing the final configuration that will be applied. The -oc option can be used to check the final configuration, but I just ran the command and output resulted in a file with 8425 lines.

Looking back, the merging of configurations should have been left to the user. The user would know better than VSG the best configuration, or group of configurations, to use.

So I must apologize, but I will not be implementing this issue.

Regards,

--Jeremy