Passing parameters by reference? Let me fix that for you I've implemented a code inspection that verifies whether a procedure has parameters that are implicitly passed by reference - in VBA a parameter is passed ByRef unless it's explicitly specified ByVal.

Here is the implementation in question:

[ComVisible(false)]
public class ImplicitByRefParameterInspection : IInspection
{
    public ImplicitByRefParameterInspection()
    {
        Severity = CodeInspectionSeverity.Warning;
    }

    public string Name { get { return "Parameter is passed ByRef implicitly"; } }
    public CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
    public CodeInspectionSeverity Severity { get; set; }

    public IEnumerable&lt;CodeInspectionResultBase&gt; GetInspectionResults(SyntaxTreeNode node)
    {
        var procedures = node.FindAllProcedures().Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; !string.IsNullOrEmpty(parameter.Instruction.Value)));
        var targets = procedures.Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; parameter.IsImplicitByRef)
                                                &amp;&amp; !procedure.Instruction.Line.IsMultiline);

        return targets.SelectMany(procedure =&gt; procedure.Parameters.Where(parameter =&gt; parameter.IsImplicitByRef)
            .Select(parameter =&gt; new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity)));
    }
}


Would there be a better way to do this? Here is the ImplicitByRefParameterInspectionResult class (gosh that's a long name!):

[ComVisible(false)]
public class ImplicitByRefParameterInspectionResult : CodeInspectionResultBase
{
    public ImplicitByRefParameterInspectionResult(string inspection, Instruction instruction, CodeInspectionSeverity type)
        : base(inspection, instruction, type)
    {
    }

    public override IDictionary&lt;string, Action&lt;VBE&gt;&gt; GetQuickFixes()
    {
        return !Handled
            ? new Dictionary&lt;string, Action&lt;VBE&gt;&gt;
                {
                    {"Pass parameter by value", PassParameterByVal},
                    {"Pass parameter by reference explicitly", PassParameterByRef}
                }
            : new Dictionary&lt;string, Action&lt;VBE&gt;&gt;();
    }

    private void PassParameterByRef(VBE vbe)
    {
        if (!Instruction.Line.IsMultiline)
        {
            var newContent = string.Concat(ReservedKeywords.ByRef, " ", Instruction.Value);
            var oldContent = Instruction.Line.Content;

            var result = oldContent.Replace(Instruction.Value, newContent);

            var module = vbe.FindCodeModules(Instruction.Line.ProjectName, Instruction.Line.ComponentName).First();
            module.ReplaceLine(Instruction.Line.StartLineNumber, result);
            Handled = true;
        }
        else
        {
            // todo: implement for multiline
            throw new NotImplementedException("This method is not [yet] implemented for multiline instructions.");
        }
    }

    private void PassParameterByVal(VBE vbe)
    {
        if (!Instruction.Line.IsMultiline)
        {
            var newContent = string.Concat(ReservedKeywords.ByVal, " ", Instruction.Value);
            var oldContent = Instruction.Line.Content;

            var result = oldContent.Replace(Instruction.Value, newContent);

            var module = vbe.FindCodeModules(Instruction.Line.ProjectName, Instruction.Line.ComponentName).First();
            module.ReplaceLine(Instruction.Line.StartLineNumber, result);
            Handled = true;
        }
        else
        {
            // todo: implement for multiline
            throw new NotImplementedException("This method is not yet implemented for multiline instructions.");
        }
    }
}


Any comment is welcome.
Starting from this

var procedures = node.FindAllProcedures().Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; !string.IsNullOrEmpty(parameter.Instruction.Value)));
var targets = procedures.Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; parameter.IsImplicitByRef)
                                        &amp;&amp; !procedure.Instruction.Line.IsMultiline);

return targets.SelectMany(procedure =&gt; procedure.Parameters.Where(parameter =&gt; parameter.IsImplicitByRef)
    .Select(parameter =&gt; new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity)));


Let's collapse it into one expression

return node.FindAllProcedures()
    .Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; !string.IsNullOrEmpty(parameter.Instruction.Value)))
    .Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; parameter.IsImplicitByRef)
                                        &amp;&amp; !procedure.Instruction.Line.IsMultiline)
    .SelectMany(procedure =&gt; procedure.Parameters.Where(parameter =&gt; parameter.IsImplicitByRef)
    .Select(parameter =&gt; new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity)));


Move the last Select out of SelectMany

return node.FindAllProcedures()
    .Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; !string.IsNullOrEmpty(parameter.Instruction.Value)))
    .Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; parameter.IsImplicitByRef)
                                        &amp;&amp; !procedure.Instruction.Line.IsMultiline)
    .SelectMany(procedure =&gt; procedure.Parameters)
    .Where(parameter =&gt; parameter.IsImplicitByRef)
    .Select(parameter =&gt; new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity));


Now it seems like procedure.Parameters.Any(parameter =&gt; parameter.IsImplicitByRef) is redundant, so let's remove that and join the successive Wheres

return node.FindAllProcedures()
    .Where(procedure =&gt; procedure.Parameters.Any(parameter =&gt; !string.IsNullOrEmpty(parameter.Instruction.Value))
                        &amp;&amp; !procedure.Instruction.Line.IsMultiline)
    .SelectMany(procedure =&gt; procedure.Parameters)
    .Where(parameter =&gt; parameter.IsImplicitByRef)
    .Select(parameter =&gt; new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity));


It's not clear why procedure.Parameters.Any(parameter =&gt; !string.IsNullOrEmpty(parameter.Instruction.Value)) is necessary -- if it is, a comment is required, otherwise we can just write

return node.FindAllProcedures()
    .Where(procedure =&gt; !procedure.Instruction.Line.IsMultiline)
    .SelectMany(procedure =&gt; procedure.Parameters)
    .Where(parameter =&gt; parameter.IsImplicitByRef)
    .Select(parameter =&gt; new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity));


Which is looking more much manageable. Or if you prefer the alternative syntax

return from procedure in node.FindAllProcedures()
       where !procedure.Instruction.Line.IsMultiline
       from parameter in procedure.Parameters
       where parameter.IsImplicitByRef
       select new ImplicitByRefParameterInspectionResult(Name, parameter.Instruction, Severity);