You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed quotes aren't smartly replaced when used in #Requires statements.
Steps to reproduce
Look at the following lines. Note that the double quote chars probably don't need to be used on that first line, but I don't think it's an error to use them. And when they are used, they should be processed properly by PSScriptAnalyzer.
I like the idea of this - but it could be a difficult one to implement.
The way the majority of the rules work within PSSA is that they analyze the Abstract Syntax Tree and not the source files directly.
The rule that does the quote replacement, AvoidUsingDoubleQuotesForConstantString, looks for StringConstantExpressionAst - the the type of AST which represents strings (be they single quoted, double quoted, or here-strings).
The AST is useful as it tells you where each part of the code starts and stops as well as other useful information from the PowerShell parser. For instance in the strings example, where each string starts and stops, and the type of string it is - making it trivial to decide if a change is required and then change the type of quotes that string uses.
The #Requires statement is not directly parsed as a node of the AST - it's parsed into the ScriptRequirements of a ScriptBlockAST - no matter where it appears within the source file.
This provides no hint as to where the #Requires statement appears within the source file and also does not parse any strings that make up the #Requires statement into StringConstantExpressionAst (the 'Az.Accounts' in your example for instance).
I believe to implement this, you'd have to do a lot of work to recognise the #requires statement directly in the source text, then manually parse any strings which make this up (including those which appear within hashtables).
I noticed quotes aren't smartly replaced when used in
#Requires
statements.Steps to reproduce
Look at the following lines. Note that the double quote chars probably don't need to be used on that first line, but I don't think it's an error to use them. And when they are used, they should be processed properly by PSScriptAnalyzer.
Expected behavior
I had expected the double quote chars to be replaced by single quote chars, like this:
Actual behavior
The quotes remain unchanged.
It seems PSScriptAnalyzer treats
#Requires
lines as mere comments and doesn't process them.Environment data
The text was updated successfully, but these errors were encountered: