Files
codeql/csharp/ql/test/query-tests/MagicConstants/AttributeInts.cs
2026-07-07 14:09:48 +01:00

29 lines
629 B
C#

using System;
class IdAttribute : Attribute
{
public IdAttribute(int x = 0) { }
public int id;
}
class IntAttributes
{
// GOOD: Constants in attributes shouldn't be flagged, and shouldn't contribute to the count.
[Id(id = 555)]
void f1()
{
}
// GOOD: Constants in attributes shouldn't be flagged, and shouldn't contribute to the count.
[Id(555 + 555)]
void f2()
{
// BAD
var x = 555 + // $ Alert[cs/magic-number]
555 + 555 + 555 + 555 + 555 + 555 + 555 + 555 + 555 + 555 +
555 + 555 + 555 + 555 + 555 + 555 + 555 + 555 + 555 + 555;
}
}