Commit 6b259eb9 authored by Jesse McGrew's avatar Jesse McGrew

Clean up IDE0090 lint messages by simplifying "new" expressions.

parent 2e0f8cc2884d
......@@ -18,7 +18,7 @@ namespace ZilfAnalyzers
const string MessageFormat = "This exception should use a diagnostic code instead";
const string Category = "Error Reporting";
static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(
static readonly DiagnosticDescriptor Rule = new(
DiagnosticIds.ExceptionShouldUseDiagnosticCode, Title, MessageFormat,
Category, DiagnosticSeverity.Warning, isEnabledByDefault: true);
......
......@@ -12,7 +12,7 @@ namespace ZilfAnalyzers
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class MessageConstantAnalyzer : DiagnosticAnalyzer
{
static readonly DiagnosticDescriptor Rule_DuplicateMessageCode = new DiagnosticDescriptor(
static readonly DiagnosticDescriptor Rule_DuplicateMessageCode = new(
DiagnosticIds.DuplicateMessageCode,
"Duplicate message code",
"The code '{0}' is used more than once in message set '{1}'",
......@@ -20,7 +20,7 @@ namespace ZilfAnalyzers
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
static readonly DiagnosticDescriptor Rule_DuplicateMessageFormat = new DiagnosticDescriptor(
static readonly DiagnosticDescriptor Rule_DuplicateMessageFormat = new(
DiagnosticIds.DuplicateMessageFormat,
"Duplicate message format",
"This format string is used more than once in message set '{0}'",
......@@ -28,7 +28,7 @@ namespace ZilfAnalyzers
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
static readonly DiagnosticDescriptor Rule_PrefixedMessageFormat = new DiagnosticDescriptor(
static readonly DiagnosticDescriptor Rule_PrefixedMessageFormat = new(
DiagnosticIds.PrefixedMessageFormat,
"Message has hardcoded prefix",
"This format string has the prefix '{0}', which should be moved to the call site",
......@@ -36,9 +36,9 @@ namespace ZilfAnalyzers
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
public static readonly Regex PrefixedMessageFormatRegex = new Regex(
public static readonly Regex PrefixedMessageFormatRegex = new(
@"^(?<prefix>[^a-z .,;:()\[\]{}]+)(?<rest>: .*)$");
public static readonly Regex FormatTokenRegex = new Regex(
public static readonly Regex FormatTokenRegex = new(
@"\{(?<number>\d+)(?<suffix>:[^}]*)?\}");
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
......
......@@ -13,7 +13,7 @@ namespace ZilfAnalyzers
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class ZilObjectAnalyzer : DiagnosticAnalyzer
{
static readonly DiagnosticDescriptor Rule_ComparingZilObjectsWithEquals = new DiagnosticDescriptor(
static readonly DiagnosticDescriptor Rule_ComparingZilObjectsWithEquals = new(
DiagnosticIds.ComparingZilObjectsWithEquals,
"Comparing ZilObjects with Equals",
"'{0}' is for hash-safe comparisons: prefer methods with explicit MDL comparison behavior",
......@@ -21,7 +21,7 @@ namespace ZilfAnalyzers
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
static readonly DiagnosticDescriptor Rule_PartiallyOverriddenZilObjectComparison = new DiagnosticDescriptor(
static readonly DiagnosticDescriptor Rule_PartiallyOverriddenZilObjectComparison = new(
DiagnosticIds.PartiallyOverriddenZilObjectComparison,
"Partially overridden ZilObject comparison",
"'{0}' overrides {1} but does not override {2}",
......
......@@ -72,7 +72,7 @@ namespace Dezapf
class CompoundChunk : Chunk
{
protected readonly List<Chunk> contents = new List<Chunk>();
protected readonly List<Chunk> contents = new();
/*
public static CompoundChunk Combine(Chunk first, Chunk second)
......
......@@ -28,7 +28,7 @@ namespace Dezapf
{
int zversion;
readonly Dictionary<ushort, ZOpAttribute> opcodes = new Dictionary<ushort, ZOpAttribute>();
readonly Dictionary<ushort, ZOpAttribute> opcodes = new();
public Context()
{
......
......@@ -67,7 +67,7 @@ namespace Dezapf
}
}
readonly List<Range> list = new List<Range>();
readonly List<Range> list = new();
public void Add(Range range)
{
......
......@@ -27,7 +27,7 @@ namespace Zapf.Parsing
{
class Tokenizer : IDisposable
{
static readonly Dictionary<char, TokenType> CharTokens = new Dictionary<char, TokenType>
static readonly Dictionary<char, TokenType> CharTokens = new()
{
{ '=', TokenType.Equals },
{ ',', TokenType.Comma },
......
......@@ -66,7 +66,7 @@ namespace Zapf
Context = context;
}
public static readonly AssemblyResult Failed = new AssemblyResult(false, null);
public static readonly AssemblyResult Failed = new(false, null);
[MemberNotNullWhen(true, nameof(Context))]
public bool Success { get; }
......
......@@ -38,8 +38,8 @@ namespace Zilf.Common.StringEncoding
}
}
readonly List<string> allTexts = new List<string>();
readonly StringEncoder encoder = new StringEncoder();
readonly List<string> allTexts = new();
readonly StringEncoder encoder = new();
/// <summary>
/// Adds some text to the accumulator.
......
......@@ -59,8 +59,8 @@ namespace Zilf.Common.StringEncoding
};
readonly byte[][] charset;
readonly List<AbbrevEntry> abbrevs = new List<AbbrevEntry>();
static readonly AbbrevComparer abbrevLengthComparer = new AbbrevComparer();
readonly List<AbbrevEntry> abbrevs = new();
static readonly AbbrevComparer abbrevLengthComparer = new();
public StringEncoder()
{
......
......@@ -79,9 +79,9 @@ namespace Zilf.Common.StringEncoding.SuffixTrees
}
}
public KeyCollection Keys => new KeyCollection(dict);
public KeyCollection Keys => new(dict);
public ValueCollection Values => new ValueCollection(dict);
public ValueCollection Values => new(dict);
public IEnumerator<KeyValuePair<char, Edge<T>>> GetEnumerator()
{
......
......@@ -31,7 +31,7 @@ namespace Zilf.Common.StringEncoding.SuffixTrees
private int depth = -1;
private int leafCount = -1;
private int resultCount = -1;
private EdgeMap<T> edges = new EdgeMap<T>();
private EdgeMap<T> edges = new();
public Node<T>? Suffix { get; set; } = null;
public ref EdgeMap<T> Edges => ref edges;
......
......@@ -66,9 +66,9 @@ namespace Zilf.Common.StringEncoding.SuffixTrees
}
}
public KeyCollection Keys => new KeyCollection(dict);
public KeyCollection Keys => new(dict);
public ValueCollection Values => new ValueCollection(dict);
public ValueCollection Values => new(dict);
public IEnumerator<KeyValuePair<char, IEdge<T>>> GetEnumerator()
{
......
......@@ -278,8 +278,8 @@ namespace Zilf.Emit
}
ILabel? pendingLabel;
readonly Dictionary<ILabel, ILabel> aliases = new Dictionary<ILabel, ILabel>();
readonly LinkedList<Line> lines = new LinkedList<Line>();
readonly Dictionary<ILabel, ILabel> aliases = new();
readonly LinkedList<Line> lines = new();
/// <summary>
/// Gets or sets the delegate that will be used to combine adjacent instructions.
......
......@@ -22,8 +22,8 @@ namespace Zilf.Emit.Zap
{
class DebugFileBuilder : IDebugFileBuilder
{
readonly Dictionary<string, int> files = new Dictionary<string, int>();
readonly List<string> storedLines = new List<string>();
readonly Dictionary<string, int> files = new();
readonly List<string> storedLines = new();
public int GetFileNumber(string? filename)
{
......
......@@ -30,26 +30,26 @@ namespace Zilf.Emit.Zap
{
const string INDENT = "\t";
internal static readonly NumericOperand ZERO = new NumericOperand(0);
internal static readonly NumericOperand ZERO = new(0);
internal static readonly NumericOperand ONE = new NumericOperand(1);
internal static readonly NumericOperand ONE = new(1);
static readonly ConstantLiteralOperand VOCAB = new ConstantLiteralOperand("VOCAB");
static readonly ConstantLiteralOperand VOCAB = new("VOCAB");
// all global names go in here
readonly Dictionary<string, string> symbols = new Dictionary<string, string>(250);
readonly List<ObjectBuilder> objects = new List<ObjectBuilder>(100);
readonly Dictionary<string, PropertyBuilder> props = new Dictionary<string, PropertyBuilder>(32);
readonly Dictionary<string, FlagBuilder> flags = new Dictionary<string, FlagBuilder>(32);
readonly Dictionary<string, IOperand> constants = new Dictionary<string, IOperand>(100);
readonly List<GlobalBuilder> globals = new List<GlobalBuilder>(100);
readonly List<TableBuilder> impureTables = new List<TableBuilder>(10);
readonly List<TableBuilder> pureTables = new List<TableBuilder>(10);
readonly List<WordBuilder> vocabulary = new List<WordBuilder>(100);
readonly HashSet<char> siBreaks = new HashSet<char>();
readonly Dictionary<string, IOperand> stringPool = new Dictionary<string, IOperand>(100);
readonly Dictionary<int, NumericOperand> numberPool = new Dictionary<int, NumericOperand>(50);
readonly Dictionary<string, string> symbols = new(250);
readonly List<ObjectBuilder> objects = new(100);
readonly Dictionary<string, PropertyBuilder> props = new(32);
readonly Dictionary<string, FlagBuilder> flags = new(32);
readonly Dictionary<string, IOperand> constants = new(100);
readonly List<GlobalBuilder> globals = new(100);
readonly List<TableBuilder> impureTables = new(10);
readonly List<TableBuilder> pureTables = new(10);
readonly List<WordBuilder> vocabulary = new(100);
readonly HashSet<char> siBreaks = new();
readonly Dictionary<string, IOperand> stringPool = new(100);
readonly Dictionary<int, NumericOperand> numberPool = new(50);
readonly IZapStreamFactory streamFactory;
internal readonly int zversion;
......
......@@ -44,8 +44,8 @@ namespace Zilf.Emit.Zap
}
}
readonly List<PropertyEntry> props = new List<PropertyEntry>();
readonly List<FlagBuilder> flags = new List<FlagBuilder>();
readonly List<PropertyEntry> props = new();
readonly List<FlagBuilder> flags = new();
public ObjectBuilder(string name)
{
......
......@@ -30,9 +30,9 @@ namespace Zilf.Emit.Zap
{
class RoutineBuilder : ConstantOperandBase, IRoutineBuilder
{
internal static readonly Label RTRUE = new Label("TRUE");
internal static readonly Label RFALSE = new Label("FALSE");
internal static readonly VariableOperand STACK = new VariableOperand("STACK");
internal static readonly Label RTRUE = new("TRUE");
internal static readonly Label RFALSE = new("FALSE");
internal static readonly VariableOperand STACK = new("STACK");
const char INDENT = '\t';
readonly GameBuilder game;
......@@ -45,9 +45,9 @@ namespace Zilf.Emit.Zap
int nextLabelNum;
string? pendingDebugText;
readonly List<LocalBuilder> requiredParams = new List<LocalBuilder>();
readonly List<LocalBuilder> optionalParams = new List<LocalBuilder>();
readonly List<LocalBuilder> locals = new List<LocalBuilder>();
readonly List<LocalBuilder> requiredParams = new();
readonly List<LocalBuilder> optionalParams = new();
readonly List<LocalBuilder> locals = new();
public RoutineBuilder(GameBuilder game, string name, bool entryPoint, bool cleanStack)
{
......
......@@ -23,9 +23,9 @@ namespace Zilf.Emit.Zap
{
class TableBuilder : ConstantOperandBase, ITableBuilder
{
readonly List<short> numericValues = new List<short>();
readonly List<IOperand> operandValues = new List<IOperand>();
readonly List<byte> types = new List<byte>();
readonly List<short> numericValues = new();
readonly List<IOperand> operandValues = new();
readonly List<byte> types = new();
int size;
const byte WORD_FLAG = 1;
......
......@@ -136,7 +136,7 @@ namespace Zilf.Playground.Services.Builds
this.jsInterop = jsInterop;
}
private static readonly Regex StoryFileRegExp = new Regex(@"\.z\d$", RegexOptions.IgnoreCase);
private static readonly Regex StoryFileRegExp = new(@"\.z\d$", RegexOptions.IgnoreCase);
public async Task CompileWorkspaceAsync()
{
......
......@@ -96,8 +96,8 @@ namespace Zilf.Compiler
/// </remarks>
static class PseudoPropertyAtoms
{
public static readonly ZilAtom Desc = new ZilAtom("?DESC?", null, StdAtom.None);
public static readonly ZilAtom Location = new ZilAtom("?IN/LOC?", null, StdAtom.None);
public static readonly ZilAtom Desc = new("?DESC?", null, StdAtom.None);
public static readonly ZilAtom Location = new("?IN/LOC?", null, StdAtom.None);
}
/// <summary>
......
......@@ -60,20 +60,20 @@ namespace Zilf.Compiler
}
// TODO: helper class for managing local variables
public readonly Dictionary<ZilAtom, LocalBindingRecord> Locals = new Dictionary<ZilAtom, LocalBindingRecord>();
public readonly List<LocalBindingRecord> AllLocalBindingRecords = new List<LocalBindingRecord>();
public readonly HashSet<ZilAtom> TempLocalNames = new HashSet<ZilAtom>();
public readonly Stack<ILocalBuilder> SpareLocals = new Stack<ILocalBuilder>();
public readonly Dictionary<ZilAtom, Stack<LocalBindingRecord>> OuterLocals = new Dictionary<ZilAtom, Stack<LocalBindingRecord>>();
public readonly Dictionary<ZilAtom, LocalBindingRecord> Locals = new();
public readonly List<LocalBindingRecord> AllLocalBindingRecords = new();
public readonly HashSet<ZilAtom> TempLocalNames = new();
public readonly Stack<ILocalBuilder> SpareLocals = new();
public readonly Dictionary<ZilAtom, Stack<LocalBindingRecord>> OuterLocals = new();
public readonly Stack<Block> Blocks = new Stack<Block>();
public readonly Stack<Block> Blocks = new();
public readonly Dictionary<ZilAtom, IGlobalBuilder> Globals;
public readonly Dictionary<ZilAtom, IOperand> Constants;
public readonly Dictionary<ZilAtom, IRoutineBuilder> Routines;
public readonly Dictionary<ZilAtom, IObjectBuilder> Objects;
public readonly Dictionary<ZilTable, ITableBuilder> Tables = new Dictionary<ZilTable, ITableBuilder>();
public readonly Dictionary<IWord, IWordBuilder> Vocabulary = new Dictionary<IWord, IWordBuilder>();
public readonly Dictionary<ZilTable, ITableBuilder> Tables = new();
public readonly Dictionary<IWord, IWordBuilder> Vocabulary = new();
public readonly Dictionary<ZilAtom, IPropertyBuilder> Properties;
public readonly Dictionary<ZilAtom, IFlagBuilder> Flags;
......
......@@ -118,7 +118,7 @@ namespace Zilf.Diagnostics
sealed class CustomFormatter : IFormatProvider, ICustomFormatter
{
public static readonly CustomFormatter Instance = new CustomFormatter();
public static readonly CustomFormatter Instance = new();
CustomFormatter()
{
......@@ -198,11 +198,11 @@ namespace Zilf.Diagnostics
where TMessageSet : class
{
readonly string prefix;
readonly Dictionary<int, MessageAttribute> messages = new Dictionary<int, MessageAttribute>();
readonly Dictionary<int, MessageAttribute> messages = new();
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
[SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes")]
public static readonly DiagnosticFactory<TMessageSet> Instance = new DiagnosticFactory<TMessageSet>();
public static readonly DiagnosticFactory<TMessageSet> Instance = new();
protected DiagnosticFactory()
{
......
......@@ -27,11 +27,11 @@ namespace Zilf.Diagnostics
{
const int MaxErrorCount = 100;
readonly List<Diagnostic> diagnostics = new List<Diagnostic>();
readonly List<Diagnostic> diagnostics = new();
readonly List<Diagnostic> suppressedDiagnostics = new List<Diagnostic>();
readonly List<Diagnostic> suppressedDiagnostics = new();
readonly HashSet<string> suppressions = new HashSet<string>();
readonly HashSet<string> suppressions = new();
bool suppressAllTheThings;
......
......@@ -26,9 +26,9 @@ namespace Zilf.Interpreter
class AssociationTable : IEnumerable<AsocResult>
{
readonly ConditionalWeakTable<ZilObject, ConditionalWeakTable<ZilObject, ZilObject>> associations =
new ConditionalWeakTable<ZilObject, ConditionalWeakTable<ZilObject, ZilObject>>();
readonly WeakCountingSet<ZilObject> firsts = new WeakCountingSet<ZilObject>();
readonly WeakCountingSet<ZilObject> seconds = new WeakCountingSet<ZilObject>();
new();
readonly WeakCountingSet<ZilObject> firsts = new();
readonly WeakCountingSet<ZilObject> seconds = new();
/// <summary>
/// Gets the value associated with a pair of objects.
......
......@@ -46,7 +46,7 @@ namespace Zilf.Interpreter
class StructuralEqualityComparer : IEqualityComparer<ZilObject>
{
public static readonly StructuralEqualityComparer Instance = new StructuralEqualityComparer();
public static readonly StructuralEqualityComparer Instance = new();
StructuralEqualityComparer()
{
......
......@@ -31,7 +31,7 @@ namespace Zilf.Interpreter
{
readonly Context ctx;
readonly Dictionary<ZilAtom, Binding> bindings = new Dictionary<ZilAtom, Binding>();
readonly Dictionary<ZilAtom, Binding> bindings = new();
/// <summary>
/// Creates a new environment, optionally inheriting bindings from a parent environment.
......
......@@ -27,7 +27,7 @@ namespace Zilf.Interpreter
[BuiltinType(StdAtom.OBLIST, PrimType.LIST)]
class ObList : ZilTiedListBase
{
readonly Dictionary<string, ZilAtom> dict = new Dictionary<string, ZilAtom>();
readonly Dictionary<string, ZilAtom> dict = new();
readonly bool ignoreCase;
public ObList()
......
......@@ -12,7 +12,7 @@ namespace Zilf.Interpreter
class ParserMacros
{
readonly Dictionary<char, SimplePrefixMacroHandler> prefixMacros =
new Dictionary<char, SimplePrefixMacroHandler>();
new();
readonly Context ctx;
......
......@@ -22,7 +22,7 @@ namespace Zilf.Interpreter
{
static class Recursion
{
static readonly ConditionalWeakTable<object, object?> table = new ConditionalWeakTable<object, object?>();
static readonly ConditionalWeakTable<object, object?> table = new();
public static bool TryLock(object obj)
{
......
......@@ -181,7 +181,7 @@ namespace Zilf.Interpreter
return ch;
}
static readonly Regex RetroPathRE = new Regex(@"^(?:(?<device>[^:]+):)?(?:<(?<directory>[^>]+)>)?(?<filename>[^:<>]+)$");
static readonly Regex RetroPathRE = new(@"^(?:(?<device>[^:]+):)?(?:<(?<directory>[^>]+)>)?(?<filename>[^:<>]+)$");
[Subr]
public static ZilObject OPEN(Context ctx, [Decl("'\"READ\"")] string mode, string path)
......
......@@ -26,7 +26,7 @@ namespace Zilf.Interpreter.Values.Tied
{
sealed class TiedLayout
{
internal static readonly Dictionary<Type, TiedLayout> Layouts = new Dictionary<Type, TiedLayout>();
internal static readonly Dictionary<Type, TiedLayout> Layouts = new();
public static TiedLayout Create<T>(params Expression<Func<T, ZilObject?>>[] elements)
where T : ZilObject, IStructure
......
......@@ -71,7 +71,7 @@ namespace Zilf.Interpreter.Values.Tied
zo => zo.ToStringContext(ctx, friendly));
}
static readonly ObList detachedObList = new ObList();
static readonly ObList detachedObList = new();
protected static ZilAtom GetStdAtom(StdAtom stdAtom)
{
......
......@@ -127,7 +127,7 @@ namespace Zilf.Interpreter.Values
[BuiltinAlternate(typeof(ZilChannel))]
sealed class ZilStringChannel : ZilChannel
{
readonly StringBuilder sb = new StringBuilder();
readonly StringBuilder sb = new();
/// <exception cref="ArgumentException"><paramref name="fileAccess"/> is not <see cref="FileAccess.Write"/>.</exception>
public ZilStringChannel(FileAccess fileAccess)
......
......@@ -36,7 +36,7 @@ namespace Zilf.Interpreter.Values
}
[ChtypeMethod]
public static ZilChar FromFix(ZilFix fix) => new ZilChar(fix.Value);
public static ZilChar FromFix(ZilFix fix) => new(fix.Value);
public char Char => (char)value;
......
......@@ -32,7 +32,7 @@ namespace Zilf.Interpreter.Values
}
[ChtypeMethod]
public static ZilDecl FromList(ZilListBase list) => new ZilDecl(list);
public static ZilDecl FromList(ZilListBase list) => new(list);
public override StdAtom StdTypeAtom => StdAtom.DECL;
......
......@@ -29,7 +29,7 @@ namespace Zilf.Interpreter.Values
{
readonly int value;
public static readonly ZilFix Zero = new ZilFix(0);
public static readonly ZilFix Zero = new(0);
public ZilFix(int value)
{
......
......@@ -45,7 +45,7 @@ namespace Zilf.Interpreter.Values
}
[ChtypeMethod]
public static ZilForm FromList(ZilListBase list) => new ZilForm(list.First!, list.Rest!);
public static ZilForm FromList(ZilListBase list) => new(list.First!, list.Rest!);
protected override string OpenBracket => "<";
......@@ -219,7 +219,7 @@ namespace Zilf.Interpreter.Values
}
static ZilForm DeepRewriteSourceInfo(ZilForm other, ISourceLine? src) =>
new ZilForm(DeepRewriteSourceInfoContents(other, src)) { SourceLine = src };
new(DeepRewriteSourceInfoContents(other, src)) { SourceLine = src };
static IEnumerable<ZilObject> DeepRewriteSourceInfoContents(
IEnumerable<ZilObject> contents, ISourceLine? src)
......
......@@ -66,7 +66,7 @@ namespace Zilf.Interpreter.Values
public ZilList ArgSpecAsList => argspec.ToZilList();
public ZilList BodyAsList => new ZilList(body);
public ZilList BodyAsList => new(body);
public override StdAtom StdTypeAtom => StdAtom.FUNCTION;
......
......@@ -34,7 +34,7 @@ namespace Zilf.Interpreter.Values
: base(first, rest) { }
[ChtypeMethod]
public static ZilList FromList(ZilListBase list) => new ZilList(list.First, list.Rest);
public static ZilList FromList(ZilListBase list) => new(list.First, list.Rest);
public override StdAtom StdTypeAtom => StdAtom.LIST;
......
......@@ -37,7 +37,7 @@ namespace Zilf.Interpreter
}
}
readonly Dictionary<int, List<Cell>> buckets = new Dictionary<int, List<Cell>>();
readonly Dictionary<int, List<Cell>> buckets = new();