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

Fix Qodana issues #2450

Open
vbreuss opened this issue Nov 9, 2023 · 4 comments
Open

Fix Qodana issues #2450

vbreuss opened this issue Nov 9, 2023 · 4 comments

Comments

@vbreuss
Copy link
Contributor

vbreuss commented Nov 9, 2023

Background and motivation

The Qodana baseline scan has currently 1,049 problems

Qodana - Baseline summary
Analysis results: 1,049 problems detected
Grouping problems according to baseline: UNCHANGED: 1,030, NEW: 19
---------------------------------------------------------------------------------------
Name                                                 Baseline  Severity  Problems count
---------------------------------------------------------------------------------------
Possible 'System.NullReferenceException'                  NEW      High               1
Member can be made private (non-private accessibil        NEW  Moderate               9
ity)                                                                                   
Method return value is never used (non-private acc        NEW  Moderate               6
essibility)                                                                            
Member can be made protected (non-private accessib        NEW  Moderate               2
ility)                                                                                 
Class is never instantiated (non-private accessibi        NEW  Moderate               1
lity)                                                                                  
Possible 'System.InvalidOperationException'         UNCHANGED      High              87
Possible multiple enumeration                       UNCHANGED      High              83
Possible 'System.NullReferenceException'            UNCHANGED      High              36
Redundant using directive                           UNCHANGED      High              23
Possible 'null' assignment to non-nullable entity   UNCHANGED      High              10
Auto-property accessor is never used (non-private   UNCHANGED      High               4
accessibility)                                                                         
Expression is always 'true' or always 'false'       UNCHANGED      High               4
Namespace does not correspond to file location      UNCHANGED      High               4
Local function hides method                         UNCHANGED      High               3
Parameter hides member                              UNCHANGED      High               3
Co-variant array conversion                         UNCHANGED      High               2
Access to modified captured variable                UNCHANGED      High               1
Inconsistent synchronization on field               UNCHANGED      High               1
Non-readonly type member referenced in 'GetHashCod  UNCHANGED      High               1
e()'                                                                                   
Possible overflow in unchecked context              UNCHANGED      High               1
Type member is never used (private accessibility)   UNCHANGED      High               1
Use null check pattern instead of a type check suc  UNCHANGED      High               1
ceeding on any not-null value                                                          
Variable in local function hides variable from out  UNCHANGED      High               1
er scope                                                                               
Method return value is never used (non-private acc  UNCHANGED  Moderate             426
essibility)                                                                            
Member can be made private (non-private accessibil  UNCHANGED  Moderate             162
ity)                                                                                   
Member can be made protected (non-private accessib  UNCHANGED  Moderate              41
ility)                                                                                 
Unused parameter (non-private accessibility)        UNCHANGED  Moderate              21
Parameter can be declared with the base type        UNCHANGED  Moderate              19
Property can be made init-only (non-private access  UNCHANGED  Moderate              17
ibility)                                                                               
Type is never used (non-private accessibility)      UNCHANGED  Moderate              17
Loop can be converted into LINQ-expression          UNCHANGED  Moderate               9
Replace 'Substring' with range indexer              UNCHANGED  Moderate               7
Convert 'if' statement into 'switch'                UNCHANGED  Moderate               6
Some values of the enum are not processed inside '                                     
switch' statement and are handled via default sect  UNCHANGED  Moderate               6
ion                                                                                    
Class with virtual (overridable) members never inh  UNCHANGED  Moderate               5
erited (non-private accessibility)                                                     
Auto-property can be made get-only (non-private ac  UNCHANGED  Moderate               4
cessibility)                                                                           
Convert delegate variable into local function       UNCHANGED  Moderate               3
Pass string interpolation expression                UNCHANGED  Moderate               3
Arrange null checking pattern                       UNCHANGED  Moderate               2
Class is never instantiated (non-private accessibi  UNCHANGED  Moderate               2
lity)                                                                                  
Parameter type can be IEnumerable<T> (private acce  UNCHANGED  Moderate               2
ssibility)                                                                             
Return type can be IEnumerable<T> (non-private acc  UNCHANGED  Moderate               2
essibility)                                                                            
Return type can be IEnumerable<T> (private accessi  UNCHANGED  Moderate               2
bility)                                                                                
Use method IsInstanceOfType(..)                     UNCHANGED  Moderate               2
Conditional expression can be rewritten as null-co  UNCHANGED  Moderate               1
alescing                                                                               
Convert into 'using' declaration                    UNCHANGED  Moderate               1
Merge 'and' pattern                                 UNCHANGED  Moderate               1
Part of foreach loop can be converted into LINQ-ex                                     
pression but another 'GetEnumerator' method will b  UNCHANGED  Moderate               1
e used                                                                                 
Property can be made init-only (private accessibil  UNCHANGED  Moderate               1
ity)                                                                                   
Type parameter could be declared as covariant or c  UNCHANGED  Moderate               1
ontravariant                                                                           
---------------------------------------------------------------------------------------

Probably not all problems can be fixed, but the easy fixes should be applied, to reduce the number of issues and reduce the allowed threshold in the build pipeline.

Alternative Concerns

No response

Are you willing help with a pull-request?

Yes, please assign this issue to me.

@jnyrup
Copy link
Member

jnyrup commented Nov 11, 2023

For every complaint Qodana has, please think about whether the change is justified.
Qodana is a tool not the truth.

@vbreuss
Copy link
Contributor Author

vbreuss commented Nov 19, 2023

A lot of issues (162) are due to `Member can be made private (non-private accessibility), e.g.
image

According to JetBrains

the recommended way is to decorate the implicitly used member with a code annotation attribute. There are two attributes for this purpose: [UsedImplicitly] and [PublicAPI], which are functionally similar, but let you and your teammates understand how the member is actually used.

Would it make sense, to explicitely annotate all these public methods with the PublicAPI attribute, or should we rather disable the rule MemberCanBePrivate.Global?

@IT-VBFK
Copy link
Contributor

IT-VBFK commented Nov 19, 2023

There is an open change request from Dennis, to exclude TFMs: https://youtrack.jetbrains.com/issue/QD-7401/Allow-excluding-or-including-certain-.NET-framework-targets

FYI: this happens, because we do not test .netstandard2.0+ anymore (since we dropped direct support for .netcore2.x and 3.x

@dennisdoomen
Copy link
Member

Please postpone the work on this issue. It's consuming too much of our time to work on the things we need to finish for v7.

@fluentassertions fluentassertions locked and limited conversation to collaborators Nov 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants