Skip to content

v0.7.0

Latest

Choose a tag to compare

@github-actions github-actions released this 19 Oct 15:51
· 5 commits to main since this release
99e6a22

For consumers

-Detailed reports each unit's lines of code. Complexity says nothing about size -- a long
function of straight-line code scores 1 and 0 -- so -Detailed now adds LinesOfCode, counted
exactly as SonarQube counts ncloc: a physical line holding at least one character that is neither
whitespace nor part of a comment. A brace on its own line, each line of a continued statement and
the non-blank lines of a here-string count; blank lines, comments and comment-based help do not.
Each line belongs to the innermost unit, so a nested function's lines are not its parent's. It is
information only, with no threshold, and a run without -Detailed is unchanged. The JSON report
carries it for a -Detailed run, as an optional field of each unit.

The gate's policy can live in a committed .pscomplexity.json. Ceilings, per-path overrides,
excludes, acceptances with their reasons and the baseline file, in one place for CI and for a run by
hand. Test-PSComplexity takes -ConfigFile, or finds the nearest .pscomplexity.json from each
path up to the repository root -- never above it, and not at all outside a repository -- and
-NoConfig turns that off. The file used is printed and recorded in the JSON report as config,
beside scope.exclude, scope.excluded and thresholds.overrides. The command line wins wherever
it says something. A config that is not valid is refused, naming every fault, and its format ships
as schemas/v1/config.schema.json. Without a config nothing changes: the ceilings are still 15 and
15. Measure-PSComplexity reads no config.

An acceptance can be written in the code. A # PSCx-Accept: <reason> line comment directly
above a function, method or constructor excuses that unit, with exactly the checks -Accept has:
the gate fails when the unit is back within its ceilings or the reason is empty. The argument then
moves with the code instead of going stale in a File + Unit list. A declaration that excuses
nothing -- separated by a blank line, sharing a line with code, or above something that is not a
unit -- is refused rather than ignored, and so is a unit accepted both in its code and in a list.
Whole units only. The report's accepted entries now say where each argument is written, as
source (inline or list) and the line of an inline one.

A Markdown summary, for a CI step summary or a pull request comment. -MarkdownPath on both
commands writes the run as Markdown: the verdict and every unit over a ceiling (the gate), the ten
most complex units (-MarkdownTop changes the number), per-file totals, and what the numbers do not
cover. With -CompareTo and a previous JSON report it also lists the units that are new, worse or
better than in that report; a report from another metric version is refused. Rendered from the same
scan as the records and the JSON report, so it holds no number they do not.

Gate only the functions a change touched. -ChangedDiff on both commands takes a unified diff
-- git diff --unified=0 origin/main...HEAD -- and restricts the run to the units owning a changed
line, where -ChangedFile takes every unit in a touched file. A changed line belongs to the
innermost unit holding it, so editing a nested function does not drag in its parent; a pure deletion
belongs to the unit it was deleted from; a line outside every function belongs to the script body.
Only the +++ and @@ headers are read, and the module still runs no git. An empty diff, text that
is not a diff, a PowerShell file the diff names that is not there, and -ChangedFile beside it are
refused. Acceptances and baseline entries are still checked against every unit of the changed files.
The JSON report records the hunks as scope.changedLines.

A PSScriptAnalyzer rule, for warnings in the editor. The package now ships
rules/PSComplexity.Rules.psm1; point PSScriptAnalyzer's CustomRulePath at it and VS Code marks
each unit over its ceiling as you type. It uses the module's own scoring and the gate's verdict --
the .pscomplexity.json the file sits under or 15 and 15, per-path ceilings, excludes, acceptances
in the config and in the code, and the config's baseline -- so the editor and the gate cannot
disagree. It measures the editor's text, gives an unsaved buffer the defaults, warns on the first
line of the unit's declaration, and never refuses: stale policy stays the gate's to report.

Fixed

A run over the changed files no longer refuses policy for the files it did not read (#203). With
a baseline, or any acceptance, -ChangedFile threw that a unit "was not measured" for every entry
naming another file, so a repository using either could not gate a pull request on its changed
files. Such an entry is now left out of the checks and of the report's accepted; entries for the
files the run did read are checked as before. And -UpdateBaseline together with -ChangedFile is
refused: the update records what the run measured, and it silently dropped every baseline entry for
the rest of the tree.

What's Changed

  • ci: self-mutation on PSMutant 0.7.0 by @TaekeK in #196
  • feat: -Detailed reports each unit's lines of code, counted as SonarQube's ncloc (#166) by @TaekeK in #198
  • test: read Test-Json's verdict from its return value (#197) by @TaekeK in #199
  • feat: the gate's policy in a committed .pscomplexity.json (#164) by @TaekeK in #200
  • feat: accept a unit with a comment above its declaration (#165) by @TaekeK in #201
  • feat: a Markdown summary of the run, for step summaries and PR comments (#167) by @TaekeK in #202
  • fix: a -ChangedFile run checks policy only for the files it read (#203) by @TaekeK in #204
  • feat: gate only the units a diff changed, with -ChangedDiff (#168) by @TaekeK in #205
  • feat: a PSScriptAnalyzer rule, so the editor warns as the gate would (#163) by @TaekeK in #206
  • docs: the Pester failure blamed on PSMutant was a damaged install by @TaekeK in #207
  • ci: create the GitHub release once the gallery accepts the version by @TaekeK in #208
  • ci: bump github/codeql-action/upload-sarif from 4.38.3 to 4.39.0 by @dependabot[bot] in #209
  • ci: PowerShell compatibility legs to 7.4.21 and 7.5.12 by @TaekeK in #210
  • test: pin list separators and nested override paths by @TaekeK in #211
  • release: date PSComplexity 0.7.0 by @TaekeK in #212
  • ci: readable release notes on the gallery and the GitHub release by @TaekeK in #213

Full Changelog: v0.6.0...v0.7.0