Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1f4234a
Add ConstantExpectedAnalyzer
wzchua Feb 25, 2022
f39fc60
Fix floating point string culture issue
wzchua Feb 25, 2022
74d9533
Update tests
wzchua Feb 25, 2022
d13a77e
Fix typos
wzchua Feb 25, 2022
8b3d43e
Rework test cases
wzchua Feb 25, 2022
d4fe364
run pack command
wzchua Feb 25, 2022
5f8922f
Reorganize and combine some rules.
wzchua Feb 25, 2022
7b883e0
Apply suggestions from code review
wzchua Feb 25, 2022
f784732
Merge branch 'main' into new-analyzer/constant-expected
wzchua May 28, 2022
d12e2fb
Apply suggestion from feedback
wzchua May 29, 2022
9d4c1a3
Merge branch 'main' into new-analyzer/constant-expected
wzchua Jul 16, 2022
db80589
Apply suggestions from code review
wzchua Jul 16, 2022
68e6e28
Apply suggestions from code review
wzchua Jul 16, 2022
52f5e3f
rebuild
wzchua Jul 16, 2022
f991607
Use const variable for Min Max literal
wzchua Jul 16, 2022
eab469f
Drop nint nuint support from ConstantExpected
wzchua Jul 16, 2022
5e1b4c3
Add early exit if symbol for attribute is not found
wzchua Jul 16, 2022
e7ac792
Add check for enums
wzchua Jul 23, 2022
1196110
Merge branch 'main' into new-analyzer/constant-expected
wzchua Aug 27, 2022
65de245
Fix RS1032
wzchua Aug 27, 2022
04ad5b1
Fix IDE0200: Lambda expression can be removed
wzchua Aug 27, 2022
011d9eb
Rework attribute symbol matching
wzchua Aug 27, 2022
ec3f1ae
Update diagnostic Ids
wzchua Aug 27, 2022
59fdd58
Update test to use ReferenceAssemblies.Net70
wzchua Aug 27, 2022
865974c
Add performance tests
wzchua Aug 27, 2022
c87ee13
Apply suggestions from code review
buyaa-n Sep 13, 2022
5f07e36
Update localized messages
buyaa-n Sep 13, 2022
7c8b93b
Merge branch 'main' into new-analyzer/constant-expected
wzchua Nov 12, 2022
266fba8
Run pack
wzchua Nov 12, 2022
86dbee4
Merge branch 'main' into new-analyzer/constant-expected
buyaa-n Nov 16, 2022
774008b
Apply suggestions from code review
buyaa-n Nov 16, 2022
ca89072
Fix generated file
buyaa-n Nov 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Robin Lindner <robin@deeprobin.de>
  • Loading branch information
wzchua and deeprobin authored Jul 16, 2022
commit db805898e146eaba5a14591d56292734de318856
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ protected override void RegisterAttributeSyntax(CompilationStartAnalysisContext
{
context.RegisterSyntaxNodeAction(context => OnAttributeNode(context), SyntaxKind.Attribute);
}
Comment thread
wzchua marked this conversation as resolved.

private void OnAttributeNode(SyntaxNodeAnalysisContext context)
{
var attributeSyntax = (AttributeSyntax)context.Node;
if (!attributeSyntax.Name.IsEquivalentTo(s_constantExpectedIdentifier) && !attributeSyntax.Name.IsEquivalentTo(s_constantExpectedAttributeIdentifier))
var attributeName = attributeSyntax.Name;
if (!attributeName.IsEquivalentTo(s_constantExpectedIdentifier) && !attributeName.IsEquivalentTo(s_constantExpectedAttributeIdentifier))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1865,13 +1865,13 @@
<value>'{0}' uses the preview type '{1}' and needs to opt into preview features. See {2} for more information.</value>
</data>
<data name="ConstantExpectedApplicationTitle" xml:space="preserve">
<value>Incorrect use of ConstantExpectedAttribute</value>
<value>Incorrect usage of ConstantExpected attribute</value>
</data>
<data name="ConstantExpectedApplicationDescription" xml:space="preserve">
<value>ConstantExpectedAttribute is not applied correctly on the paramter.</value>
<value>ConstantExpectedAttribute is not applied correctly on the parameter.</value>
Comment thread
buyaa-n marked this conversation as resolved.
Outdated
</data>
<data name="ConstantExpectedUsageTitle" xml:space="preserve">
<value>Constant is expected for the parameter</value>
<value>A constant is expected for the parameter</value>
</data>
<data name="ConstantExpectedUsageDescription" xml:space="preserve">
<value>The parameter expects a constant for optimal performance.</value>
Comment thread
buyaa-n marked this conversation as resolved.
Expand All @@ -1886,13 +1886,13 @@
<value>The '{0}' value does not fit within the parameter value bounds of '{1}' to '{2}'.</value>
Comment thread
buyaa-n marked this conversation as resolved.
Outdated
</data>
<data name="ConstantExpectedInvertedRangeMessage" xml:space="preserve">
<value>The Min and Max value are inverted.</value>
<value>The Min and Max values are inverted.</value>
</data>
<data name="ConstantExpectedOutOfBoundsMessage" xml:space="preserve">
<value>The constant does not fit within the value bounds of '{0}' to '{1}'.</value>
</data>
<data name="ConstantExpectedInvalidMessage" xml:space="preserve">
<value>The constant is not of the same '{0}' type as the parameter</value>
<value>The constant is not of the same '{0}' type as the parameter.</value>
</data>
<data name="ConstantExpectedNotConstantMessage" xml:space="preserve">
<value>The argument should be a constant for optimal performance.</value>
Comment thread
buyaa-n marked this conversation as resolved.
Outdated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ private void OnCompilationStart(CompilationStartAnalysisContext context)
context.RegisterOperationAction(OnInvocation, OperationKind.Invocation);
context.RegisterSymbolAction(context => OnMethodSymbol(context), SymbolKind.Method);
RegisterAttributeSyntax(context);
return;
}

private static void OnMethodSymbol(SymbolAnalysisContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Microsoft.NetCore.CSharp.Analyzers.Performance.CSharpConstantExpectedAnalyzer,
Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>;

namespace Microsoft.CodeAnalysis.NetAnalyzers.UnitTests.Microsoft.NetCore.Analyzers.Performance
namespace Microsoft.NetCore.Analyzers.Performance.UnitTests
{
public sealed class ConstantExpectedTests
{
Expand Down Expand Up @@ -528,7 +528,7 @@ public static void TestMethod()
{{
TestMethodWithConstant({{|#0:{testValue}|}});
}}
public static void TestMethodWithConstant([ConstantExpected(Min={min}, Max={max})] {type} val) {{ }}
public static void TestMethodWithConstant([ConstantExpected(Min = {min}, Max = {max})] {type} val) {{ }}
}}
";
await TestCSAsync(csInput,
Expand Down