-
Notifications
You must be signed in to change notification settings - Fork 382
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
UseConsistentWhitespace - Create option to ignore assignment operator inside hash table #1566
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5dc3cd3
UseConsistentWhitespace - Create option to ignore assignment operator…
daviesj b9aa6e7
Undo whitespace changes to settings files
daviesj 759c712
Begin implementation of visitor to find token in AST
daviesj 7ef643b
Fleshed out FindAstPositionVistor and fixed test
daviesj 047ae5e
Make visitor internal
daviesj 94329b0
correct spelling
daviesj cc9ebd7
fix off-by-one error in visitor
daviesj ff96591
Simplify code in visitor
daviesj 3594ed5
Move private method to the bottom & small summary correction (leaf =>…
daviesj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,369 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Management.Automation.Language; | ||
|
||
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer | ||
{ | ||
/// <summary> | ||
/// Provides an efficient way to find the position in the AST corresponding to a given script position. | ||
/// </summary> | ||
#if !(PSV3 || PSV4) | ||
internal class FindAstPositionVisitor : AstVisitor2 | ||
#else | ||
internal class FindAstPositionVisitor : AstVisitor | ||
#endif | ||
{ | ||
private IScriptPosition searchPosition; | ||
|
||
/// <summary> | ||
/// Contains the position in the AST corresponding to the provided <see cref="IScriptPosition"/> upon completion of the <see cref="Ast.Visit(AstVisitor)"/> method. | ||
/// </summary> | ||
public Ast AstPosition { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FindAstPositionVisitor"/> class with the postition to search for. | ||
/// </summary> | ||
/// <param name="position">The script position to search for.</param> | ||
public FindAstPositionVisitor(IScriptPosition position) | ||
{ | ||
this.searchPosition = position; | ||
} | ||
|
||
/// <summary> | ||
/// Traverses the AST based on offests to find the leaf node which contains the provided <see cref="IScriptPosition"/>. | ||
/// This method implements the entire functionality of this visitor. All <see cref="AstVisitor2"/> methods are overridden to simply invoke this one. | ||
/// </summary> | ||
/// <param name="ast">Current AST node to process.</param> | ||
/// <returns>An <see cref="AstVisitAction"/> indicating whether to visit children of the current node.</returns> | ||
private AstVisitAction Visit(Ast ast) | ||
{ | ||
if (ast.Extent.StartOffset > searchPosition.Offset || ast.Extent.EndOffset <= searchPosition.Offset) | ||
{ | ||
return AstVisitAction.SkipChildren; | ||
} | ||
AstPosition = ast; | ||
return AstVisitAction.Continue; | ||
} | ||
|
||
public override AstVisitAction VisitArrayExpression(ArrayExpressionAst arrayExpressionAst) | ||
{ | ||
return Visit(arrayExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitArrayLiteral(ArrayLiteralAst arrayLiteralAst) | ||
{ | ||
return Visit(arrayLiteralAst); | ||
} | ||
|
||
public override AstVisitAction VisitAssignmentStatement(AssignmentStatementAst assignmentStatementAst) | ||
{ | ||
return Visit(assignmentStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitAttribute(AttributeAst attributeAst) | ||
{ | ||
return Visit(attributeAst); | ||
} | ||
|
||
public override AstVisitAction VisitAttributedExpression(AttributedExpressionAst attributedExpressionAst) | ||
{ | ||
return Visit(attributedExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitBinaryExpression(BinaryExpressionAst binaryExpressionAst) | ||
{ | ||
return Visit(binaryExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitBlockStatement(BlockStatementAst blockStatementAst) | ||
{ | ||
return Visit(blockStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitBreakStatement(BreakStatementAst breakStatementAst) | ||
{ | ||
return Visit(breakStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitCatchClause(CatchClauseAst catchClauseAst) | ||
{ | ||
return Visit(catchClauseAst); | ||
} | ||
|
||
public override AstVisitAction VisitCommand(CommandAst commandAst) | ||
{ | ||
return Visit(commandAst); | ||
} | ||
|
||
public override AstVisitAction VisitCommandExpression(CommandExpressionAst commandExpressionAst) | ||
{ | ||
return Visit(commandExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitCommandParameter(CommandParameterAst commandParameterAst) | ||
{ | ||
return Visit(commandParameterAst); | ||
} | ||
|
||
public override AstVisitAction VisitConstantExpression(ConstantExpressionAst constantExpressionAst) | ||
{ | ||
return Visit(constantExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitContinueStatement(ContinueStatementAst continueStatementAst) | ||
{ | ||
return Visit(continueStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitConvertExpression(ConvertExpressionAst convertExpressionAst) | ||
{ | ||
return Visit(convertExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitDataStatement(DataStatementAst dataStatementAst) | ||
{ | ||
return Visit(dataStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitDoUntilStatement(DoUntilStatementAst doUntilStatementAst) | ||
{ | ||
return Visit(doUntilStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitDoWhileStatement(DoWhileStatementAst doWhileStatementAst) | ||
{ | ||
return Visit(doWhileStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitErrorExpression(ErrorExpressionAst errorExpressionAst) | ||
{ | ||
return Visit(errorExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitErrorStatement(ErrorStatementAst errorStatementAst) | ||
{ | ||
return Visit(errorStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitExitStatement(ExitStatementAst exitStatementAst) | ||
{ | ||
return Visit(exitStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitExpandableStringExpression(ExpandableStringExpressionAst expandableStringExpressionAst) | ||
{ | ||
return Visit(expandableStringExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitFileRedirection(FileRedirectionAst fileRedirectionAst) | ||
{ | ||
return Visit(fileRedirectionAst); | ||
} | ||
|
||
public override AstVisitAction VisitForEachStatement(ForEachStatementAst forEachStatementAst) | ||
{ | ||
return Visit(forEachStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitForStatement(ForStatementAst forStatementAst) | ||
{ | ||
return Visit(forStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst functionDefinitionAst) | ||
{ | ||
return Visit(functionDefinitionAst); | ||
} | ||
|
||
public override AstVisitAction VisitHashtable(HashtableAst hashtableAst) | ||
{ | ||
return Visit(hashtableAst); | ||
} | ||
|
||
public override AstVisitAction VisitIfStatement(IfStatementAst ifStatementAst) | ||
{ | ||
return Visit(ifStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitIndexExpression(IndexExpressionAst indexExpressionAst) | ||
{ | ||
return Visit(indexExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitInvokeMemberExpression(InvokeMemberExpressionAst invokeMemberExpressionAst) | ||
{ | ||
return Visit(invokeMemberExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitMemberExpression(MemberExpressionAst memberExpressionAst) | ||
{ | ||
return Visit(memberExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitMergingRedirection(MergingRedirectionAst mergingRedirectionAst) | ||
{ | ||
return Visit(mergingRedirectionAst); | ||
} | ||
|
||
public override AstVisitAction VisitNamedAttributeArgument(NamedAttributeArgumentAst namedAttributeArgumentAst) | ||
{ | ||
return Visit(namedAttributeArgumentAst); | ||
} | ||
|
||
public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst) | ||
{ | ||
return Visit(namedBlockAst); | ||
} | ||
|
||
public override AstVisitAction VisitParamBlock(ParamBlockAst paramBlockAst) | ||
{ | ||
return Visit(paramBlockAst); | ||
} | ||
|
||
public override AstVisitAction VisitParameter(ParameterAst parameterAst) | ||
{ | ||
return Visit(parameterAst); | ||
} | ||
|
||
public override AstVisitAction VisitParenExpression(ParenExpressionAst parenExpressionAst) | ||
{ | ||
return Visit(parenExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitPipeline(PipelineAst pipelineAst) | ||
{ | ||
return Visit(pipelineAst); | ||
} | ||
|
||
public override AstVisitAction VisitReturnStatement(ReturnStatementAst returnStatementAst) | ||
{ | ||
return Visit(returnStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitScriptBlock(ScriptBlockAst scriptBlockAst) | ||
{ | ||
return Visit(scriptBlockAst); | ||
} | ||
|
||
public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionAst scriptBlockExpressionAst) | ||
{ | ||
return Visit(scriptBlockExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitStatementBlock(StatementBlockAst statementBlockAst) | ||
{ | ||
return Visit(statementBlockAst); | ||
} | ||
|
||
public override AstVisitAction VisitStringConstantExpression(StringConstantExpressionAst stringConstantExpressionAst) | ||
{ | ||
return Visit(stringConstantExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitSubExpression(SubExpressionAst subExpressionAst) | ||
{ | ||
return Visit(subExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitSwitchStatement(SwitchStatementAst switchStatementAst) | ||
{ | ||
return Visit(switchStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitThrowStatement(ThrowStatementAst throwStatementAst) | ||
{ | ||
return Visit(throwStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitTrap(TrapStatementAst trapStatementAst) | ||
{ | ||
return Visit(trapStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitTryStatement(TryStatementAst tryStatementAst) | ||
{ | ||
return Visit(tryStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitTypeConstraint(TypeConstraintAst typeConstraintAst) | ||
{ | ||
return Visit(typeConstraintAst); | ||
} | ||
|
||
public override AstVisitAction VisitTypeExpression(TypeExpressionAst typeExpressionAst) | ||
{ | ||
return Visit(typeExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitUnaryExpression(UnaryExpressionAst unaryExpressionAst) | ||
{ | ||
return Visit(unaryExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitUsingExpression(UsingExpressionAst usingExpressionAst) | ||
{ | ||
return Visit(usingExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitVariableExpression(VariableExpressionAst variableExpressionAst) | ||
{ | ||
return Visit(variableExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitWhileStatement(WhileStatementAst whileStatementAst) | ||
{ | ||
return Visit(whileStatementAst); | ||
} | ||
|
||
#if !(PSV3 || PSV4) | ||
public override AstVisitAction VisitBaseCtorInvokeMemberExpression(BaseCtorInvokeMemberExpressionAst baseCtorInvokeMemberExpressionAst) | ||
{ | ||
return Visit(baseCtorInvokeMemberExpressionAst); | ||
} | ||
|
||
public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinitionAst configurationDefinitionAst) | ||
{ | ||
return Visit(configurationDefinitionAst); | ||
} | ||
|
||
public override AstVisitAction VisitDynamicKeywordStatement(DynamicKeywordStatementAst dynamicKeywordStatementAst) | ||
{ | ||
return Visit(dynamicKeywordStatementAst); | ||
} | ||
|
||
public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMemberAst) | ||
{ | ||
return Visit(functionMemberAst); | ||
} | ||
|
||
public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMemberAst) | ||
{ | ||
return Visit(propertyMemberAst); | ||
} | ||
|
||
public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinitionAst) | ||
{ | ||
return Visit(typeDefinitionAst); | ||
} | ||
|
||
public override AstVisitAction VisitUsingStatement(UsingStatementAst usingStatementAst) | ||
{ | ||
return Visit(usingStatementAst); | ||
} | ||
#endif | ||
|
||
#if !(NET452 || PSV6) // NET452 includes V3,4,5 | ||
public override AstVisitAction VisitPipelineChain(PipelineChainAst pipelineChainAst) | ||
{ | ||
return Visit(pipelineChainAst); | ||
} | ||
|
||
public override AstVisitAction VisitTernaryExpression(TernaryExpressionAst ternaryExpressionAst) | ||
{ | ||
return Visit(ternaryExpressionAst); | ||
} | ||
#endif | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a private method, I would put this one below all the others