Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ If you are already using other analyzers, you can check [which rules are duplica
|[MA0182](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0182.md)|Design|Avoid unused internal types|ℹ️|✔️|✔️|❌|
|[MA0183](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0183.md)|Usage|The format string should use placeholders|⚠️|✔️|❌|❌|
|[MA0184](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0184.md)|Style|Do not use interpolated string without parameters|👻|✔️|✔️|❌|
|[MA0185](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0185.md)|Performance|Simplify string.Create when all parameters are culture invariant|ℹ️|✔️|✔️|❌|
|[MA0185](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0185.md)|Performance|Simplify string.Create when all parameters are culture invariant|ℹ️|✔️|✔️|✔️|
|[MA0186](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0186.md)|Design|Equals method should use \[NotNullWhen(true)\] on the parameter|ℹ️|❌|✔️|❌|
|[MA0187](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0187.md)|Design|Use constructor injection instead of \[Inject\] attribute|ℹ️|❌|✔️|❌|
|[MA0188](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0188.md)|Design|Use System.TimeProvider instead of a custom time abstraction|ℹ️|✔️|❌|❌|
Expand Down
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
|[MA0008](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0008.md)|Performance|Add StructLayoutAttribute|<span title='Warning'>⚠️</span>|✔️|✔️|❌|
|[MA0009](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0009.md)|Security|Add regex evaluation timeout|<span title='Warning'>⚠️</span>|✔️|❌|❌|
|[MA0010](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0010.md)|Design|Mark attributes with AttributeUsageAttribute|<span title='Warning'>⚠️</span>|✔️|✔️|❌|
|[MA0011](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0011.md)|Usage|IFormatProvider is missing|<span title='Warning'>⚠️</span>|✔️|✔️|<span title='MA0011.consider_nullable_types&#xA;MA0011.exclude_tostring_methods&#xA;MA0011.report_maybe_culture_sensitive'>✔️</span>|
|[MA0011](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0011.md)|Usage|IFormatProvider is missing|<span title='Warning'>⚠️</span>|✔️|✔️|<span title='MA0011.consider_nullable_types&#xA;MA0011.exclude_tostring_methods&#xA;MA0011.treat_opaque_runtime_types_as_culture_sensitive&#xA;MA0011.treat_unsealed_types_as_culture_sensitive'>✔️</span>|
|[MA0012](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0012.md)|Design|Do not raise reserved exception type|<span title='Warning'>⚠️</span>|✔️|❌|❌|
|[MA0013](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0013.md)|Design|Types should not extend System.ApplicationException|<span title='Warning'>⚠️</span>|✔️|❌|❌|
|[MA0014](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0014.md)|Design|Do not raise System.ApplicationException type|<span title='Warning'>⚠️</span>|✔️|❌|❌|
Expand Down Expand Up @@ -74,8 +74,8 @@
|[MA0072](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0072.md)|Design|Do not throw from a finally block|<span title='Warning'>⚠️</span>|✔️|❌|❌|
|[MA0073](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0073.md)|Style|Avoid comparison with bool constant|<span title='Info'>ℹ️</span>|✔️|✔️|❌|
|[MA0074](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0074.md)|Usage|Avoid implicit culture-sensitive methods|<span title='Warning'>⚠️</span>|✔️|✔️|❌|
|[MA0075](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0075.md)|Design|Do not use implicit culture-sensitive ToString|<span title='Info'>ℹ️</span>|✔️|❌|<span title='MA0075.consider_nullable_types&#xA;MA0075.exclude_tostring_methods&#xA;MA0075.report_maybe_culture_sensitive'>✔️</span>|
|[MA0076](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0076.md)|Design|Do not use implicit culture-sensitive ToString in interpolated strings|<span title='Info'>ℹ️</span>|✔️|✔️|<span title='MA0076.consider_nullable_types&#xA;MA0076.exclude_tostring_methods&#xA;MA0076.report_maybe_culture_sensitive'>✔️</span>|
|[MA0075](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0075.md)|Design|Do not use implicit culture-sensitive ToString|<span title='Info'>ℹ️</span>|✔️|❌|<span title='MA0075.consider_nullable_types&#xA;MA0075.exclude_tostring_methods&#xA;MA0075.treat_opaque_runtime_types_as_culture_sensitive&#xA;MA0075.treat_unsealed_types_as_culture_sensitive'>✔️</span>|
|[MA0076](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0076.md)|Design|Do not use implicit culture-sensitive ToString in interpolated strings|<span title='Info'>ℹ️</span>|✔️|✔️|<span title='MA0076.consider_nullable_types&#xA;MA0076.exclude_tostring_methods&#xA;MA0076.treat_opaque_runtime_types_as_culture_sensitive&#xA;MA0076.treat_unsealed_types_as_culture_sensitive'>✔️</span>|
|[MA0077](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0077.md)|Design|A class that provides Equals(T) should implement IEquatable\<T\>|<span title='Warning'>⚠️</span>|✔️|✔️|❌|
|[MA0078](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0078.md)|Performance|Use 'Cast' instead of 'Select' to cast|<span title='Info'>ℹ️</span>|✔️|✔️|❌|
|[MA0079](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0079.md)|Usage|Forward the CancellationToken using .WithCancellation()|<span title='Info'>ℹ️</span>|✔️|✔️|❌|
Expand Down Expand Up @@ -183,7 +183,7 @@
|[MA0182](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0182.md)|Design|Avoid unused internal types|<span title='Info'>ℹ️</span>|✔️|✔️|❌|
|[MA0183](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0183.md)|Usage|The format string should use placeholders|<span title='Warning'>⚠️</span>|✔️|❌|❌|
|[MA0184](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0184.md)|Style|Do not use interpolated string without parameters|<span title='Hidden'>👻</span>|✔️|✔️|❌|
|[MA0185](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0185.md)|Performance|Simplify string.Create when all parameters are culture invariant|<span title='Info'>ℹ️</span>|✔️|✔️|❌|
|[MA0185](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0185.md)|Performance|Simplify string.Create when all parameters are culture invariant|<span title='Info'>ℹ️</span>|✔️|✔️|<span title='MA0185.treat_opaque_runtime_types_as_culture_sensitive&#xA;MA0185.treat_unsealed_types_as_culture_sensitive'>✔️</span>|
|[MA0186](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0186.md)|Design|Equals method should use \[NotNullWhen(true)\] on the parameter|<span title='Info'>ℹ️</span>|❌|✔️|❌|
|[MA0187](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0187.md)|Design|Use constructor injection instead of \[Inject\] attribute|<span title='Info'>ℹ️</span>|❌|✔️|❌|
|[MA0188](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0188.md)|Design|Use System.TimeProvider instead of a custom time abstraction|<span title='Info'>ℹ️</span>|✔️|❌|❌|
Expand Down
9 changes: 6 additions & 3 deletions docs/Rules/MA0011.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Sources: [UseIFormatProviderAnalyzer.cs](https://github.com/meziantou/Meziantou.
This rule warns about the usage of overloads of methods like `Parse`, `TryParse` and `ToString` that do not take a parameter of type `IFormatProvider`.
Methods ending with `OrDefault` are excluded from this rule as the argument is often not relevant for globalization.

The analyzer classifies values as culture-sensitive, culture-insensitive, or maybe culture-sensitive. It reports culture-sensitive values, including types implementing `IFormattable` or `ISpanFormattable` and types with a provider-aware `ToString` overload. Known culture-invariant types, invariant formats and values, sealed types that do not support culture-aware formatting, and types marked with `CultureInsensitiveTypeAttribute` are culture-insensitive. Values typed as `object`, an interface, a type parameter, or a non-sealed class are maybe culture-sensitive because their runtime type can format differently. They are not reported by default; set `MA0011.report_maybe_culture_sensitive` to `true` to report them.
The analyzer classifies values as culture-sensitive, culture-insensitive, opaque runtime types, or non-sealed types. It reports culture-sensitive values, including types implementing `IFormattable` or `ISpanFormattable` and types with a provider-aware `ToString` overload. Known culture-invariant types, invariant formats and values, sealed types that do not support culture-aware formatting, and types marked with `CultureInsensitiveTypeAttribute` are culture-insensitive. Values typed as `object`, an interface, or an unconstrained type parameter are opaque runtime types. Non-sealed classes are tracked separately. These two categories are not reported by default; set `MA0011.treat_opaque_runtime_types_as_culture_sensitive` or `MA0011.treat_unsealed_types_as_culture_sensitive` to `true` to report them.

For more information, see [Creating Globally Aware Applications](https://learn.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/cc853414(v=vs.95)?WT.mc_id=DT-MVP-5003978).

Expand Down Expand Up @@ -41,8 +41,11 @@ MA0011.exclude_tostring_methods=true
# Report Nullable<T>.ToString when T is culture-sensitive
MA0011.consider_nullable_types=true

# Report values that may be culture-sensitive based on their runtime type
MA0011.report_maybe_culture_sensitive=true
# Report object, interface, and unconstrained type parameter values
MA0011.treat_opaque_runtime_types_as_culture_sensitive=false

# Report non-sealed class values
MA0011.treat_unsealed_types_as_culture_sensitive=false
````

You can also annotate a type with `[Meziantou.Analyzer.Annotations.CultureInsensitiveTypeAttribute]` to disable the rule for this type. See [CultureInsensitiveTypeAttribute](../CultureInsensitiveTypeAttribute.md) for details and [Meziantou.Analyzer.Annotations README](https://github.com/meziantou/Meziantou.Analyzer/blob/main/src/Meziantou.Analyzer.Annotations/README.md) for installation options.
9 changes: 6 additions & 3 deletions docs/Rules/MA0075.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _ = "abc" + -1.ToString(CultureInfo.CurrentCulture); // compliant
_ = "abc" + -1.ToString(CultureInfo.InvariantCulture); // compliant
````

A type is culture-sensitive when it implements `System.IFormattable` or `System.ISpanFormattable`, or exposes a provider-aware `ToString` overload. A type is culture-insensitive when it is known to be invariant, is marked with `CultureInsensitiveTypeAttribute`, or is sealed and does not support culture-aware formatting. Values typed as `object`, an interface, a type parameter, or a non-sealed class are maybe culture-sensitive because their runtime type can format differently. They are not reported by default; set `MA0075.report_maybe_culture_sensitive` to `true` to report them.<br/>
A type is culture-sensitive when it implements `System.IFormattable` or `System.ISpanFormattable`, or exposes a provider-aware `ToString` overload. A type is culture-insensitive when it is known to be invariant, is marked with `CultureInsensitiveTypeAttribute`, or is sealed and does not support culture-aware formatting. Values typed as `object`, an interface, or an unconstrained type parameter are opaque runtime types. Non-sealed classes are tracked separately. These two categories are not reported by default; set `MA0075.treat_opaque_runtime_types_as_culture_sensitive` or `MA0075.treat_unsealed_types_as_culture_sensitive` to `true` to report them.<br/>
Known culture-invariant types include:
* Any enum
* System.Byte
Expand Down Expand Up @@ -44,8 +44,11 @@ MA0075.exclude_tostring_methods=true
# Report Nullable<T>.ToString when T is culture-sensitive
MA0075.consider_nullable_types=true

# Report values that may be culture-sensitive based on their runtime type
MA0075.report_maybe_culture_sensitive=true
# Report object, interface, and unconstrained type parameter values
MA0075.treat_opaque_runtime_types_as_culture_sensitive=false

# Report non-sealed class values
MA0075.treat_unsealed_types_as_culture_sensitive=false
````

You can also annotate a type with `[Meziantou.Analyzer.Annotations.CultureInsensitiveTypeAttribute]` to disable the rule for this type. See [CultureInsensitiveTypeAttribute](../CultureInsensitiveTypeAttribute.md) for details and [Meziantou.Analyzer.Annotations README](https://github.com/meziantou/Meziantou.Analyzer/blob/main/src/Meziantou.Analyzer.Annotations/README.md) for installation options.
9 changes: 6 additions & 3 deletions docs/Rules/MA0076.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _ = string.Create(CultureInfo.InvariantCulture, $"abc{-1}"); // compliant
FormattableString str = $"abc{-1}"; // compliant
````

The analyzer classifies values as culture-sensitive, culture-insensitive, or maybe culture-sensitive. It reports culture-sensitive values, including types implementing `IFormattable` or `ISpanFormattable` and types with a provider-aware `ToString` overload. Known culture-invariant types, invariant formats and values, sealed types that do not support culture-aware formatting, and types marked with `CultureInsensitiveTypeAttribute` are culture-insensitive. Values typed as `object`, an interface, a type parameter, or a non-sealed class are maybe culture-sensitive because their runtime type can format differently. They are not reported by default; set `MA0076.report_maybe_culture_sensitive` to `true` to report them.
The analyzer classifies values as culture-sensitive, culture-insensitive, opaque runtime types, or non-sealed types. It reports culture-sensitive values, including types implementing `IFormattable` or `ISpanFormattable` and types with a provider-aware `ToString` overload. Known culture-invariant types, invariant formats and values, sealed types that do not support culture-aware formatting, and types marked with `CultureInsensitiveTypeAttribute` are culture-insensitive. Values typed as `object`, an interface, or an unconstrained type parameter are opaque runtime types. Non-sealed classes are tracked separately. These two categories are not reported by default; set `MA0076.treat_opaque_runtime_types_as_culture_sensitive` or `MA0076.treat_unsealed_types_as_culture_sensitive` to `true` to report them.

## Configuration

Expand All @@ -22,8 +22,11 @@ MA0076.exclude_tostring_methods=true
# Report Nullable<T>.ToString when T is culture-sensitive
MA0076.consider_nullable_types=true

# Report values that may be culture-sensitive based on their runtime type
MA0076.report_maybe_culture_sensitive=true
# Report object, interface, and unconstrained type parameter values
MA0076.treat_opaque_runtime_types_as_culture_sensitive=false

# Report non-sealed class values
MA0076.treat_unsealed_types_as_culture_sensitive=false
````

You can also annotate a type with `[Meziantou.Analyzer.Annotations.CultureInsensitiveTypeAttribute]` to disable the rule for this type. See [CultureInsensitiveTypeAttribute](../CultureInsensitiveTypeAttribute.md) for details and [Meziantou.Analyzer.Annotations README](https://github.com/meziantou/Meziantou.Analyzer/blob/main/src/Meziantou.Analyzer.Annotations/README.md) for installation options.
15 changes: 14 additions & 1 deletion docs/Rules/MA0185.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,23 @@ The analyzer detects when all interpolated values are culture-invariant, such as
- Enum values
- Boolean values
- and other culture-insensitive types
- Opaque runtime types such as `object`, interfaces, and unconstrained type parameters, unless `MA0185.treat_opaque_runtime_types_as_culture_sensitive` is enabled
- Non-sealed classes, unless `MA0185.treat_unsealed_types_as_culture_sensitive` is enabled

You can annotate custom types with `[Meziantou.Analyzer.Annotations.CultureInsensitiveTypeAttribute]` to mark them as culture-insensitive and make additional `string.Create(CultureInfo.InvariantCulture, ...)` usages eligible for simplification. See [CultureInsensitiveTypeAttribute](../CultureInsensitiveTypeAttribute.md) for details and [Meziantou.Analyzer.Annotations README](https://github.com/meziantou/Meziantou.Analyzer/blob/main/src/Meziantou.Analyzer.Annotations/README.md) for installation options.

The analyzer will NOT suggest simplification when:
- Any parameter is culture-sensitive (e.g., `double`, `DateTime` with culture-sensitive format)
- A parameter is maybe culture-sensitive, such as one typed as `object`, an interface, a type parameter, or a non-sealed class, as its runtime type may format differently. This rule requires proof that all parameters are culture-insensitive.
- A parameter is an opaque runtime type and `MA0185.treat_opaque_runtime_types_as_culture_sensitive` is enabled
- A parameter is a non-sealed class and `MA0185.treat_unsealed_types_as_culture_sensitive` is enabled
- The culture is not `CultureInfo.InvariantCulture`

## Configuration

````
# Treat object, interface, and unconstrained type parameter values as culture-sensitive
MA0185.treat_opaque_runtime_types_as_culture_sensitive=false

# Treat non-sealed class values as culture-sensitive
MA0185.treat_unsealed_types_as_culture_sensitive=false
````
Loading