From c4eaa689c808b806f537c990479d357dd6cd0945 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 27 Sep 2023 21:41:06 +0100 Subject: [PATCH] Add banned API analyzers Add to detect usage of problematic code patterns. --- Directory.Packages.props | 1 + eng/Analyzers.targets | 2 ++ eng/analyzers/BannedSymbols.txt | 5 +++++ 3 files changed, 8 insertions(+) create mode 100644 eng/analyzers/BannedSymbols.txt diff --git a/Directory.Packages.props b/Directory.Packages.props index dceab74524d..73fa08c1b9a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,6 +10,7 @@ + diff --git a/eng/Analyzers.targets b/eng/Analyzers.targets index 798450220ca..ebd3872744c 100644 --- a/eng/Analyzers.targets +++ b/eng/Analyzers.targets @@ -1,7 +1,9 @@ + + diff --git a/eng/analyzers/BannedSymbols.txt b/eng/analyzers/BannedSymbols.txt new file mode 100644 index 00000000000..1c8d9041801 --- /dev/null +++ b/eng/analyzers/BannedSymbols.txt @@ -0,0 +1,5 @@ +P:System.DateTime.Now; Use TimeProvider.GetLocalNow().DateTime instead. +P:System.DateTime.Today; Use TimeProvider.GetLocalNow().DateTime.Date instead. +P:System.DateTimeOffset.Now; Use TimeProvider.GetLocalNow() instead. +P:System.DateTimeOffset.Today; Use TimeProvider.GetLocalNow().Date instead. +M:System.DateTimeOffset.op_Implicit(System.DateTime); Do not implicitly cast DateTime to DateTimeOffset.