Skip to content

Add UseConsistentParametersKind rule#2149

Open
Haimasker wants to merge 1 commit intoPowerShell:mainfrom
Haimasker:use-correct-parameters-definition-type-rule
Open

Add UseConsistentParametersKind rule#2149
Haimasker wants to merge 1 commit intoPowerShell:mainfrom
Haimasker:use-correct-parameters-definition-type-rule

Conversation

@Haimasker
Copy link

  • Consistent function parameters definition

  • Rule is disabled by default

  • Possible types of preferred function parameters are: "Inline", "ParamBlock"

PR Summary

This PSScriptAnalyzer rule enforces uniform parameter definitions ("Inline" or "ParamBlock") across functions, improving code readability and maintainability.

Key Benefits:

  1. Consistency: Standardizes parameter style project-wide, making code easier to read and extend.
  2. Advanced Attributes: param block provides CmdletBinding(), OutputType(), and other advanced attributes. On the other hand, these attributes can be blocked by using inline parameters.

PR Checklist

@Haimasker
Copy link
Author

@microsoft-github-policy-service agree

@Haimasker
Copy link
Author

@sdwheeler @michaeltlombardi @bergmeister
Sorry for additional tagging, but when a merge request review can be expected?

Thank you in advance.

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution and sorry for late review. I added Andy as well as he is the main code owner.
The rule might be a bit controversial as for some folks there is no 'correct' kind, therefore I suggest to name rule UseConsistentParametersKind for consistency with other rule names


## Description

All functions should have same parameters definition kind specified in the rule. Either using inline parameters in function definition or using param() block inside function body.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to better highlight there are only 2 kinds and what the consequences are of mixing them (is it just optical or does one get a compile or runtime error?).

Also, just talking from personal preference: I mix them because if I just need a simple function with arguments that are small enough to fit in one line, then I like the inline option but the moment things get more complicated (e.g. adding attributes/types, which makes inline hard to read), I use param block. We can definitely add this rule as-is since people can enable it if they think it's useful but just wondering whether it would be useful to some folks to have an optional configuration that allows them to enforce using param block when certain criteria are met (e.g. number of params, presence of attributes, etc.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, I mix it too.
Inline for small and simple functions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description was expanded.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About personal preference:

  1. The rule is disabled by default, so if someone prefers to mix parameters kinds, then this person can do it easily by not enabling the rule.
  2. I can describe my real-time scenario where this rule is very useful. In production code it is more useful to have strongly-typed code rather than trying to fit function definition in single line. So in our company we have custom rule for PsScriptAnalyzer which forces user to use OutputType for functions which have param() block. So, to force user to use OutputType for any function I first need to force user to use param() block. And it is achievable due to this UseConsistentParametersKind rule.

I just want to say that this rule can be really useful in combination with some other rules. Hope it will be helpful for someone else as for me :)

If you still have any questions, you are welcome, I will try to reply to it.

@Haimasker Haimasker force-pushed the use-correct-parameters-definition-type-rule branch from 0337dfe to eb46fe4 Compare February 14, 2026 10:18
@Haimasker Haimasker changed the title Add UseCorrectParametersKind rule Add UseConsistentParametersKind rule Feb 14, 2026
* Consistent function parameters definition

* Rule is disabled by default

* Possible types of preferred function parameters are: "Inline",
"ParamBlock"
@Haimasker Haimasker force-pushed the use-correct-parameters-definition-type-rule branch from eb46fe4 to ebd9efa Compare February 14, 2026 11:06
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

Successfully merging this pull request may close these issues.

3 participants