FinOps++ Style Guide
Style can mean a lot. It may provide a sense of structure, can act as a mark of quality, enable understanding for new user, or even aid in recognition of a project. In may ways, style is the beating heart of the FinOps++ streaming from the desire to produce exactly these outcomes.
To help with this, when designing the structure of the Assessments project, we looked closely at how to provide a style scaffolding via time-tested specifications and popular linters.
Linting
It is strongly recommended to use pylint for linting for python code. While yamllint is recommended for the YAML components specifications. And pymarkdownlnt (also called pymarkdown for short) can be used to spot check the Markdown documentation.
There are built-in configuration files for these in the top-level directory of this project that will help make sure your code is compliant with the project’s standards. These packages can be pretty easily installed in CLI Tool with the following modification to the pip install command python -m pip install -e ".[validation]".
[!CAUTION] There is an older and unaffiliated (and unmaintained) package called
pymarkdown. For security reasons, make sure to not download this version by installing specificallypymarkdownlntif you choose to install the dependencies separately into your environment.
CSpell (optional)
One other Linter that we run against your code on pull-requests is cspell. This is actually a Node.js based CLI tool that provides a basic means to spell check the project. As configured in .cspell.config.yaml, this is used as a glorified typo finder. So, between this and the fact that CSpell doesn’t use Python, we won’t require users to download an run this. But any failures found during the analysis of the pull request will need to be fixed.
[!TIP] For those that do want to go above and beyond, feel free to follow along with the CSpell Installation instructions from cspell to get the tool up-and-running.
Dictionaries
CSpell makes use of a number of default dictionaries for sourcing words. Largely these are based on common tech industry terms, but can run behind words used in FinOps. It is suggested, if you find a FinOps word that does not exist, or you think might not exist, to just add it to the words section of the .cspell.config.yaml
[!IMPORTANT] While CSpell does have a default dictionary for both US and Great Britian spelling, it seems to favor the US version for word spelling. To help avoid random issues with this, it is suggested that you favor the US spelling of words as well.
YAML
This project makes use of the YAML specification v1.2.2 for all files with the .yaml extension. That largely includes the action, capability, domain, and profile component specifications that are used generate other core pieces of FinOps++ such as the Markdown components.
Differences from the standard specification used for FinOps++ can be found in the yamllint configuration file .yamllint. The biggest change being that FinOps++ makes uses of 2 spaces for indentation rather than 4. This was chosen on purpose to help readability when it comes to nesting used by the component specifications.
YAML - Line to long error
One of the most common issues you will see with the yaml specifications is when you have a line that is too long. We along up to 120 characters, but sometimes this might not be enough to fit in everything you want or need to say. In this situtation, after figuring out the word before the 120-cutoff, you have two options to solve this problem:
- Just press enter - This is sort of a dangerous option as the enter will create a newline that might not be preserved when the specification is used to generate markdown. Leading, potentially, to the line running afoul of the markdown linter with a similar length requirement. But can be useful when already paired with option two.
- Use the “literal style” indicator - This is the special yaml character
|that allows you to covert a block of text into what YAML calls its’ literal style. In this style, line lines are always preserved. This is true even in markdown generated by this style.
Markdown
Largely, this project work around the GitHub Flavored Markdown, but should generally also work well with the CommonMark. Files that are governed by these specifications largely have the .html extension, there there are some exceptions such as the files found under guidelines/ or the project’s base index.html.
Even when these specifications are enforce, there are some difference related to handling of HTML elements when creating nested tables for the framework markdowns. Additionally, we also along line-lengths of 120 characters rather than the typical length of 80. But generally we try to keep as close as possible to these specifications. These (hopefully) minimal changes can be found in the pymarkdownlnt configuration file .pymarkdown.
MD - Line to long error
This should hopefully be generally, pretty rare. But when it does happen, it is largely going to be a function of the specification line being over the limit. The easiest fix is to go back to the YAML specification and to use option 2. from YAML - Line to long error.
Python
All python modules and code with the .py extension generally hold to the PEP 8 standard. Deviations generally are around things like line-length, where much like the Markdown change, we allow 120 character lines. We also use PascalCase for local variables rather than the standard UPPER_CASE format.
The full list of changes (honestly, the full list of configuration even including basic defaults) can be found in .pylintrc. This might be a bit hard to read, and if you are really interested in seeing the differences, would suggest running pylint --generate-rcfile > .pylintrc2 in another directory and compare the differences using a tool like diff in *nix like environments or something like Compare-Object in PowerShell.