Add new InvalidMultiDotValue rule#2180
Conversation
|
👋 Looks useful, thanks! The naming of this rule is a little awkward. It's listed as This rule has a severity of In your tests, you have 2 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 This has the same copy-pasta as your other PRs. |
|
I am trying to be precise but it is amazing how many issues you still find in PRs. |
Fixed, although I have kept the questionable name
Fixed
Fixed
Removed
Changed accordingly |
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
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
InvalidMultiDotValuerule implementation with a-Fixsuggestion 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
versionorIPAddress)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
-Fixto surround the concerned violation with single quotes.PR Checklist
.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.