Skip to content

Commit

Permalink
🎨 📝 Tidy up CodeFactor nits
Browse files Browse the repository at this point in the history
  • Loading branch information
vexx32 committed Jun 26, 2019
1 parent 81adc42 commit bcf51ca
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/System.Management.Automation/engine/CommandMetadata.cs
Expand Up @@ -1109,6 +1109,7 @@ internal string GetEndBlock()
}
";
}

internal string GetDisposeBlock()
{
return @"
Expand Down
Expand Up @@ -678,7 +678,6 @@ internal void DoComplete()
_context.ShellFunctionErrorOutputPipe = oldErrorOutputPipe;
_context.CurrentCommandProcessor = oldCurrentCommandProcessor;


// and the previous scope...
if (_previousScope != null)
{
Expand Down Expand Up @@ -991,6 +990,7 @@ private void Dispose(bool disposing)

_context.CurrentCommandProcessor = this;
SetCurrentScopeToExecutionScope();

// This is a no-op for compiled cmdlets
DisposeScriptCommands();
}
Expand All @@ -1000,6 +1000,7 @@ private void Dispose(bool disposing)

_context.ShellFunctionErrorOutputPipe = oldErrorOutputPipe;
_context.CurrentCommandProcessor = oldCurrentCommandProcessor;

// Destroy the local scope at this point if there is one...
if (_useLocalScope && CommandScope != null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/System.Management.Automation/engine/InternalCommands.cs
Expand Up @@ -141,8 +141,9 @@ public ScriptBlock End
}

private bool _disposed;

/// <summary>
/// The script block to apply in complete processing.
/// Gets or sets the script block to execute on command disposal.
/// </summary>
[Parameter(ParameterSetName = "ScriptBlockSet")]
[Alias("Dispose")]
Expand Down
5 changes: 2 additions & 3 deletions src/System.Management.Automation/engine/ProxyCommand.cs
Expand Up @@ -247,10 +247,9 @@ public static string GetEnd(CommandMetadata commandMetadata)
return commandMetadata.GetEndBlock();
}


/// <summary>
/// This method constructs a string representing the dispose block of the command
/// specified by <paramref name="commandMetadata"/>. The returned string only contains the
/// specified by <paramref name="commandMetadata"/>. The returned string only contains the
/// script, it is not enclosed in "dispose { }".
/// </summary>
/// <param name="commandMetadata">
Expand All @@ -260,7 +259,7 @@ public static string GetEnd(CommandMetadata commandMetadata)
/// A string representing the end block of the command.
/// </returns>
/// <exception cref="ArgumentNullException">
/// commandMetadata is null.
/// If <paramref name="commandMetadata"/> is null.
/// </exception>
public static string GetDispose(CommandMetadata commandMetadata)
{
Expand Down
62 changes: 34 additions & 28 deletions src/System.Management.Automation/engine/parser/ast.cs
Expand Up @@ -837,7 +837,8 @@ public class ScriptBlockAst : Ast, IParameterMetadataProvider
}

/// <summary>
/// Construct a ScriptBlockAst that uses explicitly named begin/process/end blocks.
/// Initializes a new instance of the <see cref="ScriptBlockAst"/> class.
/// This construction uses explicitly named begin/process/end/dispose blocks.
/// </summary>
/// <param name="extent">The extent of the script block.</param>
/// <param name="usingStatements">The list of using statments, may be null.</param>
Expand All @@ -852,15 +853,16 @@ public class ScriptBlockAst : Ast, IParameterMetadataProvider
/// If <paramref name="extent"/> is null.
/// </exception>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "param")]
public ScriptBlockAst(IScriptExtent extent,
IEnumerable<UsingStatementAst> usingStatements,
IEnumerable<AttributeAst> attributes,
ParamBlockAst paramBlock,
NamedBlockAst beginBlock,
NamedBlockAst processBlock,
NamedBlockAst endBlock,
NamedBlockAst disposeBlock,
NamedBlockAst dynamicParamBlock)
public ScriptBlockAst(
IScriptExtent extent,
IEnumerable<UsingStatementAst> usingStatements,
IEnumerable<AttributeAst> attributes,
ParamBlockAst paramBlock,
NamedBlockAst beginBlock,
NamedBlockAst processBlock,
NamedBlockAst endBlock,
NamedBlockAst disposeBlock,
NamedBlockAst dynamicParamBlock)
: base(extent)
{
SetUsingStatements(usingStatements);
Expand Down Expand Up @@ -938,7 +940,8 @@ public class ScriptBlockAst : Ast, IParameterMetadataProvider
}

/// <summary>
/// Construct a ScriptBlockAst that uses explicitly named begin/process/end blocks.
/// Initializes a new instance of the <see cref="ScriptBlockAst"/> class.
/// This construction uses explicitly named begin/process/end/dispose blocks.
/// </summary>
/// <param name="extent">The extent of the script block.</param>
/// <param name="usingStatements">The list of using statments, may be null.</param>
Expand All @@ -952,14 +955,15 @@ public class ScriptBlockAst : Ast, IParameterMetadataProvider
/// If <paramref name="extent"/> is null.
/// </exception>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "param")]
public ScriptBlockAst(IScriptExtent extent,
IEnumerable<UsingStatementAst> usingStatements,
ParamBlockAst paramBlock,
NamedBlockAst beginBlock,
NamedBlockAst processBlock,
NamedBlockAst endBlock,
NamedBlockAst disposeBlock,
NamedBlockAst dynamicParamBlock)
public ScriptBlockAst(
IScriptExtent extent,
IEnumerable<UsingStatementAst> usingStatements,
ParamBlockAst paramBlock,
NamedBlockAst beginBlock,
NamedBlockAst processBlock,
NamedBlockAst endBlock,
NamedBlockAst disposeBlock,
NamedBlockAst dynamicParamBlock)
: this(extent, usingStatements, null, paramBlock, beginBlock, processBlock, endBlock, disposeBlock, dynamicParamBlock)
{
}
Expand Down Expand Up @@ -988,7 +992,8 @@ public class ScriptBlockAst : Ast, IParameterMetadataProvider
}

/// <summary>
/// Construct a ScriptBlockAst that uses explicitly named begin/process/end blocks.
/// Initializes a new instance of the <see cref="ScriptBlockAst"/> class.
/// This construction uses explicitly named begin/process/end/dispose blocks.
/// </summary>
/// <param name="extent">The extent of the script block.</param>
/// <param name="paramBlock">The ast for the param block, may be null.</param>
Expand All @@ -1001,13 +1006,14 @@ public class ScriptBlockAst : Ast, IParameterMetadataProvider
/// If <paramref name="extent"/> is null.
/// </exception>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "param")]
public ScriptBlockAst(IScriptExtent extent,
ParamBlockAst paramBlock,
NamedBlockAst beginBlock,
NamedBlockAst processBlock,
NamedBlockAst endBlock,
NamedBlockAst disposeBlock,
NamedBlockAst dynamicParamBlock)
public ScriptBlockAst(
IScriptExtent extent,
ParamBlockAst paramBlock,
NamedBlockAst beginBlock,
NamedBlockAst processBlock,
NamedBlockAst endBlock,
NamedBlockAst disposeBlock,
NamedBlockAst dynamicParamBlock)
: this(extent, null, paramBlock, beginBlock, processBlock, endBlock, disposeBlock, dynamicParamBlock)
{
}
Expand Down Expand Up @@ -1217,7 +1223,7 @@ private void SetUsingStatements(IEnumerable<UsingStatementAst> usingStatements)
public NamedBlockAst EndBlock { get; private set; }

/// <summary>
/// The ast representing the dispose block for a script block, or null if no dispose block was specified.
/// Gets the ast representing the dispose block for a script block, or null if no dispose block was specified.
/// </summary>
public NamedBlockAst DisposeBlock { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/parser/token.cs
Expand Up @@ -570,7 +570,7 @@ public enum TokenKind
/// <summary>The 'base' keyword</summary>
Base = 168,

/// <summary>The 'dispose' keyword</summary>
/// <summary>The 'dispose' keyword.</summary>
Dispose = 169,

#endregion Keywords
Expand Down
Expand Up @@ -727,7 +727,6 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
createLocalScope,
args);


internal SteppablePipeline GetSteppablePipelineImpl(CommandOrigin commandOrigin, object[] args)
{
var pipelineAst = GetSimplePipeline(
Expand Down Expand Up @@ -2456,9 +2455,9 @@ public void Dispose()
{
return;
}

try
{

if (_scriptBlock.HasDisposeBlock)
{
RunClause(
Expand Down

0 comments on commit bcf51ca

Please sign in to comment.