Esempio n. 1
0
        /// <summary>
        /// Get violation for a given function definition node
        /// </summary>
        /// <param name="v">Graph vertex, must be non-null</param>
        /// <returns>An instance of DiagnosticRecord if it find violation, otherwise null</returns>
        private DiagnosticRecord GetViolation(Vertex v)
        {
            FunctionDefinitionAst fast = v.Ast as FunctionDefinitionAst;

            if (fast == null)
            {
                return(null);
            }

            if (DeclaresSupportsShouldProcess(fast))
            {
                bool callsShouldProcess            = funcDigraph.IsConnected(v, shouldProcessVertex);
                bool callsCommandWithShouldProcess = funcDigraph.IsConnected(v, implicitShouldProcessVertex);
                if (!callsShouldProcess &&
                    !callsCommandWithShouldProcess)
                {
                    return(new DiagnosticRecord(
                               string.Format(
                                   CultureInfo.CurrentCulture,
                                   Strings.ShouldProcessErrorHasAttribute,
                                   fast.Name),
                               Helper.Instance.GetShouldProcessAttributeAst(fast.Body.ParamBlock.Attributes).Extent,
                               GetName(),
                               GetDianosticSeverity(),
                               ast.Extent.File));
                }
            }
            else
            {
                if (callsShouldProcessDirectly(v))
                {
                    // check if upstream function declares SupportShouldProcess
                    // if so, this might just be a helper function
                    // do not flag this case
                    if (v.IsNestedFunctionDefinition && UpstreamDeclaresShouldProcess(v))
                    {
                        return(null);
                    }

                    return(new DiagnosticRecord(
                               string.Format(
                                   CultureInfo.CurrentCulture,
                                   Strings.ShouldProcessErrorHasCmdlet,
                                   fast.Name),
                               GetShouldProcessCallExtent(fast),
                               GetName(),
                               GetDianosticSeverity(),
                               fileName));
                }
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Get violation for a given function definition node
        /// </summary>
        /// <param name="v">Graph vertex, must be non-null</param>
        /// <returns>An instance of DiagnosticRecord if it find violation, otherwise null</returns>
        private DiagnosticRecord GetViolation(Vertex v)
        {
            FunctionDefinitionAst fast = v.Ast as FunctionDefinitionAst;

            if (fast == null)
            {
                return(null);
            }

            bool callsShouldProcess = funcDigraph.IsConnected(v, shouldProcessVertex);

            if (DeclaresSupportsShouldProcess(fast))
            {
                if (!callsShouldProcess)
                {
                    return(new DiagnosticRecord(
                               string.Format(
                                   CultureInfo.CurrentCulture,
                                   Strings.ShouldProcessErrorHasAttribute,
                                   fast.Name),
                               ast.Extent,
                               GetName(),
                               DiagnosticSeverity.Warning,
                               ast.Extent.File));
                }
            }
            else
            {
                if (callsShouldProcess)
                {
                    // check if upstream function declares SupportShouldProcess
                    // if so, this might just be a helper function
                    // do not flag this case
                    if (UpstreamDeclaresShouldProcess(v))
                    {
                        return(null);
                    }

                    return(new DiagnosticRecord(
                               string.Format(
                                   CultureInfo.CurrentCulture,
                                   Strings.ShouldProcessErrorHasCmdlet,
                                   fast.Name),
                               v.Ast.Extent,
                               GetName(),
                               DiagnosticSeverity.Warning,
                               fileName));
                }
            }

            return(null);
        }