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

feat: spacing and formatting rules (coding standards) #666

Merged
merged 7 commits into from Mar 25, 2021

Conversation

ThusSpokeNomad
Copy link
Contributor

@ThusSpokeNomad ThusSpokeNomad commented Mar 25, 2021

introducing .editorconfig for spacing and formatting rules, based on Unity C# coding standards.
this is the first part of coding standard rules, we will also have naming standards soon (WIP).
we are planning to integrate these rules into both local (git push hooks) and repo (yamato ci/cd) pipelines.

all the changes are made by dotnet-format tool (not by me at all, yay!) except .editorconfig file.

you can run this command manually in your local environment to get the same results:

$ dotnet-format ./testproject/testproject.sln
$ dotnet-format ./testproject/testproject.sln --fix-style error

I will follow-up with naming rules, git-push hook & script and yamato config in the future under a separate PR.

Comment on lines +14 to +24
# formatting rules
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error
dotnet_style_require_accessibility_modifiers = always:error
csharp_style_var_when_type_is_apparent = true:error
csharp_prefer_braces = true:error
csharp_using_directive_placement = outside_namespace:error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setting verbosity levels to "error" gives us --fix-style error ability, which basically means dotnet-format would fix them for us automatically as it did here in this PR.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

After looking through the Rpc stuff a little, I found an area that had the logic of the code adjusted such that it performs differently than before. That is a little worrisome...

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

From what I can tell, it looks like a great addition!

@wackoisgod
Copy link
Contributor

So my primary question here :P is does this follow standard unity coding guidelines ?

@@ -76,7 +76,10 @@ public void NetworkSerialize(NetworkSerializer serializer)

public void SetParamTracking(int paramIndex, bool isTracking)
{
if (paramIndex >= 32) return;
if (paramIndex >= 32)
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't warn on magic numbers ? :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, bots and tools are not that clever yet :D

@ThusSpokeNomad
Copy link
Contributor Author

So my primary question here :P is does this follow standard unity coding guidelines ?

@wackoisgod — haha, yes it does! :)

  • Text file encoding is UTF8 with no BOM, using LF (unix) line endings.
  • 4-wide tabstops, using spaces only (no tab characters)
  • No trailing whitespace on lines, but always include a single newline at the end of the file.
  • If the compiler does not require something, leave it out (i.e. 'this.' prefix, default access levels, 'Attribute' postfix, etc.)
  • 'var' required on any 'new' where the type we want is the same as what is being constructed, even primitive types
  • (This is a case where 'var' not required because the types of the variable vs the ctor are different)
  • etc.

so yeah, all of the entries in .editorconfig file are coming from Unity C# Standards Reference.
there is no personal preference went in there :)

@ThusSpokeNomad ThusSpokeNomad merged commit 6250fcb into develop Mar 25, 2021
@ThusSpokeNomad ThusSpokeNomad deleted the feature/coding-standards branch March 25, 2021 23:06
ThusSpokeNomad added a commit that referenced this pull request Aug 31, 2021
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.

None yet

4 participants