override public IEnumerable <IDiagnostic> AnalyzeInternal(SemanticModel model) { // TODO: Performance: Use a visitor to visit VariableAccesssyntax and collects the non-error symbols into a list. // Then do a symbol visitor to go through all the symbols that exist and compare. // Same issue for unused-params rule. // variables must have a reference of type VariableAccessSyntax var unreferencedVariables = model.Root.Declarations.OfType <VariableSymbol>() .Where(sym => !model.FindReferences(sym).OfType <VariableAccessSyntax>().Any()); foreach (var sym in unreferencedVariables) { yield return(CreateDiagnosticForSpan(sym.NameSyntax.Span, sym.Name)); } // TODO: This will not find local variables because they are not in the top-level scope. // Therefore this will not find scenarios such as a loop variable that is not used within the loop // local variables must have a reference of type VariableAccessSyntax var unreferencedLocalVariables = model.Root.Declarations.OfType <LocalVariableSymbol>() .Where(sym => !model.FindReferences(sym).OfType <VariableAccessSyntax>().Any()); foreach (var sym in unreferencedLocalVariables) { yield return(CreateDiagnosticForSpan(sym.NameSyntax.Span, sym.Name)); } }
override public IEnumerable <IDiagnostic> AnalyzeInternal(SemanticModel model) { // parameters must have at least two references // 1) One reference will be the the paramater syntax declaration // 2) VariableAccessSyntax indicates a reference to the parameter var unreferencedParams = model.Root.ParameterDeclarations .Where(sym => !model.FindReferences(sym).OfType <VariableAccessSyntax>().Any()); return(unreferencedParams.Select(param => CreateDiagnosticForSpan(param.NameSyntax.Span, param.Name))); }