Skip to content

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

Merged
0xFA11 merged 7 commits into
developfrom
feature/coding-standards
Mar 25, 2021
Merged

feat: spacing and formatting rules (coding standards)#666
0xFA11 merged 7 commits into
developfrom
feature/coding-standards

Conversation

@0xFA11

@0xFA11 0xFA11 commented Mar 25, 2021

Copy link
Copy Markdown
Contributor

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 thread .editorconfig
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
Copy Markdown
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.

@0xFA11
0xFA11 requested a review from wackoisgod March 25, 2021 08:20

@NoelStephensUnity NoelStephensUnity left a comment

Copy link
Copy Markdown
Member

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...

@NoelStephensUnity NoelStephensUnity left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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

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

@jeffreyrainy jeffreyrainy Mar 25, 2021

Copy link
Copy Markdown
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
Copy Markdown
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

@0xFA11

0xFA11 commented Mar 25, 2021

Copy link
Copy Markdown
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 :)

@0xFA11
0xFA11 merged commit 6250fcb into develop Mar 25, 2021
@0xFA11
0xFA11 deleted the feature/coding-standards branch March 25, 2021 23:06
0xFA11 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.

4 participants