PowerShell / PowerShell/PSScriptAnalyzer

Rule request: AvoidDefaultEncoding

Open
#2,079 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Up for Grabs
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

Apparently the default encoding -Encoding Default is removed from the cmdlet documentation that supports the -Encoding parameter. See e.g.:

Which makes sense in a way that this might cause compatibility issues when something is e.g. written (using -Encoding Default in Windows PowerShell 5.1 and read back in PowerShell 7 (e.g. after a PowerShell update migration). Yet, afaik, this isn't captured by any of the UseCompatibleCommands profiles either (probably because the default value is still accepted.

Also note:

  • that using any of the newer encoding values as Ansi and utf8NoBom in PowerShell 7 might cause an incompatibility issue with older versions of PowerShell.
  • the implementation of the -Encoding utf8 value also differs between Windows PowerShell and newer versions of PowerShell:

Therefore I think that it is wise to avoid the default and utf8 encoding (-Encoding Default and -Encoding utf8) when PSUseCompatibleCommands is enabled in the PSScriptAnalyzer settings.

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 reviewing the PSUseCompatibleCommands rule and its compatibility profiles, then compare the linked Windows PowerShell and PowerShell encoding documentation. Define the expected diagnostics for -Encoding Default and -Encoding utf8 when compatibility analysis is enabled, including how the newer Ansi and utf8NoBom values should be treated; the issue is done when the rule behavior and corresponding coverage reflect that decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.