private void AnalyzeDiagnostic(Diagnostic diagnostic, SuppressionAnalysisContext context) { var fieldDeclarationSyntax = context.GetSuppressibleNode <VariableDeclaratorSyntax>(diagnostic); if (fieldDeclarationSyntax == null) { return; } var model = context.GetSemanticModel(diagnostic.Location.SourceTree); if (!(model.GetDeclaredSymbol(fieldDeclarationSyntax) is IFieldSymbol fieldSymbol)) { return; } if (!IsSuppressable(fieldSymbol)) { return; } foreach (var descriptor in SupportedSuppressions.Where(d => d.SuppressedDiagnosticId == diagnostic.Id)) { context.ReportSuppression(Suppression.Create(descriptor, diagnostic)); } }
private HashSet <string> GetSuppressionValues(Suppression key) { HashSet <string> values; _suppressions.TryGetValue(key, out values); return(values); }
public DiagnosticRecord(PSObject inputObject) { RuleName = inputObject?.Properties?[nameof(RuleName)]?.Value?.ToString(); Severity = inputObject?.Properties?[nameof(Severity)]?.Value?.ToString(); ScriptPath = inputObject?.Properties?[nameof(ScriptPath)]?.Value?.ToString(); if (int.TryParse(inputObject?.Properties?[nameof(Line)]?.Value?.ToString(), out int line)) { Line = line; } Message = inputObject?.Properties?[nameof(Message)]?.Value?.ToString(); dynamic SuppressionList = inputObject?.Properties?[nameof(Suppression)]?.Value; if (SuppressionList != null) { foreach (dynamic suppression in SuppressionList) { Suppression suppressions = new Suppression(); suppressions.Justification = suppression.Justification; suppressions.Kind = SuppressionKind.InSource; if (suppressions != null) { Suppressions.Add(suppressions); } } } }
internal static Suppression GenerateSuppression(AdditionalInfo additionalInfo) { // If this sentinel key does not exist, we have no suppression data. if (!additionalInfo.ContainsKey("SuppressedMatch")) { return(null); } additionalInfo.TryGetValue("HashKey", out string hashKey); additionalInfo.TryGetValue("MatchingScore", out string matchingScore); additionalInfo.TryGetValue("SuppressJustification", out string justification); var suppression = new Suppression { Kind = SuppressionKind.External, Justification = justification }; if (!string.IsNullOrEmpty(matchingScore)) { suppression.SetProperty("MatchingScore", matchingScore); } if (!string.IsNullOrEmpty(hashKey)) { suppression.SetProperty("HashKey", hashKey); } return(suppression); }
private void AnalyzeDiagnostic(Diagnostic diagnostic, SuppressionAnalysisContext context) { var node = diagnostic.Location.SourceTree.GetRoot(context.CancellationToken).FindNode(diagnostic.Location.SourceSpan); if (node == null) { return; } var model = context.GetSemanticModel(diagnostic.Location.SourceTree); if (!(model.GetDeclaredSymbol(node) is IFieldSymbol fieldSymbol)) { return; } if (!IsSuppressable(fieldSymbol)) { return; } foreach (var descriptor in SupportedSuppressions.Where(d => d.SuppressedDiagnosticId == diagnostic.Id)) { context.ReportSuppression(Suppression.Create(descriptor, diagnostic)); } }
// Start is called before the first frame update void Start() { RaycastHit hit; Ray ray = new Ray(); ray.origin = transform.position; ray.direction = transform.forward; if (Physics.Raycast(ray, out hit, 10000, mask.value, QueryTriggerInteraction.Ignore)) { Debug.DrawRay(ray.origin, ray.direction * 10000); GameObject go = GameObject.Instantiate(puff, hit.point, Quaternion.Inverse(transform.rotation)); ParticleSystem ps = go.GetComponent <ParticleSystem>(); Suppression sup = go.GetComponent <Suppression> (); sup.origin = transform.position; if (hit.collider.attachedRigidbody) { Shootable s = hit.collider.attachedRigidbody.gameObject.GetComponent <Shootable>(); if (s != null) { s.getShot(d); ParticleSystem.ColorOverLifetimeModule coltm = ps.colorOverLifetime; coltm.color = Color.red; } } } }
private void AnalyzeDiagnostic(Diagnostic diagnostic, SuppressionAnalysisContext context) { var node = diagnostic.Location.SourceTree.GetRoot(context.CancellationToken).FindNode(diagnostic.Location.SourceSpan); if (node == null) { return; } var model = context.GetSemanticModel(diagnostic.Location.SourceTree); if (!(model.GetDeclaredSymbol(node) is IFieldSymbol fieldSymbol)) { return; } if (!fieldSymbol.GetAttributes().Any(a => a.AttributeClass.Matches(typeof(UnityEngine.SerializeField)) || a.AttributeClass.Matches(typeof(UnityEngine.SerializeReference)))) { return; } foreach (var descriptor in SupportedSuppressions.Where(d => d.SuppressedDiagnosticId == diagnostic.Id)) { context.ReportSuppression(Suppression.Create(descriptor, diagnostic)); } }
public override void ReportSuppressions(SuppressionAnalysisContext context) { if (!(context.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.XunitFactAttribute) is { } factAttribute)) { return; } var knownTestAttributes = new ConcurrentDictionary <INamedTypeSymbol, bool>(); foreach (var diagnostic in context.ReportedDiagnostics) { // The diagnostic is reported on the test method if (!(diagnostic.Location.SourceTree is { } tree)) { continue; } var root = tree.GetRoot(context.CancellationToken); var node = root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true); var semanticModel = context.GetSemanticModel(tree); var declaredSymbol = semanticModel.GetDeclaredSymbol(node, context.CancellationToken); if (declaredSymbol is IMethodSymbol method && method.IsXUnitTestMethod(knownTestAttributes, factAttribute)) { context.ReportSuppression(Suppression.Create(Rule, diagnostic)); } } }
/// <summary> /// Removes a suppression record from the general suppressions list. /// </summary> /// <param name="suppression">A Suppression object containing the recipient email.</param> public async Task RemoveSuppressionAsync(Suppression suppression) { if (string.IsNullOrEmpty(this.Options.ApiKey)) { throw new InvalidOperationException("Configuration variable SparkPost:ApiKey must be set."); } if (string.IsNullOrEmpty(suppression.RecipientEmail)) { throw new InvalidOperationException("Suppression variable RecipientEmail must be set."); } Uri SparkPostUri = new Uri(string.IsNullOrEmpty(this.Options.ApiHostUri) ? DefaultUri + "/suppression-list/" + suppression.RecipientEmail : this.Options.ApiHostUri + "/suppression-list/" + suppression.RecipientEmail); using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("Authorization", this.Options.ApiKey); var response = await httpClient.DeleteAsync(SparkPostUri); if (!response.IsSuccessStatusCode) { throw new Exception(await response.Content.ReadAsStringAsync()); } } }
public override void ReportSuppressions(SuppressionAnalysisContext context) { var implAttr = context.Compilation.GetTypeByMetadataName(MeansImplicitAssignmentAttribute); foreach (var reportedDiagnostic in context.ReportedDiagnostics) { if (reportedDiagnostic.Id != Diagnostics.MeansImplicitAssignment.SuppressedDiagnosticId) { continue; } var node = reportedDiagnostic.Location.SourceTree?.GetRoot(context.CancellationToken).FindNode(reportedDiagnostic.Location.SourceSpan); if (node == null) { continue; } var symbol = context.GetSemanticModel(reportedDiagnostic.Location.SourceTree).GetDeclaredSymbol(node); if (symbol == null || !symbol.GetAttributes().Any(a => a.AttributeClass?.GetAttributes().Any(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, implAttr)) == true)) { continue; } context.ReportSuppression(Suppression.Create( Diagnostics.MeansImplicitAssignment, reportedDiagnostic)); } }
public void IsNotSuppressedTest() { // Is supressed test string testString = "md5.new()"; Suppression sup = new Suppression(testString); Assert.IsTrue(sup.Index < 0, "Suppression should not be flagged"); }
public void IsSuppressedTest() { // Is supressed test string testString = "md5.new() #DevSkim: ignore DS196098"; Suppression sup = new Suppression(testString); Assert.IsTrue(sup.GetIssues().Length == 1, "Suppression should be flagged"); }
public void SuppressedIndexTest() { // Is supressed test string testString = "md5.new() #DevSkim: ignore DS196098"; Suppression sup = new Suppression(testString); Assert.IsTrue(sup.Index == 12, "Suppression should start in ondex 12"); }
public void SuppresseedAll_Test() { string testString = "var hash=MD5.Create(); /*DevSkim: ignore all*/"; Suppression sup = new Suppression(testString); // Suppress All test Assert.IsTrue(sup.GetIssues().Length == 1, "Supress All failed"); }
public void GetNotSuppressedTest() { string testString = "MD5 hash = new MD5CryptoServiceProvider(); //DevSkim: ignore DS126858,DS168931 until 1980-07-15"; Suppression sup = new Suppression(testString); SuppressedIssue iss = sup.GetSuppressedIssue("DS126858"); Assert.IsNull(sup.GetSuppressedIssue("DS126858"), "Is suppressed DS126858 should be Null"); Assert.IsNull(sup.GetSuppressedIssue("DS168931"), "Is suppressed DS168931 should be Null"); }
public override void ReportSuppressions(SuppressionAnalysisContext context) { foreach (var diagnostic in context.ReportedDiagnostics) { if (diagnostic.GetMessage(CultureInfo.InvariantCulture) is { } message&& IsOut(message)) { context.ReportSuppression(Suppression.Create(Descriptor, diagnostic)); }
public async Task RemoveSuppression() { var suppression = new Suppression() { RecipientEmail = "*****@*****.**", Type = "transactional" }; await this.Client.UpdateSuppressionAsync(suppression); }
public override void ReportSuppressions(SuppressionAnalysisContext context) { foreach (Diagnostic diagnostic in context.ReportedDiagnostics) { if (diagnostic.GetMessage().Contains("TestStruct.X")) // Filtering on the message is gross and terrible. Don't actually do this in a real suppressor. { context.ReportSuppression(Suppression.Create(SupportedSuppressions[0], diagnostic)); } } }
protected bool HasSuppression(Suppression key, string value) { HashSet <string> values; if (_suppressions.TryGetValue(key, out values) && values != null) { return(values.Contains(value)); } return(false); }
protected bool HasSuppression(Suppression key, NuGetFramework framework) { HashSet <string> values; if (_suppressions.TryGetValue(key, out values) && values != null) { var frameworkValues = new[] { framework.DotNetFrameworkName, framework.Framework, framework.GetShortFolderName() }; return(frameworkValues.Any(fx => values.Contains(fx))); } return(false); }
public async Task AddSuppression() { var suppression = new Suppression() { RecipientEmail = "*****@*****.**", Type = "transactional", Description = "Unsubscribe from newsletter" }; await this.Client.UpdateSuppressionAsync(suppression); }
private static void AnalyzeDiagnostic(Diagnostic diagnostic, SuppressionAnalysisContext context) { var model = context.GetSemanticModel(diagnostic.Location.SourceTree); var methodDeclarationSyntax = context.GetSuppressibleNode <MethodDeclarationSyntax>(diagnostic); // Reuse the same detection logic regarding decorated methods with *InitializeOnLoadMethodAttribute if (InitializeOnLoadMethodAnalyzer.MethodMatches(methodDeclarationSyntax, model, out _, out _)) { context.ReportSuppression(Suppression.Create(Rule, diagnostic)); } }
public PSSuppressionActionRule(ActionRule rule) : base(rule) { Suppression suppression = (Suppression)rule.Properties; RecurrenceType = suppression.SuppressionConfig?.RecurrenceType; StartDate = suppression.SuppressionConfig?.Schedule?.StartDate; EndDate = suppression.SuppressionConfig?.Schedule?.EndDate; StartTime = suppression.SuppressionConfig?.Schedule?.StartTime; EndTime = suppression.SuppressionConfig?.Schedule?.EndTime; RecurrenceValues = suppression.SuppressionConfig?.Schedule?.RecurrenceValues; }
private void AnalyzeDiagnostic(Diagnostic diagnostic, SuppressionAnalysisContext context) { try { var node = diagnostic.Location.SourceTree.GetRoot(context.CancellationToken).FindNode(diagnostic.Location.SourceSpan); if (node is PropertyDeclarationSyntax prop) { if (!ContainsMustInitialize(prop, context, prop.Identifier.ValueText)) { return; } } else if ((node.Parent.Parent) is FieldDeclarationSyntax f) { if (!ContainsMustInitialize(f, context, (node as VariableDeclaratorSyntax).Identifier.Text)) { return; } } else if (node is ConstructorDeclarationSyntax) { var regex = new Regex(@"(\S*)\s*'(.*)'"); var match = regex.Match(diagnostic.GetMessage()); var type = match.Groups[1].Value; var name = match.Groups[2].Value; if (type == "field") { var fieldDecl = node.Parent.DescendantNodes().OfType <FieldDeclarationSyntax>().First(n => n.Declaration.Variables.Any(v => v.Identifier.ValueText == name)); if (!ContainsMustInitialize(fieldDecl, context, name)) { return; } } else { var propDecl = node.Parent.DescendantNodes().OfType <PropertyDeclarationSyntax>().First(p => p.Identifier.ValueText == name); if (!ContainsMustInitialize(propDecl, context, name)) { return; } } } context.ReportSuppression(Suppression.Create(MustInitializeRule, diagnostic)); } catch (Exception ex) { Logger.LogError(ex); throw; } }
private static void AnalyzeDiagnostic(Diagnostic diagnostic, SuppressionAnalysisContext context) { var sourceTree = diagnostic.Location.SourceTree; var root = sourceTree.GetRoot(context.CancellationToken); var node = root.FindNode(diagnostic.Location.SourceSpan); var model = context.GetSemanticModel(diagnostic.Location.SourceTree); // Reuse the same detection logic regarding decorated methods with *InitializeOnLoadMethodAttribute if (InitializeOnLoadMethodAnalyzer.MethodMatches(node, model, out _, out _)) { context.ReportSuppression(Suppression.Create(Rule, diagnostic)); } }
public override int GetHashCode() { var hashCode = -2145328967; hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(PowerFullName); hashCode = hashCode * -1521134295 + UniqueId.GetHashCode(); hashCode = hashCode * -1521134295 + EffectClass.GetHashCode(); hashCode = hashCode * -1521134295 + EffectType.GetHashCode(); hashCode = hashCode * -1521134295 + DamageType.GetHashCode(); hashCode = hashCode * -1521134295 + MezmorizeType.GetHashCode(); hashCode = hashCode * -1521134295 + EffectModifiers.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Summon); hashCode = hashCode * -1521134295 + DelayedTime.GetHashCode(); hashCode = hashCode * -1521134295 + Ticks.GetHashCode(); hashCode = hashCode * -1521134295 + Stacking.GetHashCode(); hashCode = hashCode * -1521134295 + BaseProbability.GetHashCode(); hashCode = hashCode * -1521134295 + Suppression.GetHashCode(); hashCode = hashCode * -1521134295 + Buffable.GetHashCode(); hashCode = hashCode * -1521134295 + Resistible.GetHashCode(); hashCode = hashCode * -1521134295 + SpecialCase.GetHashCode(); hashCode = hashCode * -1521134295 + VariableModifiedOverride.GetHashCode(); hashCode = hashCode * -1521134295 + PlayerVersusMode.GetHashCode(); hashCode = hashCode * -1521134295 + ToWho.GetHashCode(); hashCode = hashCode * -1521134295 + DisplayPercentageOverride.GetHashCode(); hashCode = hashCode * -1521134295 + Scale.GetHashCode(); hashCode = hashCode * -1521134295 + Magnitude.GetHashCode(); hashCode = hashCode * -1521134295 + Duration.GetHashCode(); hashCode = hashCode * -1521134295 + AttribType.GetHashCode(); hashCode = hashCode * -1521134295 + Aspect.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(ModifierTable); hashCode = hashCode * -1521134295 + NearGround.GetHashCode(); hashCode = hashCode * -1521134295 + CancelOnMiss.GetHashCode(); hashCode = hashCode * -1521134295 + RequiresToHitCheck.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(UidClassName); hashCode = hashCode * -1521134295 + IdClassName.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(MagnitudeExpression); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Reward); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(EffectId); hashCode = hashCode * -1521134295 + IgnoreEnhancementDiversification.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Override); hashCode = hashCode * -1521134295 + ProcsPerMinute.GetHashCode(); return(hashCode); }
public void LogError(Suppression suppression, string code, string format, params string[] args) { if (!_suppressionEngine.IsErrorSuppressed(suppression)) { if (_baselineAllErrors) { _suppressionEngine.AddSuppression(suppression); } else { _log.LogNonSdkError(code, format, args); } } }
private void LogSuppressableMessage(MessageLevel messageLevel, Suppression suppression, string code, string format, params string[] args) { if (!_suppressionEngine.IsErrorSuppressed(suppression)) { if (_baselineAllErrors) { _suppressionEngine.AddSuppression(suppression); } else { _log.Log(new Message(messageLevel, string.Format(format, args), code)); } } }
private static void AnalyzeProperties(PropertyDeclarationSyntax declarationSyntax, Diagnostic diagnostic, SuppressionAnalysisContext context, SyntaxNode root) { var symbol = GetSymbol(diagnostic.Location.SourceTree, declarationSyntax.Type, context); if (!symbol.Extends(typeof(UnityEngine.Object))) { return; } //check for valid assignments if (IsAssignedTo(declarationSyntax.Identifier.Text, MethodBodies(root))) { context.ReportSuppression(Suppression.Create(Rule, diagnostic)); } }
public override void ReportSuppressions(SuppressionAnalysisContext context) { foreach (var diagnostic in context.ReportedDiagnostics) { if (!(GetSymbolForDiagnostic(diagnostic, context) is IMethodSymbol symbol)) { return; } if (symbol.IsHarmonyMethod()) { context.ReportSuppression(Suppression.Create(suppressionDescriptor, diagnostic)); } } }
private bool HasSuppression(Suppression key, string value) { HashSet<string> values; if (_suppressions.TryGetValue(key, out values) && values != null) { return values.Contains(value); } return false; }
private bool HasSuppression(Suppression key) { return _suppressions.ContainsKey(key); }
private string GetSingleSuppressionValue(Suppression key) { var values = GetSuppressionValues(key); return (values != null && values.Count == 1) ? values.Single() : null; }
private HashSet<string> GetSuppressionValues(Suppression key) { HashSet<string> values; _suppressions.TryGetValue(key, out values); return values; }