Skip to content

Code Quality

Marius Storhaug edited this page Nov 24, 2021 · 1 revision

CodeQualityMeasurement

To prevent bad code, align on coding practises and styles. As a developer you are responsible for your codes quality. Similar to other professionals, follow professional standards.

CodeQuality

Folder and file structure

  • PascalCase ?

VSCode - Generic settings

Our repos contains settings for VSCode (.vscode folder on root), automating our devs VSCode to follow the teams standards:

    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 10000,
    "explorer.compactFolders": false,
    "explorer.sortOrder": "filesFirst",

Powershell

  • PascalCase for variables and parameters.
  • Be verbose. Code should speak for itself, leading to less comments. Comments are lies waiting to happen.
  • Use verbose variable names. Spell it out, not just $a or $Obj, but $ProcessObjects or $ParameterFilePath
  • Don't use aliases in scripts, spell it out, again making the scripts verbose and 'self documenting'.
    • gps -> Get-Process
  • Always define the parameter you are using, not just going on position or type match. i.e:
    • Get-Process 'notepad' -> Get-Process -Name 'notepad'
  • Follow one Brace and indentation style: 'Kernighan and Ritchie' (K&R), also known as 'One True Bracing Style' (OTBS)

Our repos contains settings for VSCode (.vscode folder on root), automating our devs VSCode to follow the teams standards:

    "powershell.codeFormatting.autoCorrectAliases": true,
    "powershell.codeFormatting.newLineAfterCloseBrace": false,
    "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
    "powershell.codeFormatting.preset": "OTBS", // Stroustrup, Allman, OTBS. More info: https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/81
    "powershell.codeFormatting.trimWhitespaceAroundPipe": true,
    "powershell.codeFormatting.useConstantStrings": true,
    "powershell.codeFormatting.useCorrectCasing": true,
    "powershell.codeFormatting.whitespaceBetweenParameters": true,

More info:

JSON/ARM

Our repos contains settings for VSCode (.vscode folder on root), automating our devs VSCode to follow the teams standards:

  • Allow comments in JSON files, especially if there are references to GUIDs and other non-human readable references.
    "files.associations": {      // As ARM is written to support JSON,
        "*.json": "jsonc"        // comments will cause linting errors.
    },                           // This will make that no longer happen.

Clone this wiki locally