Skip to content

The "UseSingularNouns" rule should only generate a warning for words that are plural but not singular. #208

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

Closed
imfrancisd opened this issue May 25, 2015 · 4 comments
Assignees

Comments

@imfrancisd
Copy link

Suggestion

The "UseSingularNouns" rule should only generate a warning for words that are plural but not singular.

IsPlural IsSingular UseSingularNouns
False False no warning
False True no warning
True False warning
True True no warning

Before #139

The rule before #139 generated a warning for words that were both plural and singular.

IsPlural IsSingular UseSingularNouns
False False no warning
False True no warning
True False warning
True True warning (Why? The word is singular.)

After #139

The rule after #139 generates a warning even though the rule doesn't know if the word is plural or singular.

IsPlural IsSingular UseSingularNouns
False False warning (Why? If the program can't figure it out, don't generate warnings.)
False True no warning
True False warning
True True no warning

References

The "UseSingularNouns" rule can be traced back to:

Strongly Encouraged Development Guidelines
https://msdn.microsoft.com/en-us/library/dd878270(v=vs.85).aspx

Use a Specific Noun for a Cmdlet Name (SD01)

Nouns used in cmdlet naming need to be very specific so that the user can discover your cmdlets. Prefix generic nouns such as "server" with a shortened version of the product name. For example, if a noun refers to a server that is running an instance of Microsoft SQL Server, use a noun such as "SQLServer". The combination of specific nouns and the short list of approved verbs enable the user to quickly discover and anticipate functionality while avoiding duplication among cmdlet names.

To enhance the user experience, the noun that you choose for a cmdlet name should be singular. For example, use the name Get-Process instead of Get-Processes. It is best to follow this rule for all cmdlet names, even when a cmdlet is likely to act upon more than one item.

The part about singular vs. plural nouns is purely to "enhance the user experience". If the rule can't figure out if something is singular or plural, then the rule should not generate a warning, but leave the decision of how to "enhance the user experience" to the cmdlet writer.

@quoctruong
Copy link

Hi Francis, thank you for the suggestion. We will work on fixing this rule. Can you provide us with a word where IsSingular and IsPlural returns false? This would be really helpful for testing purposes. Thanks.

@imfrancisd
Copy link
Author

From a small list of English words, I found these:

a, all, another, any, anybody, anyone, anything, both, each, either, everybody, everyone, everything, he, her, hers, herself, him, himself, his, it, its, itself, me, mine

The real problem is if someone makes up a word to represent a product and PluralizationService returns $false for IsSingular and IsPlural. From the list above, I know that the word "all" is the name of laundry detergent. We just can't know what will happen in the future to the English language or to the algorithm that PluralizationService is using, so I think the rule has to be very selective about its warnings.

@KirkMunro
Copy link
Contributor

There is a great example of this right in front of all of us:

"Windows"

If you had a command called Reset-Windows, where Windows is a name and also a noun, then that would have to be allowed. But you may also have a Close-Window command referring to a command that closes one or more open windows on your desktop, in which case that would have to be singular since that is referring to window as a noun only.

The trick is in identifying when to warn on a noun like "Windows". This is a perfect example why command authors, and not only command users, need to be able to indicate the best practice for their commands. The author of Reset-Windows should be able to apply an attribute to their command indicating that the noun is, in fact, singular. See #211 about enabling authors to guide PSScriptAnalyzer in the right direction like this.

@yutingc
Copy link
Contributor

yutingc commented May 26, 2015

Hi @imfrancisd, a new fix #220 is merged with BugFixes. We take your suggestion and modify the check based on the "truth table" (expected behavior). Thanks!

@yutingc yutingc closed this as completed May 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants