Spin-off from Important security update
I've been thinking about how to "lint" RouterOS for a while. I already build RouterOS LSP, and have Rosetta MCP for AI. While these tools can "check" if a config is "valid" or has errors, and AI more easily find RouterOS fact from Rosetta... Nothing in my toolchain actually did any meaningful analysis of a configuration, which is important if you want to "surface" important configuration details. My general focus has been on offering "help" (for example linking docs to some hover in VSCode with a config). But the recent discussions highlight that some security-related and likely "config mistakes" also depend on deconstructing config to "cananocialize" into a normalized form that allow lookup/checks on the various path/cmd/attributes. In other words, some "abstract syntax tree" (AST) suggested by @Kenzo a couple years ago:
I've loosely been working on this as part of:
Which essentially designed as a library that has a CLI that matches the library, with the idea that it "safely" executes/fetches RouterOS things, including multiple to run a command against a set of routers (defined in centrs by CDB file's groups, which centrs uses to store creds).
But the "safely" part is tricky... So a critical part of tikoci/centrs is centrs explain which essentially builds an AST... since things like determining if a command "writes" before trying it is useful (and centrs has a option so read-only mode so even if account allowed write, centrs could still block itself).
explain is actually near a more completed state. The clunkers tell me the offline parsing understands 67% of syntax. And the AST generator inside explain is "scored" against a large collection of @rextended, @eworm, @tangent public scripts measured on live router to compare our offline parser... which is how I know what % is ~done. I have not measure the parser WITH a connected router, but the AST generation only get more complete, since with a real router, the syntax can be exactly checked to know if it valid (and router has needed package/architecture/etc).
But this is plumbing needed for some of the suggestions from the discussion in "Important security update", start with:
And already been at that for a while, so the centrs work is essentially the core idea suggested here:
... since I use the LLM to generate the code needed to static/offline/non-AI RouterOS anylsis. So that no LLM is needed to "lint" RouterOS configs... And if you do use AI, then the LLM can help more with by starting with linting and AST-like information.
Now one part I have not looked at as much — thus this post — is "linting rules"... So like ask for help for what some potential rule sets look like... with the idea you can run centrs (or some future tool that uses centrs' AST) on your own computer without AI. My thought is to essentially create a RouterOS version of biome linter for JS/TS/CSS/etc, https://biomejs.dev as a layer above the centrs explain (which provide the facts needed to then check against some set of rules).
Which is essential core idea from @optio's post:
For example, one potentially "@rextended approved" rule might be
style/no-unnecesary-semicolons - warn if semi-colons are used when not needed
which use
centrs explainAST to look for semi-colons at the end of RouterOS script line... but you need the AST since some multiline KV arrays do need semi-colons since they are an array separator not command separator....
But the whole security patch discussion got me thinking perhaps some more security focus "linting" checks might be good. While I could eventually come up with some set, if folks has some suggested rules — both ones that could be checked against a parsed config file using more conditional logic, and ideally phased like biome things with some no-XXX / use-XXX. Like some theoritical security/use-https and security/no-unsecure-http that check www/www-ssl config, etc., and like biome offer a fix/suggestion to enable /ip/cloud+/certification/enable-ssl-certificate. In this example, it actually flag the default configuration.
With the idea being some are opinions and possible rules do conflict... and someone using my linter config disable/enable sets of rules (perhaps organized as set for "switch"/"home"/"ISP") etc.
Anyway I'm still working on the core code for AST... but thought some discussion of possible "linting rules" (which could feed into any kinda "config scoring" we want to conceive). So if folks have suggests on potentials rules or even better how to structure rules so they are usable, please comment below.