Skip to content
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

Should nullable reference types be supported, or have their code analysis warnings disabled inside the file via pragma's? #156

Open
kmgallahan opened this issue Jun 9, 2022 · 4 comments

Comments

@kmgallahan
Copy link

kmgallahan commented Jun 9, 2022

I like TinyIoC, but it produces ~100 warnings and messages when the package is added to a project with nullable reference types enabled.

I'm curious if there is a way to prevent these without creating & adding a dedicated project to my solution with warnings/messages disabled.

TinyIoc.cs is readonly, so adding a pragma in the file can't be done. I also can't find a way to disable code analysis for this individual file externally. Same goes for disabling nullable ref types for a single file externally.

An alternative would be to release a package with support for nullable reference types.


Edit:

I figured out that you can specify individual files in an .editorconfig to tailor their code analysis rules.

[TinyIoc.cs]
dotnet_analyzer_diagnostic.severity = none
dotnet_diagnostic.severity = none

I'll leave this issue open to see if modifying TinyIoc.cs with pragma's to disable warnings/messages is something the author / community might be interested in (or adding support for nullability / releasing a separate package / using ifdef magic).

@kmgallahan kmgallahan changed the title Question: Any way to suppress warnings & messages, or can a file pragma be added? Question: When using nullable reference types, is there a way to suppress warnings & messages, or can a file pragma be added? Jun 9, 2022
@niemyjski
Copy link
Collaborator

niemyjski commented Jun 10, 2022

I'm not sure, I think you can turn off nullable types in a file with a directive? One could always submit a pr for it :)

@kmgallahan
Copy link
Author

kmgallahan commented Jun 10, 2022

I figured out that you can specify individual files in an .editorconfig to tailor their code analysis rules.

[TinyIoc.cs]
dotnet_analyzer_diagnostic.severity = none
dotnet_diagnostic.severity = none

I'll leave this issue open to see if modifying TinyIoc.cs with pragma's to disable warnings/messages is something the author / community might be interested in (or adding support for nullability / releasing a separate package / using ifdef magic).

@kmgallahan kmgallahan changed the title Question: When using nullable reference types, is there a way to suppress warnings & messages, or can a file pragma be added? Should nullable reference types be supported, or have their code analysis warnings disabled inside the file via pragma's? Jun 10, 2022
@adydecki
Copy link

adydecki commented Jul 22, 2022

Thanks for the suggestion @kmgallahan . Does these rules in the .editorconfig should get rid of the compile warnings? It still shows "nullable" warnings after I added your rules.

@kmgallahan
Copy link
Author

@adydecki It works for me. Your file may be in a location that isn't being used:

Where are these files stored?

When opening a file, EditorConfig plugins look for a file named .editorconfig in the directory of the opened file and in every parent directory. A search for .editorconfig files will stop if the root filepath is reached or an EditorConfig file with root=true is found.

EditorConfig files are read top to bottom and the most recent rules found take precedence. Properties from matching EditorConfig sections are applied in the order they were read, so properties in closer files take precedence.

https://editorconfig.org/#file-location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants