PowerShell / PowerShell/PSScriptAnalyzer

[RULE] PSScriptAnalyzerSettingsSchema

Open
#1,279 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area - Configuration Area - Engine Consider - 2.0 Issue - Enhancement
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

User Story

  • As a writer of PSScriptAnalyzer settings files
  • I want static code checking of the structure of PSScriptAnalyzer settings files
  • so that I can catch schematic violations early and easily.

Specification Details

The static schema for an Invoke-ScriptAnalyzer -Settings hashtable is not formally documented in a rigorous format at present. However, the current implementation implicitly adheres to the following as expressed using JSON Schema (with the exception of case-sensitivity):

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "title": "PSScriptAnalyzerSettings",
  "type": "object",
  "definitions": {
    "SeverityString": {
      "type": "string",
      "pattern": "Error|Warning|Information"
    },
    "stringOrStrings": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    }
  },
  "properties": {
    "CustomRulePath": {
      "$ref": "#/definitions/stringOrStrings"
    },
    "ExcludeRules": {
      "$ref": "#/definitions/stringOrStrings"
    },
    "IncludeDefaultRules": {
      "type": "boolean"
    },
    "IncludeRules": {
      "$ref": "#/definitions/stringOrStrings"
    },
    "RecurseCustomRulePath": {
      "type": "boolean"
    },
    "Rules": {
      "type": "object",
      "additionalProperties": {
        "type": "object"
      }
    },
    "Severity": {
      "oneOf": [
        {
          "$ref": "#/definitions/SeverityString"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SeverityString"
          }
        }
      ]
    }
  },
  "additionalProperties": false
}

The static schema of an Invoke-ScriptAnalyzer -Settings hashtable, as currently implemented and as expressed above (but with the addition of global case-insensitivity), shall serve as the specification for the proposed "PSScriptAnalyzerSettingsSchema" rule. Additional requirements are as follows:

  • The schema utilized by the "PSScriptAnalyzerSettingsSchema" rule MUST be enforced by the Invoke-ScriptAnalyzer command.
  • The implementation of the "PSScriptAnalyzerSettingsSchema" rule SHOULD share source code for validation logic with the Invoke-ScriptAnalyzer command in an appropriately modular fashion such that changes to the aforementioned schema's specification correspond one-to-one to changes in the source code.

PSScriptAnalyzer Version

The latest version of PSScriptAnalyzer as of this writing is 1.18.1.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Invoke-ScriptAnalyzer command and the proposed PSScriptAnalyzerSettingsSchema rule, then trace how settings are currently validated. Done means the specified case-insensitive schema is enforced by the command and the rule shares validation logic with it as required.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.