Skip to content

Commit

Permalink
Add some doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jairbubbles committed Mar 30, 2024
1 parent 3824ff0 commit 6d3a1a9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ If you are already using other analyzers, you can check [which rules are duplica
|[MA0151](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0151.md)|Usage|DebuggerDisplay must contain valid members|⚠️|✔️||
|[MA0152](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0152.md)|Performance|Use Unwrap instead of using await twice|ℹ️|✔️||
|[MA0153](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0153.md)|Design|Do not log symbols decorated with DataClassificationAttribute directly|⚠️|✔️||
|[MA0154](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0154.md)|Design|Use langword in XML comment|ℹ️|✔️||
|[MA0154](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0154.md)|Design|Use langword in XML comment|ℹ️|✔️|✔️|
|[MA0155](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0155.md)|Usage|UseShellExecute must be explicitly set|⚠️|||

<!-- rules -->

Expand Down
9 changes: 8 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
|[MA0151](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0151.md)|Usage|DebuggerDisplay must contain valid members|<span title='Warning'>⚠️</span>|✔️||
|[MA0152](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0152.md)|Performance|Use Unwrap instead of using await twice|<span title='Info'>ℹ️</span>|✔️||
|[MA0153](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0153.md)|Design|Do not log symbols decorated with DataClassificationAttribute directly|<span title='Warning'>⚠️</span>|✔️||
|[MA0154](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0154.md)|Design|Use langword in XML comment|<span title='Info'>ℹ️</span>|✔️||
|[MA0154](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0154.md)|Design|Use langword in XML comment|<span title='Info'>ℹ️</span>|✔️|✔️|
|[MA0155](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0155.md)|Usage|UseShellExecute must be explicitly set|<span title='Warning'>⚠️</span>|||

|Id|Suppressed rule|Justification|
|--|---------------|-------------|
Expand Down Expand Up @@ -622,6 +623,9 @@ dotnet_diagnostic.MA0153.severity = warning
# MA0154: Use langword in XML comment
dotnet_diagnostic.MA0154.severity = suggestion
# MA0155: UseShellExecute must be explicitly set
dotnet_diagnostic.MA0155.severity = none
```

# .editorconfig - all rules disabled
Expand Down Expand Up @@ -1085,4 +1089,7 @@ dotnet_diagnostic.MA0153.severity = none
# MA0154: Use langword in XML comment
dotnet_diagnostic.MA0154.severity = none
# MA0155: UseShellExecute must be explicitly set
dotnet_diagnostic.MA0155.severity = none
```
43 changes: 43 additions & 0 deletions docs/Rules/MA0155.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# MA0155 - UseShellExecute must be explicitly set

Detects when `Process.Start` is called without specifying the value of `UseShellExecute`.

The goal is to help for those two cases:
- The default value for this property is true on .NET Framework apps and false on .NET Core apps.
- It must be set to to false when redirecting I/O.


````c#
using System.Diasgnostics;

// Non compliant
Process.Start("cmd"); // Intent is not clear if you want to use ShellExecute or not
Process.Start("https://www.meziantou.net/"); // Will fail on .NET Core apps
Process.Start(new ProcessStartInfo("cmd")
{
RedirectStandardOutput = true,
UseShellExecute = true,
}); // It will throw with error "UseShellExecute must be set to false when redirecting I/O"
Process.Start(new ProcessStartInfo("cmd")
{
RedirectStandardOutput = true,
}); // It will throw with error "UseShellExecute must be set to false when redirecting I/O" on .NET Framework apps
// Compliant
Process.Start(new ProcessStartInfo("https://www.meziantou.net/")
{
UseShellExecute = true,
});

Process.Start(new ProcessStartInfo("cmd")
{
RedirectStandardOutput = true,
UseShellExecute = false,
});

````
3 changes: 3 additions & 0 deletions src/Meziantou.Analyzer/Rules/UseShellExecuteAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ public override void Initialize(AnalysisContext context)
ctx.RegisterOperationAction(analyzerContext.AnalyzeInvocation, OperationKind.Invocation);
ctx.RegisterOperationAction(analyzerContext.AnalyzeObjectCreation, OperationKind.ObjectCreation);
});

}



private sealed class AnalyzerContext(Compilation compilation)
{
private readonly INamedTypeSymbol? _processStartInfoSymbol = compilation.GetBestTypeByMetadataName("System.Diagnostics.ProcessStartInfo");
Expand Down

0 comments on commit 6d3a1a9

Please sign in to comment.