SS3D icon indicating copy to clipboard operation
SS3D copied to clipboard

Add test to check all assets are in PascalCase

Open stilnat opened this issue 2 years ago • 6 comments

Summary

We'd like an automatic way to check all asset's names are written in PascalCase, and the test should return a list of all assets with their position in the folder's hierarchy that do not respect this rule. Please exclude external folder such as TextMeshPro from this rule. I don't have an exhaustive list of external folder so you might want to ask in discord to know more about it.

Possible solution

In LobbyTest.cs you can check the test SpecifiedFieldsWithinSceneAreNotNull, it should be a good source of inspiration.

stilnat avatar Feb 23 '23 09:02 stilnat

I'm not sure this would be too easy to check... Checking that the first letter is a capital is easy. But knowing the required capitalization of the rest is not. Consider the following asset names:

  • FancyIDHolder
  • FANCYIDHOLDER
  • Fancyidholder
  • FaNcYiDhOlDeR

In my opinion, the first is an appropriate use of PascalCase, while the other three are clearly not. What generic rule can you use to differentiate the appropriate from the not appropriate?

Ryan089 avatar Feb 23 '23 12:02 Ryan089

Right, did not think of that. I can't see any other way than using a dictionary. Not sure if the file size is worth it just for that. I'll put the need discussion tag. https://stackoverflow.com/questions/8870261/how-to-split-text-without-spaces-into-list-of-words That might serve as inspiration, although I don't think it's that reliable.

stilnat avatar Feb 23 '23 12:02 stilnat

Let's be honest, It would always either be PascalCase, camelCase, lowercase or UPPERCASE, for someone to commit a file called "FaNcYiDhOlDeR" that person would have to be trolling, in which case the PR should not be merged anyway, I see no point in checking special cases like that.

You would have to add an extremely unnecessary and heavy algorithm that checks over 125 thousand words per file just to check if someone didn't mess up a name that should be checked by maintainers anyway

TaylorNAlbarnaz avatar Feb 24 '23 11:02 TaylorNAlbarnaz

Yeah, what I am suggesting is that resolving this issue completely is either impossible or excessive. My opinion is that it should be removed. My example was inserted only to demonstrate the difficulty with coming up with a general solution to the problem.

Ryan089 avatar Feb 25 '23 02:02 Ryan089

@Ryan089 @TaylorNAlbarnaz Actually using a dictionnary it's very simple to check if a name is okay or not, and I think it works in almost any cases ? Just check if the uppercase letter and all the lowercase following it form a known word :

  • FaNcYiDhOlDeR

    • Is "Fa" a word ? Yes. Next one.
    • Is Nc a word ? No. Test failed.
  • FANCYIDHOLDER

    • Is F a word ? No. Test failed.
  • Fancyidholder

    • is Fancyidholder a word ? No. Test failed.
  • FancyIDHolder

    • is Fancy a word ? Yes.
    • is I a word ? Yes.
    • is D a word ? No. Test failed (it can be okay or not, depending on if we want to allow acronyms to be fully capitalized)

The only issue I see would be with acronyms such as the last test above. I suggest doing the following modification. Have an acronym dictionary.

  • if two or more letters are uppercase in a row :
    • if the last letter of the uppercase serie is the last letter of the name :
      • check if the word formed of all those letters is a known acronym.
    • else :
      • check if the word formed of all those uppercase letter except the last one is a known acronym

using this modification :

  • FancyIDHolder
  • is Fancy a word ? Yes.
  • is I a word ? No. (we can remove it from the dictionnary as I don't see the word "I" useful in any name)
  • Is there following uppercase letter ? Yes.
  • Fetch them. Is H the last letter of the name ? No.
  • Is ID a known acronym ? Yes.
  • is Holder a word ? Yes.
  • Test Passed.

Add an exception for the I of interfaces and we're good I believe to cover 99.999% of cases.

Not so small extra, we have an automatic way of checking for orthographic issues in file names. We also can control what word we allow in the naming (maybe remove slurs, remove words with no meaning, in a different language, very rare word that even native would find difficult to understand and whatnot).

Only issue I see : dictionary size. Probably not that bad but I would understand that being a point of concern. My question is, is there no other application for a dictionary ? We could probably use it for moderation, for automatic speech for some AI, I don't know ... I won't completely remove the issue, but I'm removing it from the current milestone, and it keeps the need discussion tag.

stilnat avatar Feb 25 '23 08:02 stilnat

Why was this removed from 0.0.7?

cosmiccoincidence avatar Apr 20 '23 05:04 cosmiccoincidence