IKE Code Quality checker

Best practices are important. Having some amount of consistency in the code base makes it more readable and easier to update.


However, when a script has a lot of problems concerning best practices we could lose what's really important: The script logic


Enter the Indeni script parser. Open it, paste your script and see if you missed anything in terms of best practices:


Image title



I believe this will keep our PR's much more clean and our poor IKE new-comers less devastated from what to the uninitiated might seem like petty remarks.


It currently has checks for the META section, the COMMENTS section and the AWK parser. It's not perfect, it does not check everything, but it's something. Test it here:


http://loadbalancing.se/indeni/indeni.html


The parse functions are templated (a bit like the indeni Scala rules) so adding a new one is quite simple. Just add a function to the function array at the top of the script:


Image title


The new function must have this.testName, this.reason, this.severity ("error" or "warning"), this.applyToSections (could contain "yaml", "awk", "meta" or "comments" right now, but it's easy to add support for more).


Then to the logic. The mark function is where the magic happens. It takes the string of a section and returns marked segments. How you choose to to the marking is up to you but I'd advise looking at the other examples and copy in the beginning.


Notes:


  • You have to paste a full script for it to work.
  • It updates as you type, so you can literally see all your troubles go away. :)
  • Please note that the checks are based on what I think it good practice, but many people might disagree on some of these things. If you do, please do let me know and we can discuss it here.


Want to contribute? Clone it on Github and submit a pull request:

https://github.com/epacke/indeni-enhancements


Feedback most welcome.


/Patrik


Wow Patrik this is really cool!! We are working on building a script editor directly into the Indeni UI and this kind of functionality can be amazing in there.

Image title


Now supports some checks for json and xml too. Will stop here for now. Let's see it it improves the PR's. :)

Some updates:


* Hawkeye fixed a bug regarding space after comma and updated the project with a test framework.

* I also fixed bugs regarding metric extractions (support more awk metric writing functions)

* Writing the same metric more than once is now a recommendation (thanks Vasilis for the suggestion)


Hawkeye made a release yesterday:
There’s now grammar where the was none before and also less Swedish language influences. :slight_smile:

I’ll keep this post alive.
There is now a plugin for Visual Studio Code that implements these checks if anyone is interested.

A question, do we care about line endings? Since Patriks script is copy-n-paste the line ending issue has never been raised. I see alot of variants(ok… really just two) with CRLF vs simple LF.
I’ve implemented an error for CRLF recommending LF instead. Right or wrong?

If you’re interested you can find it @ https://github.com/epacke/Indeni-CodeQual/tree/master/vscode. Look for the latest .vsix file which you can use to install it into vs code. And don’t be shy about telling me that you’re using it, and post bugs of course!

1 Like

Thanks so much for creating this plugin, Joakim, it is awesome.

Regarding the LF/CRLF question. I guess I didn’t quite understand when you mentioned it on slack. It’s a nice idea, but I don’t think we should enforce this in CodeQual, on the web page, or in the new vscode plugin. There’s no reason to force Windows users to use LF locally – git can handle the CRLF->LF conversion (and back) behind the scenes. The way to do this these days is with a .gitattributes file, which we should have.

You can also always explicitly set core.autocrlf on your git client:

https://help.github.com/articles/dealing-with-line-endings/#platform-all

Alright, no problem. It will be disabled in the next release. Thank you!

Alright, so I just published it to Microsoft Marketplace which means you can install it by just searching for the extension “indeni_codequal” and click install

Super nice Joakim! This will be really handy!