Skip to content

Rule request: Avoid reserved words for functions names #2099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iRon7 opened this issue Apr 30, 2025 · 0 comments
Open

Rule request: Avoid reserved words for functions names #2099

iRon7 opened this issue Apr 30, 2025 · 0 comments

Comments

@iRon7
Copy link

iRon7 commented Apr 30, 2025

According the document about Reserved Words, the reserved words that cannot be used as identifiers because they
have a special meaning in PowerShell
:


about_Reserved_Words

Short description

Lists the reserved words that cannot be used as identifiers because they
have a special meaning in PowerShell.

Long description

There are certain words that have special meaning in PowerShell. When these
words appear without quotation marks, PowerShell attempts to apply their
special meaning rather than treating them as character strings. To use these
words as parameter arguments in a command or script without invoking their
special meaning, enclose the reserved words in quotation marks.

The following are the reserved words in PowerShell:

assembly         exit            process
base             filter          public
begin            finally         return
break            for             sequence
catch            foreach         static
class            from (*)        switch
command          function        throw
configuration    hidden          trap
continue         if              try
data             in              type
define (*)       inlinescript    until
do               interface       using
dynamicparam     module          var (*)
else             namespace       while
elseif           parallel        workflow
end              param
enum             private

(*) These keywords are reserved for future use.

It would be nice if the script analyzer warns (or even errors) if any of these names are used for a function name.
E.g. I would expect the following script definition to return an issue:

Invoke-ScriptAnalyzer -ScriptDefinition {function if {}}.ToString()
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

No branches or pull requests

1 participant