Skip to content

Commit

Permalink
wip: tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Oct 18, 2022
1 parent a61bfe7 commit 857c51e
Show file tree
Hide file tree
Showing 35 changed files with 201 additions and 80 deletions.
121 changes: 121 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# C# files
[*.cs]
indent_style = space

# Modifier preferences
dotnet_style_require_accessibility_modifiers = never:suggestion

# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = one_less_than_current

# avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# only use var when it's obvious what the variable type is
csharp_style_var_for_built_in_types = true:none
csharp_style_var_when_type_is_apparent = true:none
csharp_style_var_elsewhere = false:none

# use language keywords instead of BCL types
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# static fields should be PascalCase
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static

dotnet_naming_style.static_prefix_style.capitalization = pascal_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style

dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal

dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case

# Code style defaults
dotnet_sort_system_directives_first = true
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

# Pattern matching
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

# Null checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = do_not_ignore
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
6 changes: 3 additions & 3 deletions GZCTF.Test/ContainerServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CTFServer.Models.Internal;
using CTFServer.Services.Interface;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand Down
2 changes: 1 addition & 1 deletion GZCTF.Test/SignatureTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Text;
using CTFServer.Utils;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities.Encoders;
using System.Text;
using Xunit;
using Xunit.Abstractions;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF.Test/TestMailSender.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CTFServer.Services.Interface;
using System.Threading.Tasks;
using System.Threading.Tasks;
using CTFServer.Services.Interface;

namespace CTFServer.Test;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF.Test/TestWebAppFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CTFServer.Services.Interface;
using System.Linq;
using CTFServer.Services.Interface;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;

namespace CTFServer.Test;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CTFServer.Extensions;
using System.Net.Mime;
using CTFServer.Extensions;
using CTFServer.Middlewares;
using CTFServer.Models.Internal;
using CTFServer.Models.Request.Account;
Expand All @@ -8,7 +9,6 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Net.Mime;

namespace CTFServer.Controllers;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CTFServer.Middlewares;
using System.Net.Mime;
using CTFServer.Middlewares;
using CTFServer.Models.Internal;
using CTFServer.Models.Request.Account;
using CTFServer.Models.Request.Admin;
Expand All @@ -10,7 +11,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using System.Net.Mime;

namespace CTFServer.Controllers;

Expand Down
6 changes: 3 additions & 3 deletions GZCTF/Controllers/AssetsController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CTFServer.Middlewares;
using System.ComponentModel.DataAnnotations;
using System.Net.Mime;
using CTFServer.Middlewares;
using CTFServer.Repositories.Interface;
using CTFServer.Utils;
using Microsoft.AspNetCore.Mvc;
using System.Net.Mime;
using System.ComponentModel.DataAnnotations;

namespace CTFServer.Controllers;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Controllers/EditController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CTFServer.Extensions;
using System.Net.Mime;
using CTFServer.Extensions;
using CTFServer.Middlewares;
using CTFServer.Models.Request.Edit;
using CTFServer.Models.Request.Game;
Expand All @@ -8,7 +9,6 @@
using CTFServer.Utils;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Net.Mime;

namespace CTFServer.Controllers;

Expand Down
8 changes: 4 additions & 4 deletions GZCTF/Controllers/GameController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using CTFServer.Middlewares;
using System.Net.Mime;
using System.Security.Claims;
using System.Threading.Channels;
using CTFServer.Middlewares;
using CTFServer.Models.Request.Admin;
using CTFServer.Models.Request.Edit;
using CTFServer.Models.Request.Game;
using CTFServer.Repositories.Interface;
using CTFServer.Utils;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Net.Mime;
using System.Security.Claims;
using System.Threading.Channels;

namespace CTFServer.Controllers;

Expand Down
6 changes: 3 additions & 3 deletions GZCTF/Controllers/TeamController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Net.Mime;
using System.Text.RegularExpressions;
using CTFServer.Middlewares;
using CTFServer.Models.Request.Info;
using CTFServer.Repositories.Interface;
using CTFServer.Utils;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Net.Mime;
using System.Text.RegularExpressions;

namespace CTFServer.Controllers;

Expand Down Expand Up @@ -358,7 +358,7 @@ public async Task<IActionResult> Accept([FromBody] string code, CancellationToke

var lastColon = preCode.LastIndexOf(':');

if(!int.TryParse(preCode[(lastColon + 1)..], out var teamId))
if (!int.TryParse(preCode[(lastColon + 1)..], out var teamId))
return BadRequest(new RequestResponse($"队伍 Id 转换错误:{preCode[(lastColon + 1)..]}"));

var teamName = preCode[..lastColon];
Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Extensions/RecaptchaExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CTFServer.Models.Internal;
using System.Text.Json;
using CTFServer.Models.Internal;
using Microsoft.Extensions.Options;
using System.Text.Json;

namespace CTFServer.Extensions;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Data/Attachment.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;

namespace CTFServer.Models.Data;

Expand Down
8 changes: 4 additions & 4 deletions GZCTF/Models/Data/Challenge.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CTFServer.Models.Data;
using CTFServer.Models.Request.Edit;
using CTFServer.Utils;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using CTFServer.Models.Data;
using CTFServer.Models.Request.Edit;
using CTFServer.Utils;

namespace CTFServer.Models;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Data/FlagContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CTFServer.Models.Data;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using CTFServer.Models.Data;

namespace CTFServer.Models;

Expand Down
8 changes: 4 additions & 4 deletions GZCTF/Models/Data/Game.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using CTFServer.Models.Request.Edit;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using CTFServer.Models.Request.Edit;
using CTFServer.Utils;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities.Encoders;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace CTFServer.Models;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Data/LocalFile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;

namespace CTFServer.Models;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Data/Post.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CTFServer.Models.Request.Edit;
using System.ComponentModel.DataAnnotations;
using CTFServer.Models.Request.Edit;
using CTFServer.Utils;
using System.ComponentModel.DataAnnotations;

namespace CTFServer.Models;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Data/Submission.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;

namespace CTFServer.Models;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Data/Team.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CTFServer.Models.Request.Info;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CTFServer.Models.Request.Info;

namespace CTFServer.Models;

Expand Down
6 changes: 3 additions & 3 deletions GZCTF/Models/Data/UserInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CTFServer.Models.Request.Account;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CTFServer.Models.Request.Account;
using CTFServer.Models.Request.Admin;
using Microsoft.AspNetCore.Identity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace CTFServer.Models;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Request/Edit/ChallengeEditDetailModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CTFServer.Models.Data;
using System.ComponentModel.DataAnnotations;
using CTFServer.Models.Data;
using CTFServer.Models.Request.Game;
using System.ComponentModel.DataAnnotations;

namespace CTFServer.Models.Request.Edit;

Expand Down
4 changes: 2 additions & 2 deletions GZCTF/Models/Request/Game/ScoreboardModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CTFServer.Models.Request.Info;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
using CTFServer.Models.Request.Info;

namespace CTFServer.Models.Request.Game;

Expand Down
2 changes: 1 addition & 1 deletion GZCTF/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace CTFServer.Pages;

Expand Down
Loading

0 comments on commit 857c51e

Please sign in to comment.