-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Port rule CA1011 - Consider passing base types as parameters #61916
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
The usage is pretty straightforward. The original issue is here. There is already a PR porting this fixer from FxCop, and it's blocked by having this proposal approved (or not). Existing MS Docs for CA1011: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1011?view=vs-2022
Flag // Before
public void ReadNextByte(FileStream stream)
{
while (stream.ReadByte() != -1) { /*...*/ }
}
// After
public void ReadNextByte(Stream anyStream)
{
while (anyStream.ReadByte() != -1) { /*...*/ }
} Do not flag // Before
public void ReadHandle(FileStream stream)
{
while (anyStream.ReadByte() != -1) { /*...*/ } // ReadByte is available in Stream
var handle = stream.SafeFileHandle; // But SafeFileHandle is only available in FileStream
} (Maybe) do not flagThe alternative to "not flagging" is to give the suggestion anyway, but let the user supress it / ignore it interface IResource
{
string Location { get; }
}
class FileResource : IResource
{
// Location represents a file path
}
class HttpResource : IResource
{
// Location represents an HTTP url
}
// Should not be corrected to IResource
string GetContent(FileResource res)
{
return File.ReadAllText(res.Location); // the type encodes information about what the object represents
} |
Category: Design |
PR implementing this: dotnet/roslyn-analyzers#5356 |
VS rule description: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1011?view=vs-2022&redirectedfrom=MSDN&viewFallbackFrom=vs-2015
I think we should file a separate issue on dotnet\runtime and allow the runtime team to triage the correct severity/enabled by default state of this ported FxCop rule. @buyaa-n @carlossanlop
Originally posted by @mavasani in dotnet/roslyn-analyzers#5356 (comment)
If I get the green light from you, I will address the few comments made by @mavasani and will wait for your input in term of severity and enabled by default state.
The text was updated successfully, but these errors were encountered: