-
Notifications
You must be signed in to change notification settings - Fork 1
Merge v0.1.0 into main #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add [SquiggleCop](https://github.com/MattKotsenas/SquiggleCop) to prevent unintended changes to Roslyn analyzers --------- Signed-off-by: Richard Murillo <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Adds `.globalconfig` to enable pattern matching Resolves #27
…trings (ECS0004) (#41) This pull request introduces a new Roslyn analyzer and code fix to enforce the use of interpolated strings instead of `string.Format`. This change addresses the recommendations outlined in Effective C#: 50 Specific Ways to Improve your C#. ## Rule Details ### Rule ID: ECS0004 **Title:** Replace string.Format with interpolated string **Category:** Style **Description:** This rule identifies instances of `string.Format` and suggests replacing them with C# interpolated strings for improved readability and reduced error potential.
Related: BillWagner/EffectiveCSharpAnalyzers#7 Closes #32 The problem addressed by this rule is the use of methods that should involve callback mechanisms without employing delegates for this purpose. Specifically, methods are being invoked directly without the use of delegate types such as `Predicate<T>`, `Action<T>`, or `Func<T>`, which are designed to handle callbacks in a type-safe and consistent manner.
Signed-off-by: Richard Murillo <[email protected]>
…47) Fixes #45 ```csharp public class C { public void M() { var i = 0; var name = "Foo" + i; // This is lowered to string name = string.Concat("Foo", i.ToString()); } } ``` Two additional checks added to the analyzer: 1. Analysis of the `SyntaxKind.AddExpression` and the `BinaryExpressionSyntax` to look for concat. This is more for defense in depth to stop additional special cased analysis that was there previously. 2. Update to `OperationKind.Conversion`. When an `IConversionOperation` is analyzed, we need to consider a few things: there are safe operations where the compiler lowers the code to an optimal condition to avoid boxing, boxing depends on surrounding context, and last there are specific types that are special cased.
) This pull request introduces a new analyzer rule, ECS0008, which is designed to enforce the use of the null-conditional operator when invoking event handlers in C#. This practice helps prevent potential `NullReferenceExceptions`, improving the safety and robustness of the code. Key Features: - **Detection of Potential Violations**: The rule identifies patterns where an event handler is invoked without using the null-conditional operator (`?.Invoke`), such as direct invocations or invocations within an `if` statement checking for `null`. - **Automatic Code Fixes**: The code fix provider automatically replaces the identified pattern with the null-conditional operator, ensuring that the event handler is only invoked when it has subscribers. - **Comprehensive Coverage**: The rule handles cases where the event handler is checked directly and cases where it is first assigned to a local variable. Example Violation: ```csharp public class EventSource { private EventHandler<int> Updated; private int counter; public void RaiseUpdates() { counter++; if (Updated != null) Updated(this, counter); } } ``` Fixed code: ```csharp public class EventSource { private EventHandler<int> Updated; private int counter; public void RaiseUpdates() { counter++; Updated?.Invoke(this, counter); } } ```
The ECS1000 analyzer for `Span<T>` is not part of Effective C# and is removed
This pull request introduces a new Roslyn analyzer and associated code fix provider to enforce best practices for culture-specific string formatting in C#. The analyzer identifies cases where `FormattableString` or `string.Create` should be used instead of string for interpolated strings, depending on the target framework version. The code fix provider automatically suggests the appropriate replacement. ## Changes - Analyzer: `FormattableStringForCultureSpecificStringsAnalyzer` - Detects culture-specific string usage and recommends either `FormattableString`, `string.Create`, or `string.Format` based on the .NET version. - Code Fix Provider: `FormattableStringForCultureSpecificStringsCodeFixProvider` - Provides automated fixes based on the analyzer's recommendations. - Tests: Comprehensive unit tests covering various scenarios, including different .NET versions and complex string interpolation cases. This analyzer aligns modern C# and .NET practices, particularly Stephen Toub's guidance on using `string.Create` in .NET 6+
Signed-off-by: Richard Murillo <[email protected]>
Signed-off-by: Richard Murillo <[email protected]>
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
version.json
Outdated
@@ -1,13 +1,14 @@ | |||
{ | |||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", | |||
"version": "0.2.0-alpha", | |||
"version": "0.1.0-beta", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to merge back 0.1.0-beta, we want to ship a stable 0.1.0
## Changes - Update build matrix to use latest version of Ubuntu and Windows - Update release workflow to trigger when releases are published, edited, pre-released, or released - Move performance baseline forward - Update .NET SDK version to 8.0.400 - Move analyzer rules to shipped - Update numbering of analyzer rules to leave room for sub rules - Updated analyzer strings for title, message format, description to `LocalizableString` - Update `version.json` to use `0.1.0`
Signed-off-by: Richard Murillo <[email protected]>
Signed-off-by: Richard Murillo <[email protected]>
Signed-off-by: Richard Murillo <[email protected]>
release from the specified branches and tags, with flexibility for multiple versions within each phase. Signed-off-by: Richard Murillo <[email protected]>
No description provided.