AA1001 - Static Methods Should Have At Least One Parameter
Report code: AA1001-StaticMethodsShouldHaveAtLeastOneParameter
Summary
Status | Implemented |
Description | Static methods should have at least one parameter |
Category | Pure-Function Analyzers |
Enabled by default: | Yes |
Severity: | Error |
Cause
Static methods that take an input, and generate a deterministic output from that input, without having any side-effects are termed pure functions. These methods are thread-safe and easy to test.
Static methods that do not take any parameters, do not meet the critia of a pure function: they will have side-effects as they must derive a result from external resources. These methods are likely to not be thread-safe or easy to test as a result. Therefore methods without parameters should not be made static.
How to fix violations
There currently aren’t any implemented code-fixes for this rule.
How to suppress violations
This rule can be suppressed using the following attributes:
[HasSideEffects]
A static method annotated with HasSideEffects attribute is allowed to be void and have no parameters as it is explicitly declaring its intent to cause side effects.
[ConstantValueProvider]
A static method annotated with ConstantValueProvider attribute is allowed have no parameters as it is explicitly guaranteeing to return the same result every time it’s called.
For example, a static factory method that generates the same shape object each time it’s called can use this annotation.