Skip to content

Add new InvalidMultiDotValue rule#2180

Open
iRon7 wants to merge 4 commits intoPowerShell:mainfrom
iRon7:#1698InvalidVersionConstruction
Open

Add new InvalidMultiDotValue rule#2180
iRon7 wants to merge 4 commits intoPowerShell:mainfrom
iRon7:#1698InvalidVersionConstruction

Conversation

@iRon7
Copy link
Copy Markdown

@iRon7 iRon7 commented Apr 28, 2026

PR Summary

Issue: #1698

PowerShell does not support an implicit value with multiple dots.
Any unquoted value with 2 or more dots will not be treated as any special type (like a version or IPAddress)
but result in $null. These objects need to be constructed from either a quoted string (e.g. [Version]'1.2.3')
or their individual components (e.g. [Version]::new(1, 2, 3)).

This rule returns an Error for unquoted values that have 2 or more dots (e.g.: $version = [Version]1.2.3).
And implements a -Fix to surround the concerned violation with single quotes.

PR Checklist

@liamjpeters
Copy link
Copy Markdown
Contributor

👋

Looks useful, thanks!

The naming of this rule is a little awkward. It's listed as InvalidVersionConstruction in the markdown doc, so I guess you renamed it at some point? Naming things is hard! Perhaps something like InvalidDottedValue or InvalidDottedLiteral as a suggestion? I don't know though 🤷 - I'm bad at naming things - I just know the current name looks off.

This rule has a severity of Warning but is emitting a diagnostic of Error severity. Where this is the only diagnostic that your rule emits, these should match. Not sure which is more appropriate here - I can't think of a case where you'd want the unquoted dotted literal intentionally so maybe Error is correct?

In your tests, you have 2 Context blocks with the same Supressed name.

You are using the temp folder in some of your testing; I'd suggest looking into and using Pester's Test Drive for temporary file usage during tests. It helpfully takes care of relevant cleanup for you too at the right time.

I don't think the CompilerServices import is intended?

This has the same copy-pasta as your other PRs.

@iRon7 iRon7 changed the title Add new InvalidMultiDotValue rule WIP: Add new InvalidMultiDotValue rule Apr 28, 2026
@iRon7
Copy link
Copy Markdown
Author

iRon7 commented Apr 28, 2026

I am trying to be precise but it is amazing how many issues you still find in PRs.
It is the end of the day for me, but I will pick them up tomorrow and respond/act accordingly.
Again, thanks for your feedback!

@iRon7
Copy link
Copy Markdown
Author

iRon7 commented Apr 29, 2026

@liamjpeters,

It's listed as InvalidVersionConstruction in the markdown doc

Fixed, although I have kept the questionable name InvalidMultiDotValue name (as I would like to avoid that I forget to update a reference again) until somebody comes up with a accurate name that better covers the scope.

This rule has a severity of Warning but is emitting a diagnostic of Error severity

Fixed

you have 2 Context blocks with the same Suppressed name.

Fixed

I don't think the CompilerServices import is intended?

Removed

This has the same copy-pasta as #2178.

Changed accordingly

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 15:35
@iRon7 iRon7 changed the title WIP: Add new InvalidMultiDotValue rule Add new InvalidMultiDotValue rule Apr 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new built-in PSScriptAnalyzer rule to detect unquoted literals containing multiple dots (which PowerShell can parse as member-access on a double and end up evaluating to $null), along with documentation and test coverage.

Changes:

  • Introduces the InvalidMultiDotValue rule implementation with a -Fix suggestion to quote the multi-dot value.
  • Adds localized rule strings and new rule documentation.
  • Adds Pester tests covering violations, compliant cases, suppressions, and fix behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
docs/Rules/README.md Registers the new rule in the rules index table.
docs/Rules/InvalidMultiDotValue.md New rule documentation with examples.
Tests/Rules/InvalidMultiDotValue.tests.ps1 New test suite for detection, suppression, and -Fix.
Rules/Strings.resx Adds name/description/error/correction strings for the rule.
Rules/InvalidMultiDotValue.cs Implements AST-based detection and suggested correction extents.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/Rules/InvalidMultiDotValue.md Outdated
Comment thread docs/Rules/InvalidMultiDotValue.md Outdated
Comment thread Tests/Rules/InvalidMultiDotValue.tests.ps1 Outdated
Comment thread docs/Rules/README.md
Comment thread Rules/InvalidMultiDotValue.cs Outdated
Comment thread Rules/InvalidMultiDotValue.cs Outdated
Comment thread Rules/Strings.resx Outdated
iRon7 and others added 2 commits April 29, 2026 17:47
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants